Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aws/aws-secretsmanager-jdbc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.0.8
Choose a base ref
...
head repository: aws/aws-secretsmanager-jdbc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.0.9
Choose a head ref
  • 14 commits
  • 9 files changed
  • 6 contributors

Commits on May 12, 2022

  1. Update CI.yml

    simonmarty authored May 12, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    17be16c View commit details

Commits on May 13, 2022

  1. Update CI.yml (#76)

    simonmarty authored May 13, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6f573eb View commit details

Commits on Jun 30, 2022

  1. Bump nexus-staging-maven-plugin from 1.6.8 to 1.6.13 (#72)

    Bumps nexus-staging-maven-plugin from 1.6.8 to 1.6.13.
    
    ---
    updated-dependencies:
    - dependency-name: org.sonatype.plugins:nexus-staging-maven-plugin
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jun 30, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    067b5ed View commit details
  2. Bump maven-compiler-plugin from 3.2 to 3.10.1 (#70)

    Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.2 to 3.10.1.
    - [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
    - [Commits](apache/maven-compiler-plugin@maven-compiler-plugin-3.2...maven-compiler-plugin-3.10.1)
    
    ---
    updated-dependencies:
    - dependency-name: org.apache.maven.plugins:maven-compiler-plugin
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jun 30, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1706481 View commit details
  3. Bump junit from 4.13.1 to 4.13.2 (#71)

    Bumps [junit](https://github.com/junit-team/junit4) from 4.13.1 to 4.13.2.
    - [Release notes](https://github.com/junit-team/junit4/releases)
    - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.13.1.md)
    - [Commits](junit-team/junit4@r4.13.1...r4.13.2)
    
    ---
    updated-dependencies:
    - dependency-name: junit:junit
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Jun 30, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9589c27 View commit details

Commits on Jul 1, 2022

  1. Update README.md

    simonmarty authored Jul 1, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0a6ca01 View commit details
  2. Add codecov (#93)

    * Update CI.yml
    
    * Bump jackson-databind from 2.13.2.2 to 2.13.3
    
    Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.13.2.2 to 2.13.3.
    - [Release notes](https://github.com/FasterXML/jackson/releases)
    - [Commits](https://github.com/FasterXML/jackson/commits)
    
    ---
    updated-dependencies:
    - dependency-name: com.fasterxml.jackson.core:jackson-databind
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    * Bump maven-gpg-plugin from 1.6 to 3.0.1
    
    Bumps [maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 1.6 to 3.0.1.
    - [Release notes](https://github.com/apache/maven-gpg-plugin/releases)
    - [Commits](apache/maven-gpg-plugin@maven-gpg-plugin-1.6...maven-gpg-plugin-3.0.1)
    
    ---
    updated-dependencies:
    - dependency-name: org.apache.maven.plugins:maven-gpg-plugin
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    * Bump maven-checkstyle-plugin from 2.17 to 3.1.2
    
    Bumps [maven-checkstyle-plugin](https://github.com/apache/maven-checkstyle-plugin) from 2.17 to 3.1.2.
    - [Release notes](https://github.com/apache/maven-checkstyle-plugin/releases)
    - [Commits](apache/maven-checkstyle-plugin@maven-checkstyle-plugin-2.17...maven-checkstyle-plugin-3.1.2)
    
    ---
    updated-dependencies:
    - dependency-name: org.apache.maven.plugins:maven-checkstyle-plugin
      dependency-type: direct:production
      update-type: version-update:semver-major
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    * Bump maven-javadoc-plugin from 3.0.1 to 3.4.0
    
    Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.0.1 to 3.4.0.
    - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
    - [Commits](apache/maven-javadoc-plugin@maven-javadoc-plugin-3.0.1...maven-javadoc-plugin-3.4.0)
    
    ---
    updated-dependencies:
    - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    * Add jacoco
    
    * Bump aws-java-sdk-secretsmanager from 1.12.148 to 1.12.252
    
    Bumps [aws-java-sdk-secretsmanager](https://github.com/aws/aws-sdk-java) from 1.12.148 to 1.12.252.
    - [Release notes](https://github.com/aws/aws-sdk-java/releases)
    - [Changelog](https://github.com/aws/aws-sdk-java/blob/master/CHANGELOG.md)
    - [Commits](aws/aws-sdk-java@1.12.148...1.12.252)
    
    ---
    updated-dependencies:
    - dependency-name: com.amazonaws:aws-java-sdk-secretsmanager
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    * Bump maven-source-plugin from 3.0.1 to 3.2.1
    
    Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.0.1 to 3.2.1.
    - [Release notes](https://github.com/apache/maven-source-plugin/releases)
    - [Commits](apache/maven-source-plugin@maven-source-plugin-3.0.1...maven-source-plugin-3.2.1)
    
    ---
    updated-dependencies:
    - dependency-name: org.apache.maven.plugins:maven-source-plugin
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    * Try offline instrumentation
    
    * Simplify, try 0.8.7
    
    * Switch back to 0.8.8
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Simon Marty <martysi@amazon.com>
    3 people authored Jul 1, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ab71a6e View commit details
  3. Update README.md

    simonmarty authored Jul 1, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    38b40a9 View commit details

Commits on Aug 3, 2022

  1. Add override for default region. (#88)

    * Add override for default region.
    
    * Fixed unit tests
    
    * Increment library version number
    
    Co-authored-by: Dan Mancuso <danmanc@amazon.com>
    Co-authored-by: Simon Marty <simon.marty0@gmail.com>
    3 people authored Aug 3, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    456ccce View commit details

Commits on Sep 8, 2022

  1. Temporarily roll back README. (#100)

    Rolling back the README file until the next release so not to confused what functionality the currently released version has.
    danmancuso authored Sep 8, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1522aea View commit details

Commits on Sep 19, 2022

  1. Use current thread resource context instead of system one (#32)

    Co-authored-by: Simon Marty <simon.marty0@gmail.com>
    devportilla and simonmarty authored Sep 19, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9113696 View commit details

Commits on Oct 6, 2022

  1. Bump jackson-databind from 2.13.3 to 2.13.4 (#112)

    Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.13.3 to 2.13.4.
    - [Release notes](https://github.com/FasterXML/jackson/releases)
    - [Commits](https://github.com/FasterXML/jackson/commits)
    
    ---
    updated-dependencies:
    - dependency-name: com.fasterxml.jackson.core:jackson-databind
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Oct 6, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0bb227a View commit details
  2. Add CodeQL

    simonmarty authored Oct 6, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a43fca2 View commit details

Commits on Oct 25, 2022

  1. Bump jackson-databind from 2.13.4 to 2.13.4.2 (#124)

    Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.13.4 to 2.13.4.2.
    - [Release notes](https://github.com/FasterXML/jackson/releases)
    - [Commits](https://github.com/FasterXML/jackson/commits)
    
    ---
    updated-dependencies:
    - dependency-name: com.fasterxml.jackson.core:jackson-databind
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Oct 25, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    28f6961 View commit details
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -15,3 +15,5 @@ jobs:
distribution: 'adopt'
- name: Build with Maven
run: mvn --batch-mode --update-snapshots package
- name: Codecov
uses: codecov/codecov-action@v3.1.0
50 changes: 50 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: '38 2 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: true
matrix:
language: [ 'java' ]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -7,8 +7,12 @@ release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
**.DS_Store
.idea
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
jacoco.exec
.DS_Store

# Eclipse m2e generated files
# Eclipse Core
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# AWS Secrets Manager JDBC Library

![build](https://github.com/aws/aws-secretsmanager-jdbc/actions/workflows/CI.yml/badge.svg)
[![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)
[![Coverage](https://codecov.io/gh/aws/aws-secretsmanager-jdbc/branch/master/graph/badge.svg?token=hCl7eBaSwn)](https://codecov.io/gh/aws/aws-secretsmanager-jdbc)

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

@@ -91,3 +92,4 @@ The secret being used should be in the JSON format we use for our rotation lambd
...
}
```

72 changes: 60 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -16,24 +16,24 @@
<artifactId>aws-secretsmanager-jdbc</artifactId>
<packaging>jar</packaging>
<name>AWS Secrets Manager SQL Connection Library</name>
<version>1.0.8</version>
<version>1.0.9</version>
<description>The AWS Secrets Manager SQL Connection Library for Java enables Java developers to easily
connect to SQL databases using secrets stored in AWS Secrets Manager.
</description>
<url>https://aws.amazon.com/secrets-manager</url>

<properties>
<aws-java-sdk.version>1.12.148</aws-java-sdk.version>
<aws-java-sdk.version>1.12.252</aws-java-sdk.version>
<aws-secretsmanager-cache.version>1.0.2</aws-secretsmanager-cache.version>
<lombok.version>1.18.24</lombok.version>
<jackson.version>2.13.2.2</jackson.version>
<junit.version>4.13.1</junit.version>
<jackson.version>2.13.4.2</jackson.version>
<junit.version>4.13.2</junit.version>
<mockito.version>1.10.19</mockito.version>
<powermock.version>1.6.6</powermock.version>
<compiler.plugin.version>3.2</compiler.plugin.version>
<javadoc.plugin.version>3.0.1</javadoc.plugin.version>
<source.plugin.version>3.0.1</source.plugin.version>
<checkstyle.plugin.version>2.17</checkstyle.plugin.version>
<powermock.version>1.7.0</powermock.version>
<compiler.plugin.version>3.10.1</compiler.plugin.version>
<javadoc.plugin.version>3.4.0</javadoc.plugin.version>
<source.plugin.version>3.2.1</source.plugin.version>
<checkstyle.plugin.version>3.1.2</checkstyle.plugin.version>
<findbugs.plugin.version>3.0.5</findbugs.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@@ -125,6 +125,12 @@
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>0.8.8</version>
</dependency>
</dependencies>

<build>
@@ -206,6 +212,48 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

@@ -217,7 +265,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<version>3.0.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
@@ -231,7 +279,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype-nexus-staging</serverId>
@@ -243,4 +291,4 @@
</build>
</profile>
</profiles>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -12,10 +12,10 @@
*/
package com.amazonaws.secretsmanager.sql;

import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.secretsmanager.util.Config;
import com.amazonaws.secretsmanager.caching.SecretCache;
import com.amazonaws.secretsmanager.caching.SecretCacheConfiguration;
import com.amazonaws.secretsmanager.util.JDBCSecretCacheBuilderProvider;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;
import com.amazonaws.util.StringUtils;
@@ -105,13 +105,6 @@ public abstract class AWSSecretsManagerDriver implements Driver {
*/
public static final String INVALID_SECRET_STRING_JSON = "Could not parse SecretString JSON";

/**
* Configuration property to override PrivateLink DNS URL for Secrets Manager
*/
private static final String PROPERTY_VPC_ENDPOINT_URL = "vpcEndpointUrl";

private static final String PROPERTY_VPC_ENDPOINT_REGION = "vpcEndpointRegion";

private SecretCache secretCache;

private String realDriverClass;
@@ -120,35 +113,25 @@ public abstract class AWSSecretsManagerDriver implements Driver {

private ObjectMapper mapper = new ObjectMapper();



/**
* Constructs the driver setting the properties from the properties file using system properties as defaults.
* Instantiates the secret cache with default options.
*/
protected AWSSecretsManagerDriver() {
this(new SecretCache());
this(new JDBCSecretCacheBuilderProvider().build());
}


/**
* Constructs the driver setting the properties from the properties file using system properties as defaults.
* Sets the secret cache to the cache that was passed in.
*
* @param cache Secret cache to use to retrieve secrets
*/
protected AWSSecretsManagerDriver(SecretCache cache) {

final Config config = Config.loadMainConfig();

String vpcEndpointUrl = config.getStringPropertyWithDefault(PROPERTY_PREFIX+"."+PROPERTY_VPC_ENDPOINT_URL, null);
String vpcEndpointRegion = config.getStringPropertyWithDefault(PROPERTY_PREFIX+"."+PROPERTY_VPC_ENDPOINT_REGION, null);

if (vpcEndpointUrl == null || vpcEndpointUrl.isEmpty() || vpcEndpointRegion == null || vpcEndpointRegion.isEmpty()) {
this.secretCache = cache;
} else {
AWSSecretsManagerClientBuilder builder = AWSSecretsManagerClientBuilder.standard();
builder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(vpcEndpointUrl, vpcEndpointRegion));

this.secretCache = new SecretCache(builder);
}
this.secretCache = cache;

setProperties();
AWSSecretsManagerDriver.register(this);
@@ -186,8 +169,6 @@ protected AWSSecretsManagerDriver(SecretCacheConfiguration cacheConfig) {

/**
* Sets general configuration properties that are unrelated to the API client.
*
* @param config The main configuration for this driver.
*/
private void setProperties() {
this.config = Config.loadMainConfig().getSubconfig(PROPERTY_PREFIX + "." + getPropertySubprefix());
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ private static Properties loadPropertiesFromConfigFile(String resourceName) {
InputStream configFile;

try {
configFile = ClassLoader.getSystemResourceAsStream(resourceName);
configFile = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
if(configFile != null) {
newConfig.load(configFile);
configFile.close();
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.amazonaws.secretsmanager.util;

import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.secretsmanager.sql.AWSSecretsManagerDriver;
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;

import static com.amazonaws.util.StringUtils.isNullOrEmpty;

/**
* <p>
* A class for providing JDBC driver the secrets cache builder.
*
* Checks the config file and environment variables for overrides to the default
* region and applies those changes to the provided secret cache builder.
* </p>
*/
public class JDBCSecretCacheBuilderProvider {

/**
* Configuration property to override PrivateLink DNS URL for Secrets Manager
*/
static final String PROPERTY_VPC_ENDPOINT_URL = "vpcEndpointUrl";

static final String PROPERTY_VPC_ENDPOINT_REGION = "vpcEndpointRegion";

/**
* Configuration properties to override the default region
*/
static final String PROPERTY_REGION = "region";

static final String REGION_ENVIRONMENT_VARIABLE = "AWS_SECRET_JDBC_REGION";


private Config configFile;


public JDBCSecretCacheBuilderProvider() {
this(Config.loadMainConfig());
}

public JDBCSecretCacheBuilderProvider(Config config) {
configFile = config;
}

/**
* Provides the secrets cache builder.
*
* 1) If a PrivateLink DNS endpoint URL and region are given in the Config, then they are used to configure the endpoint.
* 2) The AWS_SECRET_JDBC_REGION environment variable is checked. If set, it is used to configure the region.
* 3) The region variable file is checked in the provided Config and, if set, used to configure the region.
* 4) Finally, if none of these are not found, the default region provider chain is used.
*
* @return the built secret cache.
*/
public AWSSecretsManagerClientBuilder build() {

AWSSecretsManagerClientBuilder builder = AWSSecretsManagerClientBuilder.standard();

//Retrieve data from information sources.
String vpcEndpointUrl = configFile.getStringPropertyWithDefault(AWSSecretsManagerDriver.PROPERTY_PREFIX+"."+PROPERTY_VPC_ENDPOINT_URL, null);
String vpcEndpointRegion = configFile.getStringPropertyWithDefault(AWSSecretsManagerDriver.PROPERTY_PREFIX+"."+PROPERTY_VPC_ENDPOINT_REGION, null);
String envRegion = System.getenv(REGION_ENVIRONMENT_VARIABLE);
String configRegion = configFile.getStringPropertyWithDefault(AWSSecretsManagerDriver.PROPERTY_PREFIX+"."+PROPERTY_REGION, null);


//Apply settings to our builder configuration.
if ( !isNullOrEmpty(vpcEndpointUrl) && !isNullOrEmpty(vpcEndpointRegion) ) {
builder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(vpcEndpointUrl, vpcEndpointRegion));
} else if ( !isNullOrEmpty(envRegion) ) {
builder.withRegion(envRegion);
} else if ( !isNullOrEmpty(configRegion) ) {
builder.withRegion(configRegion);
}

return builder;
}
}
Loading