Skip to content

Commit 5f25d5b

Browse files
authored
Merge pull request #164 from coveooss/feature/aws-sdk-v2-migration
2 parents b478b52 + 728f288 commit 5f25d5b

15 files changed

+315
-253
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ target
33
*.classpath
44
*.project
55
*.xml.versionsBackup
6+
.idea

pom.xml

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55

66
<groupId>com.coveo</groupId>
77
<artifactId>spring-boot-parameter-store-integration</artifactId>
8-
<version>1.5.0</version>
8+
<version>2.0.0</version>
99

1010
<name>Spring Boot Parameter Store Integration</name>
1111
<description>An integration of Amazon Web Services' Systems Manager Parameter Store for Spring Boot's properties injection.</description>
1212
<url>https://github.com/coveo/spring-boot-parameter-store-integration</url>
1313

1414
<properties>
15+
<maven.compiler.release>17</maven.compiler.release>
1516
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<jackson.version>2.17.1</jackson.version>
18+
<spring-boot.version>3.3.1</spring-boot.version>
1619
</properties>
1720

1821
<licenses>
@@ -26,47 +29,74 @@
2629
<developer>
2730
<name>Frederic Boutin</name>
2831
<organization>Coveo</organization>
29-
<organizationUrl>https://github.com/coveo</organizationUrl>
32+
<organizationUrl>https://github.com/coveooss</organizationUrl>
33+
</developer>
34+
<developer>
35+
<name>Jacques-Etienne Beaudet</name>
36+
<organization>Coveo</organization>
37+
<organizationUrl>https://github.com/coveooss</organizationUrl>
3038
</developer>
3139
</developers>
3240

3341
<scm>
34-
<connection>scm:git:git@github.com:coveo/spring-boot-parameter-store-integration.git</connection>
35-
<developerConnection>scm:git:git@github.com:coveo/spring-boot-parameter-store-integration.git</developerConnection>
36-
<url>http://github.com/coveo/spring-boot-parameter-store-integration</url>
42+
<connection>scm:git:git@github.com:coveooss/spring-boot-parameter-store-integration.git</connection>
43+
<developerConnection>scm:git:git@github.com:coveooss/spring-boot-parameter-store-integration.git</developerConnection>
44+
<url>http://github.com/coveooss/spring-boot-parameter-store-integration</url>
3745
</scm>
3846

3947
<dependencyManagement>
4048
<dependencies>
4149
<dependency>
4250
<groupId>com.fasterxml.jackson</groupId>
4351
<artifactId>jackson-bom</artifactId>
44-
<version>2.10.3</version>
52+
<version>${jackson.version}</version>
4553
<scope>import</scope>
4654
<type>pom</type>
4755
</dependency>
56+
<dependency>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-dependencies</artifactId>
59+
<version>${spring-boot.version}</version>
60+
<scope>import</scope>
61+
<type>pom</type>
62+
</dependency>
63+
<dependency>
64+
<groupId>software.amazon.awssdk</groupId>
65+
<artifactId>bom</artifactId>
66+
<version>2.26.15</version>
67+
<type>pom</type>
68+
<scope>import</scope>
69+
</dependency>
4870
</dependencies>
4971
</dependencyManagement>
5072

5173
<dependencies>
5274
<dependency>
5375
<groupId>org.springframework.boot</groupId>
5476
<artifactId>spring-boot</artifactId>
55-
<version>1.5.22.RELEASE</version>
5677
</dependency>
5778
<dependency>
58-
<groupId>com.amazonaws</groupId>
59-
<artifactId>aws-java-sdk-ssm</artifactId>
60-
<version>1.11.833</version>
79+
<groupId>software.amazon.awssdk</groupId>
80+
<artifactId>ssm</artifactId>
6181
</dependency>
62-
6382
<!-- Test libraries -->
6483
<dependency>
6584
<groupId>org.springframework.boot</groupId>
6685
<artifactId>spring-boot-starter-test</artifactId>
67-
<version>1.5.21.RELEASE</version>
6886
<scope>test</scope>
6987
</dependency>
88+
<dependency>
89+
<groupId>com.google.truth</groupId>
90+
<artifactId>truth</artifactId>
91+
<version>1.4.3</version>
92+
<scope>test</scope>
93+
<exclusions>
94+
<exclusion>
95+
<artifactId>junit</artifactId>
96+
<groupId>junit</groupId>
97+
</exclusion>
98+
</exclusions>
99+
</dependency>
70100
</dependencies>
71101

