Skip to content

Commit

Permalink
fix parameter store and secrets manager
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak committed Sep 23, 2024
1 parent 0742cf8 commit e7749c8
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,31 @@ protected SsmClient createSimpleSystemManagementClient(BootstrapContext context)
if (configurer != null) {
AwsClientCustomizer.apply(configurer, builder);
}
}
catch (IllegalStateException e) {
log.debug("Bean of type AwsParameterStoreClientCustomizer is not registered: " + e.getMessage());
}

try {
AwsSyncClientCustomizer awsSyncClientCustomizer = context.get(AwsSyncClientCustomizer.class);
if (awsSyncClientCustomizer != null) {
awsSyncClientCustomizer.customize(builder);
}
}
catch (IllegalStateException e) {
log.debug("Bean of type AwsSyncClientCustomizer is not registered: " + e.getMessage());
}

try {
SsmClientCustomizer ssmClientCustomizer = context.get(SsmClientCustomizer.class);
if (ssmClientCustomizer != null) {
ssmClientCustomizer.customize(builder);
}
}
catch (IllegalStateException e) {
log.debug("Bean of type AwsClientConfigurerParameterStore is not registered: " + e.getMessage());
log.debug("Bean of type SsmClientCustomizer is not registered: " + e.getMessage());
}

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,32 @@ protected SecretsManagerClient createAwsSecretsManagerClient(BootstrapContext co
if (configurer != null) {
AwsClientCustomizer.apply(configurer, builder);
}
}
catch (IllegalStateException e) {
log.debug("Bean of type AwsParameterStoreClientCustomizer is not registered: " + e.getMessage());
}

try {
AwsSyncClientCustomizer awsSyncClientCustomizer = context.get(AwsSyncClientCustomizer.class);
if (awsSyncClientCustomizer != null) {
awsSyncClientCustomizer.customize(builder);
}
}
catch (IllegalStateException e) {
log.debug("Bean of type AwsSyncClientCustomizer is not registered: " + e.getMessage());
}

try {
SecretsManagerClientCustomizer secretsManagerClientCustomizer = context
.get(SecretsManagerClientCustomizer.class);
if (secretsManagerClientCustomizer != null) {
secretsManagerClientCustomizer.customize(builder);
}
}
catch (IllegalStateException e) {
log.debug("Bean of type AwsClientConfigurerSecretsManager is not registered: " + e.getMessage());
log.debug("Bean of type SecretsManagerClientCustomizer is not registered: " + e.getMessage());
}

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.mockito.Mockito.when;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

import io.awspring.cloud.autoconfigure.AwsSyncClientCustomizer;
import io.awspring.cloud.autoconfigure.ConfiguredAwsClient;
import java.io.IOException;
import java.time.Duration;
Expand Down Expand Up @@ -138,6 +139,20 @@ void clientIsConfiguredWithConfigurerProvidedToBootstrapRegistry() {
}
}

@Test
void clientIsConfiguredWithCustomizerProvidedToBootstrapRegistry() {
SpringApplication application = new SpringApplication(App.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.addBootstrapRegistryInitializer(new CustomizerConfiguration());

try (ConfigurableApplicationContext context = runApplication(application,
"aws-parameterstore:/config/spring/")) {
ConfiguredAwsClient ssmClient = new ConfiguredAwsClient(context.getBean(SsmClient.class));
assertThat(ssmClient.getApiCallTimeout()).isEqualTo(Duration.ofMillis(2001));
assertThat(ssmClient.getSyncHttpClient()).isNotNull();
}
}

@Test
void whenKeysAreNotSpecifiedFailsWithHumanReadableFailureMessage(CapturedOutput output) {
SpringApplication application = new SpringApplication(App.class);
Expand Down Expand Up @@ -451,4 +466,19 @@ public SdkHttpClient httpClient() {
}
}

static class CustomizerConfiguration implements BootstrapRegistryInitializer {

@Override
public void initialize(BootstrapRegistry registry) {
registry.register(SsmClientCustomizer.class, context -> (builder -> {
builder.overrideConfiguration(builder.overrideConfiguration().copy(c -> {
c.apiCallTimeout(Duration.ofMillis(2001));
}));
}));
registry.register(AwsSyncClientCustomizer.class, context -> (builder -> {
builder.httpClient(ApacheHttpClient.builder().connectionTimeout(Duration.ofMillis(1542)).build());
}));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.mockito.Mockito.when;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

import io.awspring.cloud.autoconfigure.AwsSyncClientCustomizer;
import io.awspring.cloud.autoconfigure.ConfiguredAwsClient;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -193,6 +194,20 @@ void clientIsConfiguredWithConfigurerProvidedToBootstrapRegistry() {
}
}

@Test
void clientIsConfiguredWithCustomizerProvidedToBootstrapRegistry() {
SpringApplication application = new SpringApplication(App.class);
application.setWebApplicationType(WebApplicationType.NONE);
application.addBootstrapRegistryInitializer(new CustomizerConfiguration());

try (ConfigurableApplicationContext context = runApplication(application,
"aws-secretsmanager:/config/spring;/config/second")) {
ConfiguredAwsClient client = new ConfiguredAwsClient(context.getBean(SecretsManagerClient.class));
assertThat(client.getApiCallTimeout()).isEqualTo(Duration.ofMillis(2001));
assertThat(client.getSyncHttpClient()).isNotNull();
}
}

@Test
void whenKeysAreNotSpecifiedFailsWithHumanReadableFailureMessage(CapturedOutput output) {
SpringApplication application = new SpringApplication(App.class);
Expand Down Expand Up @@ -501,4 +516,19 @@ public SdkHttpClient httpClient() {
}
}

static class CustomizerConfiguration implements BootstrapRegistryInitializer {

@Override
public void initialize(BootstrapRegistry registry) {
registry.register(SecretsManagerClientCustomizer.class, context -> (builder -> {
builder.overrideConfiguration(builder.overrideConfiguration().copy(c -> {
c.apiCallTimeout(Duration.ofMillis(2001));
}));
}));
registry.register(AwsSyncClientCustomizer.class, context -> (builder -> {
builder.httpClient(ApacheHttpClient.builder().connectionTimeout(Duration.ofMillis(1542)).build());
}));
}
}

}

0 comments on commit e7749c8

Please sign in to comment.