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

Upgrade AWS dependencies #940

Merged
merged 2 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.Duration;
import java.util.Objects;
import org.springframework.test.util.ReflectionTestUtils;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.awscore.client.config.AwsClientOption;
import software.amazon.awssdk.awscore.defaultsmode.DefaultsMode;
import software.amazon.awssdk.core.SdkClient;
Expand Down Expand Up @@ -85,4 +86,8 @@ public SdkAsyncHttpClient getAsyncHttpClient() {
return clientConfigurationAttributes.get(SdkClientOption.ASYNC_HTTP_CLIENT);
}

public AwsCredentialsProvider getAwsCredentialsProvider() {
return clientConfigurationAttributes.get(AwsClientOption.CREDENTIALS_PROVIDER);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SSM;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
Expand Down Expand Up @@ -47,6 +46,7 @@
import org.testcontainers.utility.DockerImageName;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
Expand Down Expand Up @@ -163,20 +163,18 @@ void ssmClientCanBeOverwrittenInBootstrapConfig() {

@Test
void credentialsProviderCanBeOverwrittenInBootstrapConfig() {
AwsCredentialsProvider mockCredentialsProvider = mock(AwsCredentialsProvider.class);
when(mockCredentialsProvider.resolveCredentials())
.thenReturn(AwsBasicCredentials.create("mock-key", "mock-secret"));
AwsCredentialsProvider bootstrapCredentialsProvider = StaticCredentialsProvider
.create(AwsBasicCredentials.create("mock-key", "mock-secret"));
SpringApplication application = new SpringApplication(App.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.addBootstrapRegistryInitializer(registry -> {
registry.register(AwsCredentialsProvider.class, ctx -> mockCredentialsProvider);
registry.register(AwsCredentialsProvider.class, ctx -> bootstrapCredentialsProvider);
});

try (ConfigurableApplicationContext context = runApplication(application,
"aws-parameterstore:/config/spring")) {
// perhaps there is a better way to verify that correct credentials provider
// is used by SSM client without using reflection?
verify(mockCredentialsProvider).resolveCredentials();
ConfiguredAwsClient ssmClient = new ConfiguredAwsClient(context.getBean(SsmClient.class));
assertThat(ssmClient.getAwsCredentialsProvider()).isEqualTo(bootstrapCredentialsProvider);
}
}

Expand Down Expand Up @@ -248,17 +246,17 @@ void arrayParameterNames() {
putParameter(localstack, "/config/myservice/key_1_.nested_1_.nestedValue", "key_nestedValue4", REGION);

try (ConfigurableApplicationContext context = runApplication(application,
"aws-parameterstore:/config/myservice/")) {
"aws-parameterstore:/config/myservice/")) {
assertThat(context.getEnvironment().getProperty("key[0].value")).isEqualTo("value1");
assertThat(context.getEnvironment().getProperty("key[0].nested[0].nestedValue"))
.isEqualTo("key_nestedValue1");
.isEqualTo("key_nestedValue1");
assertThat(context.getEnvironment().getProperty("key[0].nested[1].nestedValue"))
.isEqualTo("key_nestedValue2");
.isEqualTo("key_nestedValue2");
assertThat(context.getEnvironment().getProperty("key[1].value")).isEqualTo("value2");
assertThat(context.getEnvironment().getProperty("key[1].nested[0].nestedValue"))
.isEqualTo("key_nestedValue3");
.isEqualTo("key_nestedValue3");
assertThat(context.getEnvironment().getProperty("key[1].nested[1].nestedValue"))
.isEqualTo("key_nestedValue4");
.isEqualTo("key_nestedValue4");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SECRETSMANAGER;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
Expand Down Expand Up @@ -225,20 +224,19 @@ void secretsManagerClientCanBeOverwrittenInBootstrapConfig() {

@Test
void credentialsProviderCanBeOverwrittenInBootstrapConfig() {
AwsCredentialsProvider mockCredentialsProvider = mock(AwsCredentialsProvider.class);
when(mockCredentialsProvider.resolveCredentials())
.thenReturn(AwsBasicCredentials.create("mock-key", "mock-secret"));
AwsCredentialsProvider bootstrapCredentialsProvider = StaticCredentialsProvider
.create(AwsBasicCredentials.create("mock-key", "mock-secret"));
SpringApplication application = new SpringApplication(App.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.addBootstrapRegistryInitializer(registry -> {
registry.register(AwsCredentialsProvider.class, ctx -> mockCredentialsProvider);
registry.register(AwsCredentialsProvider.class, ctx -> bootstrapCredentialsProvider);
});

try (ConfigurableApplicationContext context = runApplication(application,
"aws-secretsmanager:/config/spring")) {
// perhaps there is a better way to verify that correct credentials provider
// is used by SSM client without using reflection?
verify(mockCredentialsProvider).resolveCredentials();
ConfiguredAwsClient secretsManagerClient = new ConfiguredAwsClient(
context.getBean(SecretsManagerClient.class));
assertThat(secretsManagerClient.getAwsCredentialsProvider()).isEqualTo(bootstrapCredentialsProvider);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@ public class ConfiguredTransferManager {
private final S3AsyncClient client;

ConfiguredTransferManager(S3TransferManager s3TransferManager) {
this.transferConfiguration = (TransferManagerConfiguration) ReflectionTestUtils.getField(s3TransferManager,
"transferConfiguration");
this.client = (S3AsyncClient) ReflectionTestUtils.getField(s3TransferManager, "s3AsyncClient");
// todo: this is getting too hacky
if (s3TransferManager.getClass().getName().equals("software.amazon.awssdk.transfer.s3.internal.CrtS3TransferManager")) {
S3TransferManager delegate = (S3TransferManager) ReflectionTestUtils.getField(s3TransferManager, "delegate");
this.transferConfiguration = (TransferManagerConfiguration) ReflectionTestUtils.getField(delegate,
"transferConfiguration");
this.client = (S3AsyncClient) ReflectionTestUtils.getField(s3TransferManager, "s3AsyncClient");
} else {
this.transferConfiguration = (TransferManagerConfiguration) ReflectionTestUtils.getField(s3TransferManager,
"transferConfiguration");
this.client = (S3AsyncClient) ReflectionTestUtils.getField(s3TransferManager, "s3AsyncClient");
}

}

boolean getUploadDirectoryFileVisitOption() {
Expand Down
6 changes: 3 additions & 3 deletions spring-cloud-aws-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<properties>
<javaparser.version>3.24.10</javaparser.version>
<spotless.version>2.31.0</spotless.version>
<awssdk-v2.version>2.20.63</awssdk-v2.version>
<amazon.dax.version>2.0.3</amazon.dax.version>
<awssdk-v2.version>2.21.12</awssdk-v2.version>
<amazon.dax.version>2.0.4</amazon.dax.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<spring-cloud-commons.version>4.0.4</spring-cloud-commons.version>
<jakarta.mail.version>2.1.0</jakarta.mail.version>
<eclipse.jakarta.mail.version>1.0.0</eclipse.jakarta.mail.version>
<aws-crt.version>0.21.14</aws-crt.version>
<aws-crt.version>0.28.3</aws-crt.version>
<mockito.version>5.3.1</mockito.version>
<bytebuddy.version>1.14.9</bytebuddy.version>
</properties>
Expand Down
Loading