72102
<build>
@@ -106,10 +136,6 @@
106136
<groupId>org.apache.maven.plugins</groupId>
107137
<artifactId>maven-compiler-plugin</artifactId>
108138
<version>3.7.0</version>
109-
<configuration>
110-
<source>1.8</source>
111-
<target>1.8</target>
112-
</configuration>
113139
</plugin>
114140
</plugins>
115141

src/main/java/com/coveo/configuration/parameterstore/ParameterStorePropertySourceEnvironmentPostProcessor.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
import org.springframework.boot.env.EnvironmentPostProcessor;
55
import org.springframework.core.Ordered;
66
import org.springframework.core.env.ConfigurableEnvironment;
7+
import org.springframework.core.env.Profiles;
78
import org.springframework.util.ObjectUtils;
89

9-
import com.amazonaws.ClientConfigurationFactory;
10-
import com.amazonaws.retry.PredefinedRetryPolicies;
11-
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
1210
import com.coveo.configuration.parameterstore.strategy.ParameterStorePropertySourceConfigurationStrategy;
1311
import com.coveo.configuration.parameterstore.strategy.ParameterStorePropertySourceConfigurationStrategyFactory;
1412
import com.coveo.configuration.parameterstore.strategy.StrategyType;
13+
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
14+
import software.amazon.awssdk.core.internal.retry.SdkDefaultRetrySetting;
15+
import software.amazon.awssdk.core.retry.RetryMode;
16+
import software.amazon.awssdk.services.ssm.SsmClient;
17+
import software.amazon.awssdk.services.ssm.SsmClientBuilder;
1518

1619
public class ParameterStorePropertySourceEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered
1720
{
@@ -26,13 +29,16 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp
2629
}
2730
}
2831

29-
private AWSSimpleSystemsManagementClientBuilder preconfigureSSMClientBuilder(ConfigurableEnvironment environment)
32+
private SsmClientBuilder preconfigureSSMClientBuilder(ConfigurableEnvironment environment)
3033
{
31-
return AWSSimpleSystemsManagementClientBuilder.standard()
32-
.withClientConfiguration(new ClientConfigurationFactory().getConfig()
33-
.withRetryPolicy(PredefinedRetryPolicies.getDefaultRetryPolicyWithCustomMaxRetries(environment.getProperty(ParameterStorePropertySourceConfigurationProperties.MAX_ERROR_RETRY,
34-
Integer.class,
35-
PredefinedRetryPolicies.DEFAULT_MAX_ERROR_RETRY))));
34+
Integer maxRetries = environment.getProperty(ParameterStorePropertySourceConfigurationProperties.MAX_ERROR_RETRY,
35+
Integer.class,
36+
SdkDefaultRetrySetting.maxAttempts(RetryMode.STANDARD));
37+
ClientOverrideConfiguration clientOverrideConfiguration = ClientOverrideConfiguration.builder()
38+
.retryStrategy(configurator -> configurator.maxAttempts(maxRetries
39+
+ 1))
40+
.build();
41+
return SsmClient.builder().overrideConfiguration(clientOverrideConfiguration);
3642
}
3743

3844
private ParameterStorePropertySourceConfigurationStrategy getParameterStorePropertySourceConfigurationStrategy(ConfigurableEnvironment environment)
@@ -48,9 +54,9 @@ private boolean isParameterStorePropertySourceEnabled(ConfigurableEnvironment en
4854
return environment.getProperty(ParameterStorePropertySourceConfigurationProperties.ENABLED,
4955
Boolean.class,
5056
Boolean.FALSE)
51-
|| environment.acceptsProfiles(ParameterStorePropertySourceConfigurationProperties.ENABLED_PROFILE)
57+
|| environment.acceptsProfiles(Profiles.of(ParameterStorePropertySourceConfigurationProperties.ENABLED_PROFILE))
5258
|| (!ObjectUtils.isEmpty(userDefinedEnabledProfiles)
53-
&& environment.acceptsProfiles(userDefinedEnabledProfiles));
59+
&& environment.acceptsProfiles(Profiles.of(userDefinedEnabledProfiles)));
5460
}
5561

