Moves to aws sdk v2. (#2111)

* Moves to aws sdk v2.  Fixes #2038 and #2106
This commit is contained in:
Ryan Baxter
2022-06-16 15:02:01 -04:00
committed by GitHub
parent ec4c448c10
commit 399c9ec6b4
20 changed files with 204 additions and 222 deletions

View File

@@ -340,17 +340,17 @@ This helper is not used with the JGit library, so a JGit CredentialProvider for
AWS CodeCommit URIs follow this pattern:
```bash
https//git-codecommit.${AWS_REGION}.amazonaws.com/v1/repos/${repo}.
https://git-codecommit.${AWS_REGION}.amazonaws.com/v1/repos/${repo}
```
If you provide a username and password with an AWS CodeCommit URI, they must be the https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html[AWS accessKeyId and secretAccessKey] that provide access to the repository.
If you do not specify a username and password, the accessKeyId and secretAccessKey are retrieved by using the https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html[AWS Default Credential Provider Chain].
If you do not specify a username and password, the accessKeyId and secretAccessKey are retrieved by using the https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/credentials.html[Default Credential Provider Chain].
If your Git URI matches the CodeCommit URI pattern (shown earlier), you must provide valid AWS credentials in the username and password or in one of the locations supported by the default credential provider chain.
AWS EC2 instances may use https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html[IAM Roles for EC2 Instances].
NOTE: The `aws-java-sdk-core` jar is an optional dependency.
If the `aws-java-sdk-core` jar is not on your classpath, the AWS Code Commit credential provider is not created, regardless of the git server URI.
NOTE: The `software.amazon.awssdk:auth` jar is an optional dependency.
If the `software.amazon.awssdk:auth` jar is not on your classpath, the AWS Code Commit credential provider is not created, regardless of the git server URI.
===== Authentication with Google Cloud Source
@@ -940,15 +940,15 @@ NOTE: When no profile is specified `default` will be used.
==== AWS S3 Backend
Spring Cloud Config Server supports AWS S3 as a backend for configuration properties.
You can enable this feature by adding a dependency to the link:https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-s3.html[AWS Java SDK For Amazon S3].
You can enable this feature by adding a dependency to the link:https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/examples-s3.html[AWS Java SDK For Amazon S3].
[source,xml,indent=0]
.pom.xml
----
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
</dependencies>
----
@@ -970,7 +970,7 @@ spring:
It is also possible to specify an AWS URL to link:https://aws.amazon.com/blogs/developer/using-new-regions-and-endpoints/[override the standard endpoint] of your S3 service with `spring.cloud.config.server.awss3.endpoint`. This allows support for beta regions of S3, and other S3 compatible storage APIs.
Credentials are found using the link:https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html[Default AWS Credential Provider Chain]. Versioned and encrypted buckets are supported without further configuration.
Credentials are found using the link:https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/credentials.html[Default Credential Provider Chain]. Versioned and encrypted buckets are supported without further configuration.
Configuration files are stored in your bucket as `{application}-{profile}.properties`, `{application}-{profile}.yml` or `{application}-{profile}.json`. An optional label can be provided to specify a directory path to the file.
@@ -978,14 +978,14 @@ NOTE: When no profile is specified `default` will be used.
==== AWS Parameter Store Backend
Spring Cloud Config Server supports AWS Parameter Store as a backend for configuration properties. You can enable this feature by adding a dependency to the link:https://github.com/aws/aws-sdk-java/tree/master/aws-java-sdk-ssm[AWS Java SDK for SSM].
Spring Cloud Config Server supports AWS Parameter Store as a backend for configuration properties. You can enable this feature by adding a dependency to the link:https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/examples-ssm.html[AWS Java SDK for SSM].
[source,xml,indent=0]
.pom.xml
----
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ssm</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ssm</artifactId>
</dependency>
----
@@ -1019,7 +1019,7 @@ The following table describes the AWS Parameter Store configuration properties.
|*region*
|no
|
|The region to be used by the AWS Parameter Store client. If it's not explicitly set, the SDK tries to determine the region to use by using the link:https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-region-selection.html#default-region-provider-chain[Default Region Provider Chain].
|The region to be used by the AWS Parameter Store client. If it's not explicitly set, the SDK tries to determine the region to use by using the link:https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/region-selection.html#default-region-provider-chain[Default Region Provider Chain].
|*endpoint*
|no
@@ -1058,7 +1058,7 @@ The following table describes the AWS Parameter Store configuration properties.
|===
AWS Parameter Store API credentials are determined using the link:https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-default[Default Credential Provider Chain].
AWS Parameter Store API credentials are determined using the link:https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/credentials.html#credentials-default[Default Credential Provider Chain].
Versioned parameters are already supported with the default behaviour of returning the latest version.
[NOTE]
@@ -1072,14 +1072,14 @@ Versioned parameters are already supported with the default behaviour of returni
==== AWS Secrets Manager Backend
Spring Cloud Config Server supports link:https://aws.amazon.com/secrets-manager/[AWS Secrets Manager] as a backend for configuration properties.
You can enable this feature by adding a dependency to link:https://github.com/aws/aws-sdk-java/tree/master/aws-java-sdk-secretsmanager[AWS Java SDK for Secrets Manager].
You can enable this feature by adding a dependency to link:https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/examples-secretsmanager.html[AWS Java SDK for Secrets Manager].
[source,xml,indent=0]
.pom.xml
----
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>secretsmanager</artifactId>
</dependency>
----
@@ -1102,7 +1102,7 @@ spring:
----
AWS Secrets Manager API credentials are determined using link:https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-default[Default Credential Provider Chain].
AWS Secrets Manager API credentials are determined using link:https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/credentials.html#credentials-default[Default Credential Provider Chain].
[NOTE]
====
@@ -1816,7 +1816,7 @@ For instance, you might want to align the config label with your branch but make
=== Specifying Multiple URLs for the Config Server
To ensure high availability when you have multiple instances of Config Server deployed and expect one or more instances to be unavailable or unable to honor requests from time to time (such as if the Git server is down), you can either specify multiple URLs (as a comma-separated list under the `spring.cloud.config.uri` property) or have all your instances register in a Service Registry like Eureka (if using Discovery-First Bootstrap mode).
To ensure high availability when you have multiple instances of Config Server deployed and expect one or more instances to be unavailable or unable to honor requests from time to time (such as if the Git server is down), you can either specify multiple URLs (as a comma-separated list under the `spring.cloud.config.uri` property) or have all your instances register in a Service Registry like Eureka (if using Discovery-First Bootstrap mode).
The URLs listed under `spring.cloud.config.uri` are tried in the order listed. By default, the Config Client will try to fetch properties from each URL until an attempt is successful to ensure high availability.

23
pom.xml
View File

@@ -28,7 +28,7 @@
<properties>
<bintray.package>config</bintray.package>
<spring-cloud-commons.version>4.0.0-SNAPSHOT</spring-cloud-commons.version>
<aws-java-sdk.version>1.11.911</aws-java-sdk.version>
<aws-java-sdk.version>2.17.195</aws-java-sdk.version>
<google-api-services-iam.version>v1-rev20201112-1.30.10</google-api-services-iam.version>
<testcontainers.version>1.16.2</testcontainers.version>
<wiremock.version>2.31.0</wiremock.version>
@@ -71,24 +71,11 @@
<version>${spring-cloud-commons.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ssm</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>${aws-java-sdk.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>

View File

@@ -16,7 +16,7 @@
<description>Spring Cloud Config Dependencies</description>
<properties>
<jgit.version>5.12.0.202106070339-r</jgit.version>
<spring-vault.version>2.3.2</spring-vault.version>
<spring-vault.version>3.0.0-M1</spring-vault.version>
<spring-credhub.version>2.1.1.RELEASE</spring-credhub.version>
</properties>
<dependencyManagement>

View File

@@ -94,23 +94,28 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>auth</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-core</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ssm</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>secretsmanager</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ssm</artifactId>
<optional>true</optional>
</dependency>
<dependency>

View File

@@ -19,14 +19,14 @@ package org.springframework.cloud.config.server.config;
import java.util.List;
import java.util.Optional;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.google.cloud.secretmanager.v1.SecretManagerServiceClient;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.http.client.HttpClient;
import org.eclipse.jgit.api.TransportConfigCallback;
import org.tmatesoft.svn.core.SVNException;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.ssm.SsmClient;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
@@ -210,7 +210,7 @@ public class EnvironmentRepositoryConfiguration {
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(AmazonS3.class)
@ConditionalOnClass(S3Client.class)
static class AwsS3FactoryConfig {
@Bean
@@ -221,7 +221,7 @@ public class EnvironmentRepositoryConfiguration {
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(AWSSecretsManager.class)
@ConditionalOnClass(SecretsManagerClient.class)
static class AwsSecretsManagerFactoryConfig {
@Bean
@@ -233,7 +233,7 @@ public class EnvironmentRepositoryConfiguration {
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(AWSSimpleSystemsManagement.class)
@ConditionalOnClass(SsmClient.class)
static class AwsParameterStoreFactoryConfig {
@Bean

View File

@@ -16,8 +16,10 @@
package org.springframework.cloud.config.server.environment;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.client.builder.AwsSyncClientBuilder;
import java.net.URI;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
import software.amazon.awssdk.regions.Region;
import org.springframework.util.StringUtils;
@@ -26,15 +28,11 @@ abstract class AwsClientBuilderConfigurer {
private AwsClientBuilderConfigurer() {
}
static void configureClientBuilder(AwsSyncClientBuilder<?, ?> clientBuilder, String region, String endpoint) {
static void configureClientBuilder(AwsClientBuilder<?, ?> clientBuilder, String region, String endpoint) {
if (StringUtils.hasText(region)) {
clientBuilder.region(Region.of(region));
if (StringUtils.hasText(endpoint)) {
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(
endpoint, region);
clientBuilder.withEndpointConfiguration(endpointConfiguration);
}
else {
clientBuilder.withRegion(region);
clientBuilder.endpointOverride(URI.create(endpoint));
}
}
}

View File

@@ -26,10 +26,10 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest;
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult;
import com.amazonaws.services.simplesystemsmanagement.model.Parameter;
import software.amazon.awssdk.services.ssm.SsmClient;
import software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest;
import software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse;
import software.amazon.awssdk.services.ssm.model.Parameter;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
@@ -43,14 +43,13 @@ import static org.springframework.cloud.config.server.environment.AwsParameterSt
*/
public class AwsParameterStoreEnvironmentRepository implements EnvironmentRepository {
private final AWSSimpleSystemsManagement awsSsmClient;
private final SsmClient awsSsmClient;
private final ConfigServerProperties configServerProperties;
private final AwsParameterStoreEnvironmentProperties environmentProperties;
public AwsParameterStoreEnvironmentRepository(AWSSimpleSystemsManagement awsSsmClient,
ConfigServerProperties configServerProperties,
public AwsParameterStoreEnvironmentRepository(SsmClient awsSsmClient, ConfigServerProperties configServerProperties,
AwsParameterStoreEnvironmentProperties environmentProperties) {
this.awsSsmClient = awsSsmClient;
this.configServerProperties = configServerProperties;
@@ -137,20 +136,20 @@ public class AwsParameterStoreEnvironmentRepository implements EnvironmentReposi
private Map<String, String> getPropertiesByParameterPath(String path) {
Map<String, String> result = new HashMap<>();
GetParametersByPathRequest request = new GetParametersByPathRequest().withPath(path)
.withRecursive(environmentProperties.isRecursive())
.withWithDecryption(environmentProperties.isDecryptValues())
.withMaxResults(environmentProperties.getMaxResults());
GetParametersByPathRequest request = GetParametersByPathRequest.builder().path(path)
.recursive(environmentProperties.isRecursive()).withDecryption(environmentProperties.isDecryptValues())
.maxResults(environmentProperties.getMaxResults()).build();
GetParametersByPathResult response = awsSsmClient.getParametersByPath(request);
GetParametersByPathResponse response = awsSsmClient.getParametersByPath(request);
if (response != null) {
addParametersToProperties(path, response.getParameters(), result);
addParametersToProperties(path, response.parameters(), result);
while (StringUtils.hasLength(response.getNextToken())) {
response = awsSsmClient.getParametersByPath(request.withNextToken(response.getNextToken()));
while (StringUtils.hasLength(response.nextToken())) {
response = awsSsmClient
.getParametersByPath(request.toBuilder().nextToken(response.nextToken()).build());
addParametersToProperties(path, response.getParameters(), result);
addParametersToProperties(path, response.parameters(), result);
}
}
@@ -159,9 +158,9 @@ public class AwsParameterStoreEnvironmentRepository implements EnvironmentReposi
private void addParametersToProperties(String path, List<Parameter> parameters, Map<String, String> properties) {
for (Parameter parameter : parameters) {
String name = StringUtils.delete(parameter.getName(), path).replace(DEFAULT_PATH_SEPARATOR, ".");
String name = StringUtils.delete(parameter.name(), path).replace(DEFAULT_PATH_SEPARATOR, ".");
properties.put(name, parameter.getValue());
properties.put(name, parameter.value());
}
}

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.config.server.environment;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
import software.amazon.awssdk.services.ssm.SsmClient;
import software.amazon.awssdk.services.ssm.SsmClientBuilder;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
@@ -37,11 +37,11 @@ public class AwsParameterStoreEnvironmentRepositoryFactory implements
@Override
public AwsParameterStoreEnvironmentRepository build(AwsParameterStoreEnvironmentProperties environmentProperties) {
AWSSimpleSystemsManagementClientBuilder clientBuilder = AWSSimpleSystemsManagementClientBuilder.standard();
SsmClientBuilder clientBuilder = SsmClient.builder();
configureClientBuilder(clientBuilder, environmentProperties.getRegion(), environmentProperties.getEndpoint());
AWSSimpleSystemsManagement client = clientBuilder.build();
SsmClient client = clientBuilder.build();
return new AwsParameterStoreEnvironmentRepository(client, configServerProperties, environmentProperties);
}

View File

@@ -20,10 +20,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectIdBuilder;
import software.amazon.awssdk.core.ResponseInputStream;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.cloud.config.environment.Environment;
@@ -43,7 +43,7 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
private static final String PATH_SEPARATOR = "/";
private final AmazonS3 s3Client;
private final S3Client s3Client;
private final String bucketName;
@@ -51,7 +51,7 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
protected int order = Ordered.LOWEST_PRECEDENCE;
public AwsS3EnvironmentRepository(AmazonS3 s3Client, String bucketName, ConfigServerProperties server) {
public AwsS3EnvironmentRepository(S3Client s3Client, String bucketName, ConfigServerProperties server) {
this.s3Client = s3Client;
this.bucketName = bucketName;
this.serverProperties = server;
@@ -68,11 +68,11 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
@Override
public Environment findOne(String specifiedApplication, String specifiedProfiles, String specifiedLabel) {
final String application = StringUtils.isEmpty(specifiedApplication)
final String application = !StringUtils.hasText(specifiedApplication)
? serverProperties.getDefaultApplicationName() : specifiedApplication;
final String profiles = StringUtils.isEmpty(specifiedProfiles) ? serverProperties.getDefaultProfile()
final String profiles = !StringUtils.hasText(specifiedProfiles) ? serverProperties.getDefaultProfile()
: specifiedProfiles;
final String label = StringUtils.isEmpty(specifiedLabel) ? serverProperties.getDefaultLabel() : specifiedLabel;
final String label = !StringUtils.hasText(specifiedLabel) ? serverProperties.getDefaultLabel() : specifiedLabel;
String[] profileArray = parseProfiles(profiles);
String[] apps = new String[] { application };
@@ -113,9 +113,7 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
private S3ConfigFile getS3ConfigFile(String application, String profile, String label) {
String objectKeyPrefix = buildObjectKeyPrefix(application, profile, label);
final S3ObjectIdBuilder s3ObjectIdBuilder = new S3ObjectIdBuilder().withBucket(bucketName);
return getS3ConfigFile(s3ObjectIdBuilder, objectKeyPrefix);
return getS3ConfigFile(objectKeyPrefix);
}
private String buildObjectKeyPrefix(String application, String profile, String label) {
@@ -130,24 +128,23 @@ public class AwsS3EnvironmentRepository implements EnvironmentRepository, Ordere
return objectKeyPrefix.toString();
}
private S3ConfigFile getS3ConfigFile(S3ObjectIdBuilder s3ObjectIdBuilder, String keyPrefix) {
private S3ConfigFile getS3ConfigFile(String keyPrefix) {
try {
final S3Object properties = s3Client
.getObject(new GetObjectRequest(s3ObjectIdBuilder.withKey(keyPrefix + ".properties").build()));
return new PropertyS3ConfigFile(properties.getObjectMetadata().getVersionId(),
properties.getObjectContent());
final ResponseInputStream<GetObjectResponse> responseInputStream = s3Client
.getObject(GetObjectRequest.builder().bucket(bucketName).key(keyPrefix + ".properties").build());
return new PropertyS3ConfigFile(responseInputStream.response().versionId(), responseInputStream);
}
catch (Exception eProperties) {
try {
final S3Object yaml = s3Client
.getObject(new GetObjectRequest(s3ObjectIdBuilder.withKey(keyPrefix + ".yml").build()));
return new YamlS3ConfigFile(yaml.getObjectMetadata().getVersionId(), yaml.getObjectContent());
final ResponseInputStream<GetObjectResponse> responseInputStream = s3Client
.getObject(GetObjectRequest.builder().bucket(bucketName).key(keyPrefix + ".yml").build());
return new YamlS3ConfigFile(responseInputStream.response().versionId(), responseInputStream);
}
catch (Exception eYaml) {
try {
final S3Object json = s3Client
.getObject(new GetObjectRequest(s3ObjectIdBuilder.withKey(keyPrefix + ".json").build()));
return new JsonS3ConfigFile(json.getObjectMetadata().getVersionId(), json.getObjectContent());
final ResponseInputStream<GetObjectResponse> responseInputStream = s3Client
.getObject(GetObjectRequest.builder().bucket(bucketName).key(keyPrefix + ".json").build());
return new JsonS3ConfigFile(responseInputStream.response().versionId(), responseInputStream);
}
catch (Exception eJson) {
return null;

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.config.server.environment;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3ClientBuilder;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
@@ -34,9 +34,9 @@ public class AwsS3EnvironmentRepositoryFactory
@Override
public AwsS3EnvironmentRepository build(AwsS3EnvironmentProperties environmentProperties) {
final AmazonS3ClientBuilder clientBuilder = AmazonS3ClientBuilder.standard();
final S3ClientBuilder clientBuilder = S3Client.builder();
configureClientBuilder(clientBuilder, environmentProperties.getRegion(), environmentProperties.getEndpoint());
final AmazonS3 client = clientBuilder.build();
final S3Client client = clientBuilder.build();
AwsS3EnvironmentRepository repository = new AwsS3EnvironmentRepository(client,
environmentProperties.getBucket(), server);

View File

@@ -21,14 +21,14 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest;
import com.amazonaws.services.secretsmanager.model.GetSecretValueResult;
import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;
import software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
@@ -48,7 +48,7 @@ public class AwsSecretsManagerEnvironmentRepository implements EnvironmentReposi
private final ObjectMapper objectMapper;
private final AWSSecretsManager awsSmClient;
private final SecretsManagerClient awsSmClient;
private final ConfigServerProperties configServerProperties;
@@ -56,7 +56,7 @@ public class AwsSecretsManagerEnvironmentRepository implements EnvironmentReposi
private final int order;
public AwsSecretsManagerEnvironmentRepository(AWSSecretsManager awsSmClient,
public AwsSecretsManagerEnvironmentRepository(SecretsManagerClient awsSmClient,
ConfigServerProperties configServerProperties,
AwsSecretsManagerEnvironmentProperties environmentProperties) {
this.awsSmClient = awsSmClient;
@@ -135,12 +135,12 @@ public class AwsSecretsManagerEnvironmentRepository implements EnvironmentReposi
private Map<Object, Object> findProperties(String path) {
Map<Object, Object> properties = new HashMap<>();
GetSecretValueRequest request = new GetSecretValueRequest().withSecretId(path);
GetSecretValueRequest request = GetSecretValueRequest.builder().secretId(path).build();
try {
GetSecretValueResult response = awsSmClient.getSecretValue(request);
GetSecretValueResponse response = awsSmClient.getSecretValue(request);
if (response != null) {
Map<String, Object> secretMap = objectMapper.readValue(response.getSecretString(),
Map<String, Object> secretMap = objectMapper.readValue(response.secretString(),
new TypeReference<Map<String, Object>>() {
});

View File

@@ -16,8 +16,8 @@
package org.springframework.cloud.config.server.environment;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.amazonaws.services.secretsmanager.AWSSecretsManagerClientBuilder;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
@@ -37,11 +37,11 @@ public class AwsSecretsManagerEnvironmentRepositoryFactory implements
@Override
public AwsSecretsManagerEnvironmentRepository build(AwsSecretsManagerEnvironmentProperties environmentProperties) {
AWSSecretsManagerClientBuilder clientBuilder = AWSSecretsManagerClientBuilder.standard();
SecretsManagerClientBuilder clientBuilder = SecretsManagerClient.builder();
configureClientBuilder(clientBuilder, environmentProperties.getRegion(), environmentProperties.getEndpoint());
AWSSecretsManager client = clientBuilder.build();
SecretsManagerClient client = clientBuilder.build();
return new AwsSecretsManagerEnvironmentRepository(client, configServerProperties, environmentProperties);
}

View File

@@ -18,9 +18,9 @@ package org.springframework.cloud.config.server.environment.vault.authentication
import java.util.concurrent.atomic.AtomicReference;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import org.springframework.cloud.config.server.environment.VaultEnvironmentProperties;
import org.springframework.cloud.config.server.environment.VaultEnvironmentProperties.AuthenticationMethod;
@@ -41,12 +41,12 @@ public class AwsIamClientAuthenticationProvider extends SpringVaultClientAuthent
public ClientAuthentication getClientAuthentication(VaultEnvironmentProperties vaultProperties,
RestOperations vaultRestOperations, RestOperations externalRestOperations) {
assertClassPresent("com.amazonaws.auth.AWSCredentials",
missingClassForAuthMethod("AWSCredentials", "aws-java-sdk-core", AuthenticationMethod.AWS_IAM));
assertClassPresent("software.amazon.awssdk.auth.credentials.AwsCredentials",
missingClassForAuthMethod("AwsCredentials", "aws-core", AuthenticationMethod.AWS_IAM));
VaultEnvironmentProperties.AwsIamProperties awsIam = vaultProperties.getAwsIam();
AWSCredentialsProvider credentialsProvider = AwsCredentialProvider.getAwsCredentialsProvider();
AwsCredentialsProvider credentialsProvider = AwsCredentialProvider.getAwsCredentialsProvider();
AwsIamAuthenticationOptions.AwsIamAuthenticationOptionsBuilder builder = AwsIamAuthenticationOptions.builder();
@@ -72,32 +72,27 @@ public class AwsIamClientAuthenticationProvider extends SpringVaultClientAuthent
private static class AwsCredentialProvider {
private static AWSCredentialsProvider getAwsCredentialsProvider() {
private static AwsCredentialsProvider getAwsCredentialsProvider() {
DefaultAWSCredentialsProviderChain backingCredentialsProvider = DefaultAWSCredentialsProviderChain
.getInstance();
DefaultCredentialsProvider backingCredentialsProvider = DefaultCredentialsProvider.create();
// Eagerly fetch credentials preventing lag during the first, actual login.
AWSCredentials firstAccess = backingCredentialsProvider.getCredentials();
AwsCredentials firstAccess = backingCredentialsProvider.resolveCredentials();
AtomicReference<AWSCredentials> once = new AtomicReference<>(firstAccess);
AtomicReference<AwsCredentials> once = new AtomicReference<>(firstAccess);
return new AWSCredentialsProvider() {
return new AwsCredentialsProvider() {
@Override
public AWSCredentials getCredentials() {
public AwsCredentials resolveCredentials() {
if (once.compareAndSet(firstAccess, null)) {
return firstAccess;
}
return backingCredentialsProvider.getCredentials();
return backingCredentialsProvider.resolveCredentials();
}
@Override
public void refresh() {
backingCredentialsProvider.refresh();
}
};
}

View File

@@ -27,18 +27,19 @@ import java.util.TimeZone;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSSessionCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.util.ValidationUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jgit.errors.UnsupportedCredentialItem;
import org.eclipse.jgit.transport.CredentialItem;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.URIish;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import org.springframework.util.Assert;
import static org.springframework.util.StringUtils.hasText;
@@ -79,7 +80,7 @@ public class AwsCodeCommitCredentialProvider extends CredentialsProvider {
* The AWSCredentialsProvider will be used to provide the access key and secret key if
* they are not specified.
*/
private AWSCredentialsProvider awsCredentialProvider;
private AwsCredentialsProvider awsCredentialProvider;
/**
* If the access and secret keys are provided, then the AWSCredentialsProvider will
@@ -253,22 +254,22 @@ public class AwsCodeCommitCredentialProvider extends CredentialsProvider {
* Get the AWSCredentials. If an AWSCredentialProvider was specified, use that,
* otherwise, create a new AWSCredentialsProvider. If the username and password are
* provided, then use those directly as AWSCredentials. Otherwise us the
* {@link DefaultAWSCredentialsProviderChain} as is standard with AWS applications.
* {@link DefaultCredentialsProvider} as is standard with AWS applications.
* @return the AWS credentials.
*/
private AWSCredentials retrieveAwsCredentials() {
private AwsCredentials retrieveAwsCredentials() {
if (this.awsCredentialProvider == null) {
if (this.username != null && this.password != null) {
this.logger.debug("Creating a static AWSCredentialsProvider");
this.awsCredentialProvider = new AWSStaticCredentialsProvider(
new BasicAWSCredentials(this.username, this.password));
AwsBasicCredentials.create(this.username, this.password));
}
else {
this.logger.debug("Creating a default AWSCredentialsProvider");
this.awsCredentialProvider = new DefaultAWSCredentialsProviderChain();
this.awsCredentialProvider = DefaultCredentialsProvider.create();
}
}
return this.awsCredentialProvider.getCredentials();
return this.awsCredentialProvider.resolveCredentials();
}
/**
@@ -282,14 +283,14 @@ public class AwsCodeCommitCredentialProvider extends CredentialsProvider {
String awsAccessKey;
String awsSecretKey;
try {
AWSCredentials awsCredentials = retrieveAwsCredentials();
AwsCredentials awsCredentials = retrieveAwsCredentials();
StringBuilder awsKey = new StringBuilder();
awsKey.append(awsCredentials.getAWSAccessKeyId());
awsSecretKey = awsCredentials.getAWSSecretKey();
if (awsCredentials instanceof AWSSessionCredentials) {
AWSSessionCredentials sessionCreds = (AWSSessionCredentials) awsCredentials;
if (sessionCreds.getSessionToken() != null) {
awsKey.append('%').append(sessionCreds.getSessionToken());
awsKey.append(awsCredentials.accessKeyId());
awsSecretKey = awsCredentials.secretAccessKey();
if (awsCredentials instanceof AwsSessionCredentials) {
AwsSessionCredentials sessionCreds = (AwsSessionCredentials) awsCredentials;
if (sessionCreds.sessionToken() != null) {
awsKey.append('%').append(sessionCreds.sessionToken());
}
}
awsAccessKey = awsKey.toString();
@@ -344,14 +345,14 @@ public class AwsCodeCommitCredentialProvider extends CredentialsProvider {
/**
* @return the awsCredentialProvider
*/
public AWSCredentialsProvider getAwsCredentialProvider() {
public AwsCredentialsProvider getAwsCredentialProvider() {
return this.awsCredentialProvider;
}
/**
* @param awsCredentialProvider the awsCredentialProvider to set
*/
public void setAwsCredentialProvider(AWSCredentialsProvider awsCredentialProvider) {
public void setAwsCredentialProvider(AwsCredentialsProvider awsCredentialProvider) {
this.awsCredentialProvider = awsCredentialProvider;
}
@@ -387,22 +388,20 @@ public class AwsCodeCommitCredentialProvider extends CredentialsProvider {
* Simple implementation of AWSCredentialsProvider that just wraps static
* AWSCredentials. AWS Actually provides this class in newer versions of the AWS API.
*/
public class AWSStaticCredentialsProvider implements AWSCredentialsProvider {
public class AWSStaticCredentialsProvider implements AwsCredentialsProvider {
private final AWSCredentials credentials;
private final AwsCredentials credentials;
public AWSStaticCredentialsProvider(AWSCredentials credentials) {
this.credentials = ValidationUtils.assertNotNull(credentials, "credentials");
public AWSStaticCredentialsProvider(AwsCredentials credentials) {
Assert.notNull(credentials, "credentials");
this.credentials = credentials;
}
public AWSCredentials getCredentials() {
@Override
public AwsCredentials resolveCredentials() {
return this.credentials;
}
public void refresh() {
// Nothing to do for static credentials.
}
}
}

View File

@@ -123,7 +123,7 @@ public class GitCredentialsProviderFactory {
*/
private boolean awsAvailable() {
return this.awsCodeCommitEnabled
&& ClassUtils.isPresent("com.amazonaws.auth.DefaultAWSCredentialsProviderChain", null);
&& ClassUtils.isPresent("software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain", null);
}
/**

View File

@@ -18,12 +18,12 @@ package org.springframework.cloud.config.server.credentials;
import java.net.URISyntaxException;
import com.amazonaws.auth.AWSCredentialsProvider;
import org.eclipse.jgit.errors.UnsupportedCredentialItem;
import org.eclipse.jgit.transport.CredentialItem;
import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
import org.junit.Test;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import org.springframework.cloud.config.server.support.AwsCodeCommitCredentialProvider;
import org.springframework.cloud.config.server.support.GitCredentialsProviderFactory;
@@ -97,13 +97,13 @@ public class AwsCodeCommitCredentialsProviderTests {
@Test
public void testAwsCredentialsProviderIsNullInitially() {
AWSCredentialsProvider awsProvider = this.provider.getAwsCredentialProvider();
AwsCredentialsProvider awsProvider = this.provider.getAwsCredentialProvider();
assertThat(awsProvider).isNull();
}
@Test
public void testAwsCredentialsProviderIsDefinedAfterGet() throws URISyntaxException {
AWSCredentialsProvider awsProvider = this.provider.getAwsCredentialProvider();
AwsCredentialsProvider awsProvider = this.provider.getAwsCredentialProvider();
assertThat(awsProvider).isNull();
assertThat(this.provider.get(new URIish(AWS_REPO), makeCredentialItems())).isTrue();
awsProvider = this.provider.getAwsCredentialProvider();

View File

@@ -29,13 +29,13 @@ import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest;
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult;
import com.amazonaws.services.simplesystemsmanagement.model.Parameter;
import com.amazonaws.services.simplesystemsmanagement.model.ParameterType;
import org.apache.commons.lang3.RandomUtils;
import org.junit.Test;
import software.amazon.awssdk.services.ssm.SsmClient;
import software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest;
import software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse;
import software.amazon.awssdk.services.ssm.model.Parameter;
import software.amazon.awssdk.services.ssm.model.ParameterType;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
@@ -97,8 +97,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
}
};
private final AWSSimpleSystemsManagement awsSsmClientMock = mock(AWSSimpleSystemsManagement.class,
"aws-ssm-client-mock");
private final SsmClient awsSsmClientMock = mock(SsmClient.class, "aws-ssm-client-mock");
private final ConfigServerProperties configServerProperties = new ConfigServerProperties();
@@ -686,7 +685,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
Environment expected = new Environment(application, profiles, null, null, null);
when(awsSsmClientMock.getParametersByPath(any(GetParametersByPathRequest.class)))
.thenReturn(new GetParametersByPathResult());
.thenReturn(GetParametersByPathResponse.builder().build());
// Act
Environment result = repository.findOne(application, profile, null);
@@ -725,14 +724,14 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
for (PropertySource ps : environment.getPropertySources()) {
String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin());
GetParametersByPathRequest request = new GetParametersByPathRequest().withPath(path)
.withRecursive(environmentProperties.isRecursive())
.withWithDecryption(environmentProperties.isDecryptValues())
.withMaxResults(environmentProperties.getMaxResults());
GetParametersByPathRequest request = GetParametersByPathRequest.builder().path(path)
.recursive(environmentProperties.isRecursive())
.withDecryption(environmentProperties.isDecryptValues())
.maxResults(environmentProperties.getMaxResults()).build();
Set<Parameter> parameters = getParameters(ps, path, withSlashesForPropertyName);
GetParametersByPathResult response = new GetParametersByPathResult().withParameters(parameters);
GetParametersByPathResponse response = GetParametersByPathResponse.builder().parameters(parameters).build();
if (paginatedResponse && environmentProperties.getMaxResults() < parameters.size()) {
List<Set<Parameter>> chunks = splitParametersIntoChunks(parameters);
@@ -745,24 +744,24 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
if (i == 0) {
nextToken = generateNextToken();
GetParametersByPathResult responseClone = response.clone().withParameters(chunk)
.withNextToken(nextToken);
GetParametersByPathResponse responseClone = response.toBuilder().parameters(chunk)
.nextToken(nextToken).build();
when(awsSsmClientMock.getParametersByPath(eq(request))).thenReturn(responseClone);
}
else if (i == chunks.size() - 1) {
GetParametersByPathRequest requestClone = request.clone().withNextToken(nextToken);
GetParametersByPathResult responseClone = response.clone().withParameters(chunk);
GetParametersByPathRequest requestClone = request.toBuilder().nextToken(nextToken).build();
GetParametersByPathResponse responseClone = response.toBuilder().parameters(chunk).build();
when(awsSsmClientMock.getParametersByPath(eq(requestClone))).thenReturn(responseClone);
}
else {
String newNextToken = generateNextToken();
GetParametersByPathRequest requestClone = request.clone().withNextToken(nextToken);
GetParametersByPathRequest requestClone = request.toBuilder().nextToken(nextToken).build();
GetParametersByPathResult responseClone = response.clone().withParameters(chunk)
.withNextToken(newNextToken);
GetParametersByPathResponse responseClone = response.toBuilder().parameters(chunk)
.nextToken(newNextToken).build();
when(awsSsmClientMock.getParametersByPath(eq(requestClone))).thenReturn(responseClone);
@@ -778,10 +777,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests {
private Set<Parameter> getParameters(PropertySource propertySource, String path,
boolean withSlashesForPropertyName) {
Function<Map.Entry<?, ?>, Parameter> mapper = p -> new Parameter()
.withName(path + (withSlashesForPropertyName
Function<Map.Entry<?, ?>, Parameter> mapper = p -> Parameter
.builder().name(path + (withSlashesForPropertyName
? ((String) p.getKey()).replace(".", DEFAULT_PATH_SEPARATOR) : p.getKey()))
.withType(ParameterType.String).withValue((String) p.getValue()).withVersion(1L);
.type(ParameterType.STRING).value((String) p.getValue()).version(1L).build();
return propertySource.getSource().entrySet().stream().map(mapper).collect(Collectors.toSet());
}

View File

@@ -17,17 +17,19 @@
package org.springframework.cloud.config.server.environment;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectId;
import com.amazonaws.util.StringInputStream;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import software.amazon.awssdk.core.ResponseInputStream;
import software.amazon.awssdk.http.AbortableInputStream;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
import software.amazon.awssdk.utils.StringInputStream;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
@@ -45,7 +47,7 @@ public class AwsS3EnvironmentRepositoryTests {
final ConfigServerProperties server = new ConfigServerProperties();
final AmazonS3 s3Client = mock(AmazonS3.class, "config");
final S3Client s3Client = mock(S3Client.class, "config");
final EnvironmentRepository envRepo = new AwsS3EnvironmentRepository(s3Client, "bucket1", server);
@@ -200,19 +202,21 @@ public class AwsS3EnvironmentRepositoryTests {
}
private void setupS3(String fileName, String version, String propertyContent) throws UnsupportedEncodingException {
final S3ObjectId s3ObjectId = new S3ObjectId("bucket1", fileName);
final GetObjectRequest request = new GetObjectRequest(s3ObjectId);
final GetObjectRequest request = GetObjectRequest.builder().bucket("bucket1").key(fileName).build();
final S3Object s3Object = new S3Object();
s3Object.setObjectContent(new StringInputStream(propertyContent));
GetObjectResponse.Builder s3Object = GetObjectResponse.builder();
if (version != null) {
final ObjectMetadata metadata = new ObjectMetadata();
metadata.setHeader("x-amz-version-id", version);
s3Object.setObjectMetadata(metadata);
final Map<String, String> metadata = new HashMap<>();
metadata.put("x-amz-version-id", version);
s3Object.metadata(metadata);
s3Object.versionId(version);
}
when(s3Client.getObject(argThat(new GetObjectRequestMatcher(request)))).thenReturn(s3Object);
ResponseInputStream<GetObjectResponse> response = new ResponseInputStream<GetObjectResponse>(s3Object.build(),
AbortableInputStream.create(new StringInputStream(propertyContent)));
when(s3Client.getObject(argThat(new GetObjectRequestMatcher(request)))).thenReturn(response);
}
private void assertExpectedEnvironment(Environment env, String applicationName, String label, String version,
@@ -240,9 +244,8 @@ public class AwsS3EnvironmentRepositoryTests {
if (actual == null) {
return false;
}
return Objects.equals(actual.getBucketName(), expected.getBucketName())
&& Objects.equals(actual.getKey(), expected.getKey())
&& Objects.equals(actual.getVersionId(), expected.getVersionId());
return Objects.equals(actual.bucket(), expected.bucket()) && Objects.equals(actual.key(), expected.key())
&& Objects.equals(actual.versionId(), expected.versionId());
}
}

View File

@@ -20,9 +20,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest;
import com.amazonaws.services.secretsmanager.model.GetSecretValueResult;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@@ -30,6 +27,9 @@ import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
@@ -49,7 +49,7 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
private static final Log log = LogFactory.getLog(AwsSecretsManagerEnvironmentRepository.class);
private final AWSSecretsManager awsSmClientMock = mock(AWSSecretsManager.class, "aws-sm-client-mock");
private final SecretsManagerClient awsSmClientMock = mock(SecretsManagerClient.class, "aws-sm-client-mock");
private final ConfigServerProperties configServerProperties = new ConfigServerProperties();
@@ -739,10 +739,10 @@ public class AwsSecretsManagerEnvironmentRepositoryTests {
private void setupAwsSmClientMocks(Environment environment) {
for (PropertySource ps : environment.getPropertySources()) {
String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin());
GetSecretValueRequest request = new GetSecretValueRequest().withSecretId(path);
GetSecretValueRequest request = GetSecretValueRequest.builder().secretId(path).build();
String secrets = getSecrets(ps);
GetSecretValueResult response = new GetSecretValueResult().withSecretString(secrets);
GetSecretValueResponse response = GetSecretValueResponse.builder().secretString(secrets).build();
when(awsSmClientMock.getSecretValue(eq(request))).thenReturn(response);
}

View File

@@ -138,7 +138,7 @@ class SpringVaultClientConfigurationTests {
@Test
public void awsIamAuthentication() {
System.setProperty("aws.accessKeyId", "access-key-id");
System.setProperty("aws.secretKey", "secret-key");
System.setProperty("aws.secretAccessKey", "secret-key");
properties.setAuthentication(AWS_IAM);
properties.getAwsIam().setRole("server");