-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add override for default region. #88
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
16cebc4
Add override for default region.
danmancuso d848302
Fixed unit tests
danmancuso 85fe743
Merge branch 'master' into region-override
danmancuso d3c1a46
Increment library version number
simonmarty cf9bf5d
Merge branch 'master' into region-override
danmancuso 5a6153d
Add newline to readme.
danmancuso 8287d5a
Used isNullOrEmpty for cleaner checking
danmancuso 3564aa5
Updated ignore file
danmancuso f666daa
Remove unused import.
danmancuso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/com/amazonaws/secretsmanager/util/JDBCSecretCacheBuilderProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These provide a way to override the default region and I do like this change for other use cases (so don't revert it), but we also want a way for customers to configure a backup region in order to provide high availability using replicated secrets. There are multiple ways to accomplish this. Some potential options:
In both approaches, if a Secret ARN is provided, we probably want to do some automatic region substitution as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is spot on with our need. During DR testing, we would like to be able to configure failover secret/region config to be used.