Skip to content

Commit ea84aa7

Browse files
chore: add Prettier and Spotless checks, format files
1 parent ca0fb3d commit ea84aa7

34 files changed

+222
-225
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
name: Bug report
33
about: Create a report to help us improve
4-
title: ''
4+
title: ""
55
labels: bug
6-
assignees: ''
7-
6+
assignees: ""
87
---
98

109
**Describe the bug**
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
---
22
name: Feature request
33
about: Suggest an idea for this project
4-
title: ''
4+
title: ""
55
labels: enhancement
6-
assignees: ''
7-
6+
assignees: ""
87
---
9-
10-

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
*Issue #, if available:*
2-
3-
*Description of changes:*
1+
_Issue #, if available:_
42

3+
_Description of changes:_
54

65
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

.github/workflows/CI.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@ jobs:
2222
java-version: 11
2323
distribution: adopt
2424

25+
- name: Prettier
26+
uses: rutajdash/prettier-cli-action@v1.0.2
27+
with:
28+
file_pattern: "**/*.{md,yml}"
29+
30+
- name: Check formatting
31+
run: mvn spotless:check
32+
2533
- name: Build with Maven
2634
run: mvn --batch-mode --update-snapshots package
2735

2836
- name: Codecov
2937
uses: codecov/codecov-action@v5
38+
with:
39+
token: ${{ secrets.CODECOV_TOKEN }}

CHANGELOG.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

CODE_OF_CONDUCT.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Code of Conduct
2-
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
3-
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
2+
3+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
4+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
45
opensource-codeofconduct@amazon.com with any additional questions or comments.

CONTRIBUTING.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,63 @@
11
# Contributing Guidelines
22

3-
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
3+
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
44
documentation, we greatly value feedback and contributions from our community.
55

6-
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
6+
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
77
information to effectively respond to your bug report or contribution.
88

9-
109
## Reporting Bugs/Feature Requests
1110

1211
We welcome you to use the GitHub issue tracker to report bugs or suggest features.
1312

