Skip to content
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

Migrate to AWS SDK v2 #2099

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 17 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
<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>
<aws-java-sdk-v1.version>1.12.220</aws-java-sdk-v1.version>
hpoettker marked this conversation as resolved.
Show resolved Hide resolved
<wiremock.version>2.31.0</wiremock.version>
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
<maven-checkstyle-plugin.failsOnViolation>true
Expand Down Expand Up @@ -71,23 +72,23 @@
<version>${spring-cloud-commons.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>protocol-core</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>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>ssm</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -116,8 +117,13 @@
<version>${testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>${aws-java-sdk-v1.version}</version>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>${wiremock.version}</version>
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-config-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,7 @@
import org.json.JSONException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.BindMode;
import org.testcontainers.junit.jupiter.Container;
Expand All @@ -42,6 +43,7 @@
* vaultordering/client-dev.yml
*/
@Testcontainers
@Tag("DockerRequired")
public class ConfigDataOrderingVaultIntegrationTests {

private static final int configServerPort = TestSocketUtils.findAvailableTcpPort();
Expand Down
26 changes: 18 additions & 8 deletions spring-cloud-config-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,23 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>protocol-core</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>secretsmanager</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ssm</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ssm</artifactId>
<optional>true</optional>
</dependency>
<dependency>
Expand Down Expand Up @@ -168,6 +168,16 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>localstack</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,14 +19,14 @@
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;
Expand Down Expand Up @@ -210,7 +210,7 @@ public ConfigurableHttpConnectionFactory httpClientConnectionFactory() {
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(AmazonS3.class)
@ConditionalOnClass(S3Client.class)
static class AwsS3FactoryConfig {

@Bean
Expand All @@ -221,7 +221,7 @@ public AwsS3EnvironmentRepositoryFactory awsS3EnvironmentRepositoryFactory(Confi
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(AWSSecretsManager.class)
@ConditionalOnClass(SecretsManagerClient.class)
static class AwsSecretsManagerFactoryConfig {

@Bean
Expand All @@ -233,7 +233,7 @@ public AwsSecretsManagerEnvironmentRepositoryFactory awsSecretsManagerEnvironmen
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(AWSSimpleSystemsManagement.class)
@ConditionalOnClass(SsmClient.class)
static class AwsParameterStoreFactoryConfig {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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;

Expand All @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,10 +26,10 @@
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;
Expand All @@ -43,14 +43,13 @@
*/
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;
Expand Down Expand Up @@ -137,20 +136,20 @@ private List<PropertySource> getPropertySources(Set<String> parameterPaths) {
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);
}
}

Expand All @@ -159,9 +158,9 @@ private Map<String, String> getPropertiesByParameterPath(String path) {

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());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -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;

Expand All @@ -37,11 +37,11 @@ public AwsParameterStoreEnvironmentRepositoryFactory(ConfigServerProperties conf

@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);
}
Expand Down