Skip to content

Commit ff03483

Browse files
authoredAug 29, 2023
V2 (#210)
* FindBugs is unmaintained, switch to SpotBugs * v2 * Update README.md
1 parent d25e52d commit ff03483

26 files changed

+343
-338
lines changed
 

‎.github/workflows/CI.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Java Build
22

33
on: [push, pull_request]
44

5+
env:
6+
AWS_DEFAULT_REGION: us-west-2
7+
58
jobs:
69
build:
710
runs-on: ubuntu-latest
@@ -16,4 +19,4 @@ jobs:
1619
- name: Build with Maven
1720
run: mvn --batch-mode --update-snapshots package
1821
- name: Codecov
19-
uses: codecov/codecov-action@v3.1.0
22+
uses: codecov/codecov-action@v3.1.4

‎.github/workflows/codeql-analysis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ name: "CodeQL"
1313

1414
on:
1515
push:
16-
branches: [ "master" ]
16+
branches: ["master", "v2"]
1717
pull_request:
18-
branches: [ "master" ]
18+
branches: ["master", "v2"]
1919
schedule:
2020
- cron: '38 2 * * 1'
2121

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jacoco.exec
1717
# Eclipse m2e generated files
1818
# Eclipse Core
1919
.project
20+
.settings
2021
# JDT-specific (Eclipse Java Development Tools)
2122
.classpath
2223

‎README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AWS Secrets Manager JDBC Library
22

33
[![Java Build](https://github.com/aws/aws-secretsmanager-jdbc/actions/workflows/CI.yml/badge.svg?event=push)](https://github.com/aws/aws-secretsmanager-jdbc/actions/workflows/CI.yml)
4-
[![Coverage](https://codecov.io/gh/aws/aws-secretsmanager-jdbc/branch/master/graph/badge.svg?token=hCl7eBaSwn)](https://codecov.io/gh/aws/aws-secretsmanager-jdbc)
4+
[![Coverage](https://codecov.io/gh/aws/aws-secretsmanager-jdbc/branch/v2/graph/badge.svg?token=hCl7eBaSwn)](https://codecov.io/gh/aws/aws-secretsmanager-jdbc)
55

66
The **AWS Secrets Manager JDBC Library** enables Java developers to easily connect to SQL databases using secrets stored in AWS Secrets Manager.
77

@@ -25,7 +25,7 @@ The recommended way to use the SQL Connection Library is to consume it from Mave
2525
<dependency>
2626
<groupId>com.amazonaws.secretsmanager</groupId>
2727
<artifactId>aws-secretsmanager-jdbc</artifactId>
28-
<version>1.0.12</version>
28+
<version>2.0.0</version>
2929
</dependency>
3030
```
3131

@@ -95,7 +95,7 @@ The secret being used should be in the JSON format we use for our rotation lambd
9595

9696
## Credentials
9797

98-
This library uses the [Default Credential Provider Chain](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html). The following options exist to override some of the defaults:
98+
This library uses the [Default Credential Provider Chain](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials.html). The following options exist to override some of the defaults:
9999

100100
1) Set a PrivateLink DNS endpoint URL and a region in the secretsmanager.properties file:
101101
```text

‎pom.xml

+40-69
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,13 @@
1616
<artifactId>aws-secretsmanager-jdbc</artifactId>
1717
<packaging>jar</packaging>
1818
<name>AWS Secrets Manager SQL Connection Library</name>
19-
<version>1.0.12</version>
19+
<version>2.0.0</version>
2020
<description>The AWS Secrets Manager SQL Connection Library for Java enables Java developers to easily
2121
connect to SQL databases using secrets stored in AWS Secrets Manager.
2222
</description>
2323
<url>https://aws.amazon.com/secrets-manager</url>
2424

2525
<properties>
26-
<aws-java-sdk.version>1.12.252</aws-java-sdk.version>
27-
<aws-secretsmanager-cache.version>1.0.2</aws-secretsmanager-cache.version>
28-
<lombok.version>1.18.24</lombok.version>
29-
<jackson.version>2.14.1</jackson.version>
30-
<junit.version>4.13.2</junit.version>
31-
<mockito.version>1.10.19</mockito.version>
32-
<powermock.version>1.7.0</powermock.version>
33-
<compiler.plugin.version>3.10.1</compiler.plugin.version>
34-
<javadoc.plugin.version>3.4.0</javadoc.plugin.version>
35-
<source.plugin.version>3.2.1</source.plugin.version>
36-
<checkstyle.plugin.version>3.1.2</checkstyle.plugin.version>
37-
<findbugs.plugin.version>3.0.5</findbugs.plugin.version>
3826
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3927
</properties>
4028

@@ -76,79 +64,86 @@
7664
<dependency>
7765
<groupId>com.amazonaws.secretsmanager</groupId>
7866
<artifactId>aws-secretsmanager-caching-java</artifactId>
79-
<version>${aws-secretsmanager-cache.version}</version>
67+
<version>2.0.0</version>
8068
</dependency>
8169

8270
<dependency>
83-
<groupId>com.amazonaws</groupId>
84-
<artifactId>aws-java-sdk-secretsmanager</artifactId>
85-
<version>${aws-java-sdk.version}</version>
71+
<groupId>software.amazon.awssdk</groupId>
72+
<artifactId>secretsmanager</artifactId>
73+
<version>2.20.93</version>
8674
</dependency>
8775

8876
<dependency>
8977
<groupId>org.projectlombok</groupId>
9078
<artifactId>lombok</artifactId>
91-
<version>${lombok.version}</version>
79+
<version>1.18.28</version>
9280
<scope>provided</scope>
9381
</dependency>
9482

9583
<dependency>
9684
<groupId>com.fasterxml.jackson.core</groupId>
9785
<artifactId>jackson-databind</artifactId>
98-
<version>${jackson.version}</version>
86+
<version>2.15.2</version>
87+
</dependency>
88+
89+
<dependency>
90+
<groupId>com.github.spotbugs</groupId>
91+
<artifactId>spotbugs-annotations</artifactId>
92+
<version>4.7.3</version>
9993
</dependency>
10094

10195
<dependency>
10296
<groupId>junit</groupId>
10397
<artifactId>junit</artifactId>
104-
<version>${junit.version}</version>
98+
<version>4.13.2</version>
99+
<scope>test</scope>
100+
</dependency>
101+
102+
<dependency>
103+
<groupId>com.github.stefanbirkner</groupId>
104+
<artifactId>system-rules</artifactId>
105+
<version>1.19.0</version>
105106
<scope>test</scope>
106107
</dependency>
107108

108109
<dependency>
109110
<groupId>org.mockito</groupId>
110-
<artifactId>mockito-all</artifactId>
111-
<version>${mockito.version}</version>
111+
<artifactId>mockito-inline</artifactId>
112+
<version>3.12.4</version>
112113
<scope>test</scope>
113114
</dependency>
114115

115116
<dependency>
116117
<groupId>org.powermock</groupId>
117118
<artifactId>powermock-module-junit4</artifactId>
118-
<version>${powermock.version}</version>
119+
<version>2.0.9</version>
119120
<scope>test</scope>
120121
</dependency>
121122

122123
<dependency>
123124
<groupId>org.powermock</groupId>
124-
<artifactId>powermock-api-mockito</artifactId>
125-
<version>${powermock.version}</version>
125+
<artifactId>powermock-api-mockito2</artifactId>
126+
<version>2.0.9</version>
126127
<scope>test</scope>
127128
</dependency>
128-
<dependency>
129-
<groupId>org.jacoco</groupId>
130-
<artifactId>org.jacoco.agent</artifactId>
131-
<classifier>runtime</classifier>
132-
<version>0.8.8</version>
133-
</dependency>
134129
</dependencies>
135130

136131
<build>
137132
<plugins>
138133
<plugin>
139134
<groupId>org.apache.maven.plugins</groupId>
140135
<artifactId>maven-compiler-plugin</artifactId>
141-
<version>${compiler.plugin.version}</version>
136+
<version>3.11.0</version>
142137
<configuration>
143-
<source>1.8</source>
144-
<target>1.8</target>
138+
<source>11</source>
139+
<target>11</target>
145140
<encoding>UTF-8</encoding>
146141
</configuration>
147142
</plugin>
148143
<plugin>
149144
<groupId>org.apache.maven.plugins</groupId>
150145
<artifactId>maven-source-plugin</artifactId>
151-
<version>${source.plugin.version}</version>
146+
<version>3.3.0</version>
152147
<executions>
153148
<execution>
154149
<id>attach-sources</id>
@@ -161,7 +156,7 @@
161156
<plugin>
162157
<groupId>org.apache.maven.plugins</groupId>
163158
<artifactId>maven-javadoc-plugin</artifactId>
164-
<version>${javadoc.plugin.version}</version>
159+
<version>3.5.0</version>
165160
<executions>
166161
<execution>
167162
<id>attach-javadocs</id>
@@ -174,10 +169,9 @@
174169
<plugin>
175170
<groupId>org.apache.maven.plugins</groupId>
176171
<artifactId>maven-checkstyle-plugin</artifactId>
177-
<version>${checkstyle.plugin.version}</version>
172+
<version>3.3.0</version>
178173
<configuration>
179174
<configLocation>${basedir}/config/checkstyle/checkstyle.xml</configLocation>
180-
<encoding>UTF-8</encoding>
181175
<consoleOutput>true</consoleOutput>
182176
<failsOnError>true</failsOnError>
183177
<linkXRef>false</linkXRef>
@@ -194,9 +188,9 @@
194188
</executions>
195189
</plugin>
196190
<plugin>
197-
<groupId>org.codehaus.mojo</groupId>
198-
<artifactId>findbugs-maven-plugin</artifactId>
199-
<version>${findbugs.plugin.version}</version>
191+
<groupId>com.github.spotbugs</groupId>
192+
<artifactId>spotbugs-maven-plugin</artifactId>
193+
<version>4.7.3.5</version>
200194
<configuration>
201195
<effort>Max</effort>
202196
<threshold>Low</threshold>
@@ -215,45 +209,22 @@
215209
<plugin>
216210
<groupId>org.jacoco</groupId>
217211
<artifactId>jacoco-maven-plugin</artifactId>
218-
<version>0.8.8</version>
212+
<version>0.8.10</version>
219213
<executions>
220214
<execution>
221-
<id>default-instrument</id>
222-
<goals>
223-
<goal>instrument</goal>
224-
</goals>
225-
</execution>
226-
<execution>
227-
<id>default-restore-instrumented-classes</id>
228215
<goals>
229-
<goal>restore-instrumented-classes</goal>
216+
<goal>prepare-agent</goal>
230217
</goals>
231218
</execution>
232219
<execution>
233220
<id>report</id>
234-
<phase>prepare-package</phase>
221+
<phase>test</phase>
235222
<goals>
236223
<goal>report</goal>
237224
</goals>
238225
</execution>
239-
<execution>
240-
<id>default-check</id>
241-
<goals>
242-
<goal>check</goal>
243-
</goals>
244-
</execution>
245226
</executions>
246227
</plugin>
247-
<plugin>
248-
<groupId>org.apache.maven.plugins</groupId>
249-
<artifactId>maven-surefire-plugin</artifactId>
250-
<version>2.22.2</version>
251-
<configuration>
252-
<systemPropertyVariables>
253-
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
254-
</systemPropertyVariables>
255-
</configuration>
256-
</plugin>
257228
</plugins>
258229
</build>
259230

@@ -265,7 +236,7 @@
265236
<plugin>
266237
<groupId>org.apache.maven.plugins</groupId>
267238
<artifactId>maven-gpg-plugin</artifactId>
268-
<version>3.0.1</version>
239+
<version>3.1.0</version>
269240
<executions>
270241
<execution>
271242
<id>sign-artifacts</id>
@@ -291,4 +262,4 @@
291262
</build>
292263
</profile>
293264
</profiles>
294-
</project>
265+
</project>

‎src/main/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerDriver.java

+19-16
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212
*/
1313
package com.amazonaws.secretsmanager.sql;
1414

15-
import com.amazonaws.secretsmanager.util.Config;
16-
import com.amazonaws.secretsmanager.caching.SecretCache;
17-
import com.amazonaws.secretsmanager.caching.SecretCacheConfiguration;
18-
import com.amazonaws.secretsmanager.util.JDBCSecretCacheBuilderProvider;
19-
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
20-
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;
21-
import com.amazonaws.util.StringUtils;
22-
import com.fasterxml.jackson.databind.JsonNode;
23-
import com.fasterxml.jackson.databind.ObjectMapper;
24-
2515
import java.io.IOException;
2616
import java.sql.Connection;
2717
import java.sql.Driver;
@@ -33,6 +23,19 @@
3323
import java.util.Properties;
3424
import java.util.logging.Logger;
3525

26+
import com.amazonaws.secretsmanager.caching.SecretCache;
27+
import com.amazonaws.secretsmanager.caching.SecretCacheConfiguration;
28+
import com.amazonaws.secretsmanager.util.Config;
29+
import com.amazonaws.secretsmanager.util.JDBCSecretCacheBuilderProvider;
30+
import com.fasterxml.jackson.databind.JsonNode;
31+
import com.fasterxml.jackson.databind.ObjectMapper;
32+
33+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
34+
35+
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
36+
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder;
37+
import software.amazon.awssdk.utils.StringUtils;
38+
3639
/**
3740
* <p>
3841
* Provides support for accessing SQL databases using credentials stored within AWS Secrets Manager. If this
@@ -130,6 +133,7 @@ protected AWSSecretsManagerDriver() {
130133
*
131134
* @param cache Secret cache to use to retrieve secrets
132135
*/
136+
@SuppressFBWarnings("MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR")
133137
protected AWSSecretsManagerDriver(SecretCache cache) {
134138
this.secretCache = cache;
135139

@@ -143,7 +147,7 @@ protected AWSSecretsManagerDriver(SecretCache cache) {
143147
*
144148
* @param builder Builder used to instantiate cache
145149
*/
146-
protected AWSSecretsManagerDriver(AWSSecretsManagerClientBuilder builder) {
150+
protected AWSSecretsManagerDriver(SecretsManagerClientBuilder builder) {
147151
this(new SecretCache(builder));
148152
}
149153

@@ -153,7 +157,7 @@ protected AWSSecretsManagerDriver(AWSSecretsManagerClientBuilder builder) {
153157
*
154158
* @param client AWS Secrets Manager client to instantiate cache
155159
*/
156-
protected AWSSecretsManagerDriver(AWSSecretsManager client) {
160+
protected AWSSecretsManagerDriver(SecretsManagerClient client) {
157161
this(new SecretCache(client));
158162
}
159163

@@ -342,7 +346,7 @@ private Connection connectWithSecret(String unwrappedUrl, Properties info, Strin
342346
JsonNode jsonObject = mapper.readTree(secretString);
343347
updatedInfo.setProperty("user", jsonObject.get("username").asText());
344348
updatedInfo.setProperty("password", jsonObject.get("password").asText());
345-
} catch (IOException | NullPointerException e) {
349+
} catch (IOException e) {
346350
// Most likely to occur in the event that the data is not JSON.
347351
// Or the secret's username and/or password fields have been
348352
// removed entirely. Either scenario is most often a user error.
@@ -380,7 +384,7 @@ public Connection connect(String url, Properties info) throws SQLException {
380384
} else { // Else, assume this is a secret ID and try to retrieve it
381385
try {
382386
String secretString = secretCache.getSecretString(url);
383-
if (StringUtils.isNullOrEmpty(secretString)) {
387+
if (StringUtils.isBlank(secretString)) {
384388
throw new IllegalArgumentException("URL " + url + " is not a valid URL starting with scheme " +
385389
SCHEME + " or a valid retrievable secret ID ");
386390
}
@@ -391,7 +395,7 @@ public Connection connect(String url, Properties info) throws SQLException {
391395
JsonNode dbnameNode = jsonObject.get("dbname");
392396
String dbname = dbnameNode == null ? null : dbnameNode.asText();
393397
unwrappedUrl = constructUrlFromEndpointPortDatabase(endpoint, port, dbname);
394-
} catch (IOException | NullPointerException e) {
398+
} catch (IOException e) {
395399
// Most likely to occur in the event that the data is not JSON.
396400
// Or the secret has been modified and is no longer valid.
397401
// Either scenario is most often a user error.
@@ -437,4 +441,3 @@ public boolean jdbcCompliant() {
437441
return getWrappedDriver().jdbcCompliant();
438442
}
439443
}
440-

0 commit comments

Comments
 (0)
Please sign in to comment.