14-
When filing an issue, please check [existing open](https://github.com/aws/aws-secretsmanager-jdbc/issues), or [recently closed](https://github.com/aws/aws-secretsmanager-jdbc/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
13+
When filing an issue, please check [existing open](https://github.com/aws/aws-secretsmanager-jdbc/issues), or [recently closed](https://github.com/aws/aws-secretsmanager-jdbc/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
1514
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
1615

17-
* A reproducible test case or series of steps
18-
* The version of our code being used
19-
* Any modifications you've made relevant to the bug
20-
* Anything unusual about your environment or deployment
21-
16+
- A reproducible test case or series of steps
17+
- The version of our code being used
18+
- Any modifications you've made relevant to the bug
19+
- Anything unusual about your environment or deployment
2220

2321
## Contributing via Pull Requests
22+
2423
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
2524

26-
1. You are working against the latest source on the *master* branch.
25+
1. You are working against the latest source on the _master_ branch.
2726
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
2827
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
2928

3029
To send us a pull request, please:
3130

3231
1. Fork the repository.
3332
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
34-
3. Ensure local tests pass.
35-
4. Commit to your fork using clear commit messages.
36-
5. Send us a pull request, answering any default questions in the pull request interface.
37-
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
33+
3. Use rustfmt to ensure consistent formatting for `.java` files, and Prettier for `.md` and `.yml` files (see [Formatting instructions](#formatting-instructions)).
34+
4. Ensure local tests pass.
35+
5. Commit to your fork using clear commit messages.
36+
6. Send us a pull request, answering any default questions in the pull request interface.
37+
7. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
3838

39-
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
39+
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
4040
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
4141

42+
# Formatting instructions
43+
44+
- Install [Prettier](https://prettier.io/docs/install).
45+
- If using VS Code, install the VS Code extension for the above.
46+
- Run `mvn spotless:apply` and `prettier --write **/*.{md,yml}`.
4247

4348
## Finding contributions to work on
44-
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws/aws-secretsmanager-jdbc/labels/help%20wanted) issues is a great place to start.
4549

50+
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws/aws-secretsmanager-jdbc/labels/help%20wanted) issues is a great place to start.
4651

4752
## Code of Conduct
48-
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
49-
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
50-
opensource-codeofconduct@amazon.com with any additional questions or comments.
5153

54+
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
55+
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
56+
opensource-codeofconduct@amazon.com with any additional questions or comments.
5257

5358
## Security issue notifications
54-
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
5559

60+
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.
5661

5762
## Licensing
5863

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ This library is licensed under the Apache 2.0 License.
1111

1212
## Features
1313

14-
* Provides wrappers to common JDBC drivers enabling simple database connectivity
15-
* Provides database connection pooling support through c3p0
14+
- Provides wrappers to common JDBC drivers enabling simple database connectivity
15+
- Provides database connection pooling support through c3p0
1616

1717
## Building from Source
1818

19-
After you've downloaded the code from GitHub, you can build it using Maven.
20-
* To disable GPG signing in the build, use this command: `mvn clean install -Dgpg.skip=true`
21-
* To build the default (non-shaded) JAR, use this command: `mvn clean install`
22-
* To build the shaded (uber) JAR with all dependencies included, use this command: `mvn clean install -Pshade`
23-
The shaded JAR will be generated in the `target/` directory with the `-shaded` classifier, e.g.: `target/aws-secretsmanager-jdbc-2.0.2-shaded.jar`
19+
After you've downloaded the code from GitHub, you can build it using Maven.
20+
21+
- To disable GPG signing in the build, use this command: `mvn clean install -Dgpg.skip=true`
22+
- To build the default (non-shaded) JAR, use this command: `mvn clean install`
23+
- To build the shaded (uber) JAR with all dependencies included, use this command: `mvn clean install -Pshade`
24+
The shaded JAR will be generated in the `target/` directory with the `-shaded` classifier, e.g.: `target/aws-secretsmanager-jdbc-2.0.2-shaded.jar`
2425

2526
## Usage
26-
The recommended way to use the SQL Connection Library is to consume it from Maven. The latest released version can be found at: https://mvnrepository.com/artifact/com.amazonaws.secretsmanager/aws-secretsmanager-jdbc
2727

28-
``` xml
28+
The recommended way to use the SQL Connection Library is to consume it from Maven. The latest released version can be found at: https://mvnrepository.com/artifact/com.amazonaws.secretsmanager/aws-secretsmanager-jdbc
29+
30+
```xml
2931
<dependency>
3032
<groupId>com.amazonaws.secretsmanager</groupId>
3133
<artifactId>aws-secretsmanager-jdbc</artifactId>
@@ -35,7 +37,7 @@ The recommended way to use the SQL Connection Library is to consume it from Mave
3537

3638
To use the latest build (pre-release), don't forget to enable the download of snapshot jars from Maven.
3739

38-
``` xml
40+
```xml
3941
<profiles>
4042
<profile>
4143
<id>allow-snapshots</id>
@@ -53,13 +55,12 @@ To use the latest build (pre-release), don't forget to enable the download of sn
5355
```
5456

5557
### Usage Example
58+
5659
We provide database drivers that intercept calls to real database drivers and replace secret IDs with actual login credentials.
5760
This prevents hard-coding database credentials into your application code.
5861

59-
6062
The following is an example which uses the secret to resolve both the endpoint and the login credentials.
6163

62-
6364
```
6465
// Load the JDBC driver
6566
Class.forName( "com.amazonaws.secretsmanager.sql.AWSSecretsManagerPostgreSQLDriver" ).newInstance();
@@ -88,30 +89,32 @@ String URL = "jdbc-secretsmanager:postgresql://example.com:5432/database";
8889
```
8990

9091
The secret should be in the correct JSON format. For more information, see the [AWS Secrets Manager documentation](https://docs.aws.amazon.com/secretsmanager/latest/userguide/reference_secret_json_structure). For example:
92+
9193
```json
9294
{
9395
"host": "<host name>",
9496
"username": "<username>",
9597
"password": "<password>",
9698
"dbname": "<database name>",
97-
"port": "<port number>",
99+
"port": "<port number>"
98100
}
99101
```
100102

101103
We support a variety of drivers. For more information, see the [AWS Secrets Manager JDBC documentation](https://docs.aws.amazon.com/secretsmanager/latest/userguide/retrieving-secrets_jdbc).
102104

103-
104105
## Credentials
105106

106107
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:
107108

108-
1) Set a PrivateLink DNS endpoint URL and a region in the secretsmanager.properties file:
109+
1. Set a PrivateLink DNS endpoint URL and a region in the secretsmanager.properties file:
110+
109111
```text
110112
drivers.vpcEndpointUrl= #The endpoint URL
111113
drivers.vpcEndpointRegion= #The endpoint region
112114
```
113115

114-
2) Override the primary region by setting the 'AWS_SECRET_JDBC_REGION' environment variable to the preferred region, or via the secretsmanager.properties file:
116+
2. Override the primary region by setting the 'AWS_SECRET_JDBC_REGION' environment variable to the preferred region, or via the secretsmanager.properties file:
117+
115118
```text
116119
drivers.region= #The region to use.
117120
```

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,20 @@
225225
</execution>
226226
</executions>
227227
</plugin>
228+
<plugin>
229+
<groupId>com.diffplug.spotless</groupId>
230+
<artifactId>spotless-maven-plugin</artifactId>
231+
<version>2.44.4</version>
232+
<configuration>
233+
<!-- define a language-specific format -->
234+
<java>
235+
<palantirJavaFormat>
236+
<version>2.39.0</version>
237+
<style>PALANTIR</style>
238+
</palantirJavaFormat>
239+
</java>
240+
</configuration>
241+
</plugin>
228242
</plugins>
229243
</build>
230244

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

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
*/
1313
package com.amazonaws.secretsmanager.sql;
1414

15+
import com.amazonaws.secretsmanager.caching.SecretCache;
16+
import com.amazonaws.secretsmanager.caching.SecretCacheConfiguration;
17+
import com.amazonaws.secretsmanager.util.Config;
18+
import com.amazonaws.secretsmanager.util.JDBCSecretCacheBuilderProvider;
19+
import com.fasterxml.jackson.databind.JsonNode;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1522
import java.io.IOException;
1623
import java.sql.Connection;
1724
import java.sql.Driver;
@@ -22,16 +29,6 @@
2229
import java.util.Enumeration;
2330
import java.util.Properties;
2431
import java.util.logging.Logger;
25-
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-
3532
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
3633
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder;
3734
import software.amazon.awssdk.utils.StringUtils;
@@ -105,7 +102,7 @@ public abstract class AWSSecretsManagerDriver implements Driver {
105102

106103
/**
107104
* Message to return on the RuntimeException when secret string is invalid json
108-
*/
105+
*/
109106
public static final String INVALID_SECRET_STRING_JSON = "Could not parse SecretString JSON";
110107

111108
private SecretCache secretCache;
@@ -116,8 +113,6 @@ public abstract class AWSSecretsManagerDriver implements Driver {
116113

117114
private ObjectMapper mapper = new ObjectMapper();
118115

119-
120-
121116
/**
122117
* Constructs the driver setting the properties from the properties file using system properties as defaults.
123118
* Instantiates the secret cache with default options.
@@ -126,7 +121,6 @@ protected AWSSecretsManagerDriver() {
126121
this(new JDBCSecretCacheBuilderProvider().build());
127122
}
128123

129-
130124
/**
131125
* Constructs the driver setting the properties from the properties file using system properties as defaults.
132126
* Sets the secret cache to the cache that was passed in.
@@ -196,7 +190,8 @@ private void loadRealDriver() {
196190
try {
197191
Class.forName(this.realDriverClass);
198192
} catch (ClassNotFoundException e) {
199-
throw new IllegalStateException("Could not load real driver with name, \"" + this.realDriverClass + "\".", e);
193+
throw new IllegalStateException(
194+
"Could not load real driver with name, \"" + this.realDriverClass + "\".", e);
200195
}
201196
}
202197

@@ -268,8 +263,8 @@ public Driver getWrappedDriver() {
268263
}
269264
}
270265
throw new IllegalStateException("No Driver has been registered with name, " + this.realDriverClass
271-
+ ". Please check your system properties or " + Config.CONFIG_FILE_NAME
272-
+ " for typos. Also ensure that the Driver registers itself.");
266+
+ ". Please check your system properties or " + Config.CONFIG_FILE_NAME
267+
+ " for typos. Also ensure that the Driver registers itself.");
273268
}
274269

275270
@Override
@@ -284,7 +279,7 @@ public boolean acceptsURL(String url) throws SQLException {
284279
} else if (url.startsWith("jdbc:")) {
285280
// For any other JDBC URL, return false
286281
return false;
287-
} else {
282+
} else {
288283
// We accept a secret ID as the URL so if the config is set, and it's not a JDBC URL, return true
289284
return true;
290285
}
@@ -306,7 +301,7 @@ public boolean acceptsURL(String url) throws SQLException {
306301

307302
/**
308303
* Construct a database URL from the endpoint, port and database name. This method is called when the
309-
* <code>connect</code> method is called with a secret ID instead of a URL.
304+
* <code>connect</code> method is called with a secret ID instead of a URL.
310305
*
311306
* @param endpoint The endpoint retrieved from the secret cache
312307
* @param port The port retrieved from the secret cache
@@ -364,11 +359,10 @@ private Connection connectWithSecret(String unwrappedUrl, Properties info, Strin
364359
if (isExceptionDueToAuthenticationError(e)) {
365360
boolean refreshSuccess = this.secretCache.refreshNow(credentialsSecretId);
366361
if (!refreshSuccess) {
367-
throw(e);
362+
throw (e);
368363
}
369-
}
370-
else {
371-
throw(e);
364+
} else {
365+
throw (e);
372366
}
373367
}
374368
}
@@ -391,8 +385,8 @@ public Connection connect(String url, Properties info) throws SQLException {
391385
try {
392386
String secretString = secretCache.getSecretString(url);
393387
if (StringUtils.isBlank(secretString)) {
394-
throw new IllegalArgumentException("URL " + url + " is not a valid URL starting with scheme " +
395-
SCHEME + " or a valid retrievable secret ID ");
388+
throw new IllegalArgumentException("URL " + url + " is not a valid URL starting with scheme "
389+
+ SCHEME + " or a valid retrievable secret ID ");
396390
}
397391
JsonNode jsonObject = mapper.readTree(secretString);
398392
String endpoint = jsonObject.get("host").asText();

0 commit comments

Comments
 (0)