From 658ec5839ccc88e40deabf1c78c9e8288246fedb Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 17 Mar 2023 10:22:08 +0100 Subject: [PATCH] Add support for a singleton Region in AwsIamAuthenticationOptions. See gh-758 --- .../AwsIamAuthenticationOptions.java | 14 ++++++++++++++ .../AwsIamAuthenticationUnitTests.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spring-vault-core/src/main/java/org/springframework/vault/authentication/AwsIamAuthenticationOptions.java b/spring-vault-core/src/main/java/org/springframework/vault/authentication/AwsIamAuthenticationOptions.java index 0f35084e..d30c3b8f 100644 --- a/spring-vault-core/src/main/java/org/springframework/vault/authentication/AwsIamAuthenticationOptions.java +++ b/spring-vault-core/src/main/java/org/springframework/vault/authentication/AwsIamAuthenticationOptions.java @@ -20,6 +20,7 @@ import java.net.URI; import software.amazon.awssdk.auth.credentials.AwsCredentials; import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.regions.providers.AwsRegionProvider; import software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain; @@ -212,6 +213,19 @@ public class AwsIamAuthenticationOptions { return this; } + /** + * Configure a {@link Region}, used for computing the signature. + * @param region must not be {@literal null}. + * @return {@code this} {@link AwsIamAuthenticationOptionsBuilder}. + * @since 3.0.2 + */ + public AwsIamAuthenticationOptionsBuilder region(Region region) { + + Assert.notNull(region, "Region must not be null"); + + return regionProvider(() -> region); + } + /** * Configure an {@link AwsRegionProvider}, required to calculate the region to be * used for computing the signature. diff --git a/spring-vault-core/src/test/java/org/springframework/vault/authentication/AwsIamAuthenticationUnitTests.java b/spring-vault-core/src/test/java/org/springframework/vault/authentication/AwsIamAuthenticationUnitTests.java index 17e99ed4..3ae5e4c4 100644 --- a/spring-vault-core/src/test/java/org/springframework/vault/authentication/AwsIamAuthenticationUnitTests.java +++ b/spring-vault-core/src/test/java/org/springframework/vault/authentication/AwsIamAuthenticationUnitTests.java @@ -89,7 +89,7 @@ class AwsIamAuthenticationUnitTests { + "}")); AwsIamAuthenticationOptions options = AwsIamAuthenticationOptions.builder().role("foo-role") - .regionProvider(() -> Region.US_WEST_1).credentials(AwsBasicCredentials.create("foo", "bar")).build(); + .region(Region.US_WEST_1).credentials(AwsBasicCredentials.create("foo", "bar")).build(); AuthenticationSteps steps = AwsIamAuthentication.createAuthenticationSteps(options); AuthenticationStepsExecutor executor = new AuthenticationStepsExecutor(steps, this.restTemplate);