Skip to content

Commit

Permalink
Optional prefix in overriden settings
Browse files Browse the repository at this point in the history
Signed-off-by: Vikas Bansal <43470111+vikasvb90@users.noreply.github.com>
  • Loading branch information
vikasvb90 committed Sep 4, 2023
1 parent 65c4c09 commit a494816
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static KmsClientSettings getClientSettings(Settings settings) {
KmsClientSettings getMetadataSettings(Settings settings) {
AwsCredentials newCredentials = loadCredentials(settings);
newCredentials = newCredentials == null ? this.credentials : newCredentials;
final Settings normalizedSettings = Settings.builder().put(settings).build();
final Settings normalizedSettings = Settings.builder().put(settings).normalizePrefix("kms.").build();

String newProxyUsername = this.proxyUsername, newProxyPassword = this.proxyPassword;
if (PROXY_USERNAME_SETTING.exists(normalizedSettings)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ public void testSpecificEndpoint() {
assertEquals(baseSettings.endpoint, "kms.endpoint");
}

public void testOverrideWithMetadataSettings() {
public void testOverrideWithPrefixedMetadataSettings() {
overrideWithMetadataSettings("kms.");
}

public void testOverrideWithNoPrefixMetadataSettings() {
overrideWithMetadataSettings("");
}

public void overrideWithMetadataSettings(String prefix) {
final MockSecureSettings secureSettings = new MockSecureSettings();
String accessKey = "access_key", secretKey = "secret_key", sessionToken = "session_token";
secureSettings.setString("kms.access_key", accessKey);
Expand All @@ -104,7 +112,7 @@ public void testOverrideWithMetadataSettings() {
{
final String endpoint = "some.host";
final KmsClientSettings refinedSettings = baseSettings.getMetadataSettings(
Settings.builder().put("kms.endpoint", endpoint).build()
Settings.builder().put(prefix + "endpoint", endpoint).build()
);
assertEquals(refinedSettings.endpoint, endpoint);
validateCredsAreStillSame(refinedSettings, accessKey, secretKey, sessionToken);
Expand All @@ -113,7 +121,7 @@ public void testOverrideWithMetadataSettings() {
{
String region = "eu-west-1";
final KmsClientSettings refinedSettings = baseSettings.getMetadataSettings(
Settings.builder().put("kms.region", region).build()
Settings.builder().put(prefix + "region", region).build()
);
assertEquals(refinedSettings.region, region);
validateCredsAreStillSame(refinedSettings, accessKey, secretKey, sessionToken);
Expand All @@ -122,7 +130,7 @@ public void testOverrideWithMetadataSettings() {
{
String proxyHost = "proxy-host";
final KmsClientSettings refinedSettings = baseSettings.getMetadataSettings(
Settings.builder().put("kms.proxy.host", proxyHost).build()
Settings.builder().put(prefix + "proxy.host", proxyHost).build()
);
assertEquals(refinedSettings.proxyHost, proxyHost);
validateCredsAreStillSame(refinedSettings, accessKey, secretKey, sessionToken);
Expand All @@ -131,7 +139,7 @@ public void testOverrideWithMetadataSettings() {
{
int proxyPort = 70;
final KmsClientSettings refinedSettings = baseSettings.getMetadataSettings(
Settings.builder().put("kms.proxy.port", proxyPort).build()
Settings.builder().put(prefix + "proxy.port", proxyPort).build()
);
assertEquals(refinedSettings.proxyPort, proxyPort);
validateCredsAreStillSame(refinedSettings, accessKey, secretKey, sessionToken);
Expand All @@ -140,7 +148,7 @@ public void testOverrideWithMetadataSettings() {
{
TimeValue readTimeout = TimeValue.timeValueMillis(5000);
final KmsClientSettings refinedSettings = baseSettings.getMetadataSettings(
Settings.builder().put("kms.read_timeout", readTimeout).build()
Settings.builder().put(prefix + "read_timeout", readTimeout).build()
);
assertEquals(refinedSettings.readTimeoutMillis, readTimeout.getMillis());
validateCredsAreStillSame(refinedSettings, accessKey, secretKey, sessionToken);
Expand Down

0 comments on commit a494816

Please sign in to comment.