5662
private boolean isMultiRegionEnabled(ConfigurableEnvironment environment)

src/main/java/com/coveo/configuration/parameterstore/ParameterStoreSource.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
package com.coveo.configuration.parameterstore;
22

3-
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
4-
import com.amazonaws.services.simplesystemsmanagement.model.GetParameterRequest;
5-
import com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult;
6-
import com.amazonaws.services.simplesystemsmanagement.model.ParameterNotFoundException;
73
import com.coveo.configuration.parameterstore.exception.ParameterStoreError;
84
import com.coveo.configuration.parameterstore.exception.ParameterStoreParameterNotFoundError;
5+
import software.amazon.awssdk.services.ssm.SsmClient;
6+
import software.amazon.awssdk.services.ssm.model.GetParameterRequest;
7+
import software.amazon.awssdk.services.ssm.model.GetParameterResponse;
8+
import software.amazon.awssdk.services.ssm.model.ParameterNotFoundException;
9+
import software.amazon.awssdk.services.ssm.model.ParameterVersionNotFoundException;
10+
11+
import java.util.Objects;
912

1013
public class ParameterStoreSource
1114
{
12-
private AWSSimpleSystemsManagement ssmClient;
13-
private boolean haltBoot;
15+
private final SsmClient ssmClient;
16+
private final boolean haltBoot;
1417

15-
public ParameterStoreSource(AWSSimpleSystemsManagement ssmClient, boolean haltBoot)
18+
public ParameterStoreSource(SsmClient ssmClient, boolean haltBoot)
1619
{
17-
this.ssmClient = ssmClient;
20+
this.ssmClient = Objects.requireNonNull(ssmClient);
1821
this.haltBoot = haltBoot;
1922
}
2023

2124
public Object getProperty(String propertyName)
2225
{
2326
try {
24-
GetParameterResult getParameterResult = ssmClient.getParameter(new GetParameterRequest().withName(propertyName)
25-
.withWithDecryption(true));
27+
GetParameterResponse getParameterResult = ssmClient.getParameter(GetParameterRequest.builder()
28+
.name(propertyName)
29+
.withDecryption(true)
30+
.build());
2631
validate(propertyName, getParameterResult);
27-
return getParameterResult.getParameter().getValue();
28-
} catch (ParameterNotFoundException e) {
32+
return getParameterResult.parameter().value();
33+
} catch (ParameterNotFoundException | ParameterVersionNotFoundException e) {
2934
if (haltBoot) {
3035
throw new ParameterStoreParameterNotFoundError(propertyName, e);
3136
}
@@ -35,24 +40,24 @@ public Object getProperty(String propertyName)
3540
return null;
3641
}
3742

38-
private void validate(String propertyName, GetParameterResult getParameterResult)
43+
private void validate(String propertyName, GetParameterResponse getParameterResponse)
3944
{
40-
String requestId = getParameterResult.getSdkResponseMetadata().getRequestId();
41-
int statusCode = getParameterResult.getSdkHttpMetadata().getHttpStatusCode();
45+
String requestId = getParameterResponse.responseMetadata().requestId();
46+
int statusCode = getParameterResponse.sdkHttpResponse().statusCode();
4247
if (statusCode != 200) {
4348
throw new ParameterStoreError(propertyName,
4449
String.format("Invalid response code '%s' received from AWS. AWS Request ID : '%s'.",
4550
statusCode,
4651
requestId));
4752
}
4853

49-
if (getParameterResult.getParameter() == null) {
54+
if (getParameterResponse.parameter() == null) {
5055
throw new ParameterStoreError(propertyName,
5156
String.format("A null Parameter was received from AWS. AWS Request ID : '%s'.",
5257
requestId));
5358
}
5459

55-
if (getParameterResult.getParameter().getValue() == null) {
60+
if (getParameterResponse.parameter().value() == null) {
5661
throw new ParameterStoreError(propertyName,
5762
String.format("A null Parameter value was received from AWS. AWS Request ID : '%s'.",
5863
requestId));

src/main/java/com/coveo/configuration/parameterstore/strategy/DefaultParameterStorePropertySourceConfigurationStrategy.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,32 @@
22

33
import org.springframework.core.env.ConfigurableEnvironment;
44

5-
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
6-
import com.amazonaws.regions.AwsRegionProviderChain;
7-
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
8-
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder;
95
import com.coveo.configuration.parameterstore.ParameterStorePropertySource;
106
import com.coveo.configuration.parameterstore.ParameterStorePropertySourceConfigurationProperties;
117
import com.coveo.configuration.parameterstore.ParameterStoreSource;
8+
import software.amazon.awssdk.regions.Region;
9+
import software.amazon.awssdk.regions.providers.AwsRegionProviderChain;
10+
import software.amazon.awssdk.services.ssm.SsmClient;
11+
import software.amazon.awssdk.services.ssm.SsmClientBuilder;
12+
13+
import java.net.URI;
14+
import java.util.Objects;
1215

1316
public class DefaultParameterStorePropertySourceConfigurationStrategy
1417
implements ParameterStorePropertySourceConfigurationStrategy
1518
{
1619
private static final String PARAMETER_STORE_PROPERTY_SOURCE_NAME = "AWSParameterStorePropertySource";
1720

18-
private AwsRegionProviderChain awsRegionProviderChain;
21+
private final AwsRegionProviderChain awsRegionProviderChain;
1922

2023
public DefaultParameterStorePropertySourceConfigurationStrategy(AwsRegionProviderChain awsRegionProviderChain)
2124
{
22-
this.awsRegionProviderChain = awsRegionProviderChain;
25+
this.awsRegionProviderChain = Objects.requireNonNull(awsRegionProviderChain);
2326
}
2427

2528
@Override
2629
public void configureParameterStorePropertySources(ConfigurableEnvironment environment,
27-
AWSSimpleSystemsManagementClientBuilder ssmClientBuilder)
30+
SsmClientBuilder ssmClientBuilder)
2831
{
2932
boolean haltBoot = environment.getProperty(ParameterStorePropertySourceConfigurationProperties.HALT_BOOT,
3033
Boolean.class,
@@ -34,19 +37,17 @@ public void configureParameterStorePropertySources(ConfigurableEnvironment envir
3437
haltBoot));
3538
}
3639

37-
private ParameterStorePropertySource buildParameterStorePropertySource(AWSSimpleSystemsManagement ssmClient,
38-
boolean haltBoot)
40+
private ParameterStorePropertySource buildParameterStorePropertySource(SsmClient ssmClient, boolean haltBoot)
3941
{
4042
return new ParameterStorePropertySource(PARAMETER_STORE_PROPERTY_SOURCE_NAME,
4143
new ParameterStoreSource(ssmClient, haltBoot));
4244
}
4345

44-
private AWSSimpleSystemsManagement buildSSMClient(ConfigurableEnvironment environment,
45-
AWSSimpleSystemsManagementClientBuilder ssmClientBuilder)
46+
private SsmClient buildSSMClient(ConfigurableEnvironment environment, SsmClientBuilder ssmClientBuilder)
4647
{
4748
if (hasCustomEndpoint(environment)) {
48-
return ssmClientBuilder.withEndpointConfiguration(new EndpointConfiguration(getCustomEndpoint(environment),
49-
getSigningRegion(environment)))
49+
return ssmClientBuilder.endpointOverride(URI.create(getCustomEndpoint(environment)))
50+
.region(Region.of(getSigningRegion(environment)))
5051
.build();
5152
}
5253
return ssmClientBuilder.build();
@@ -65,6 +66,6 @@ private String getCustomEndpoint(ConfigurableEnvironment environment)
6566
private String getSigningRegion(ConfigurableEnvironment environment)
6667
{
6768
return environment.getProperty(ParameterStorePropertySourceConfigurationProperties.SSM_CLIENT_SIGNING_REGION,
68-
awsRegionProviderChain.getRegion());
69+
awsRegionProviderChain.getRegion().toString());
6970
}
7071
}

0 commit comments

Comments
 (0)