Skip to content

Commit

Permalink
Fix the order of importing properties in Secrets Manager integration (#…
Browse files Browse the repository at this point in the history
…882)

Co-authored-by: Tomek Bielecki <Tomek.Bielecki@aus.com>
  • Loading branch information
tomek82 and tomek82 authored Dec 1, 2023
1 parent fc0511b commit bb94631
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
import java.util.List;
import org.apache.commons.logging.Log;
import org.springframework.boot.BootstrapContext;
import org.springframework.boot.context.config.ConfigDataLocation;
import org.springframework.boot.context.config.ConfigDataLocationNotFoundException;
import org.springframework.boot.context.config.ConfigDataLocationResolverContext;
import org.springframework.boot.context.config.Profiles;
import org.springframework.boot.context.config.*;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.logging.DeferredLogFactory;
Expand Down Expand Up @@ -62,9 +59,9 @@ protected String getPrefix() {
}

@Override
public List<SecretsManagerConfigDataResource> resolveProfileSpecific(
ConfigDataLocationResolverContext resolverContext, ConfigDataLocation location, Profiles profiles)
throws ConfigDataLocationNotFoundException {
public List<SecretsManagerConfigDataResource> resolve(ConfigDataLocationResolverContext resolverContext,
ConfigDataLocation location)
throws ConfigDataLocationNotFoundException, ConfigDataResourceNotFoundException {
registerBean(resolverContext, AwsProperties.class, loadAwsProperties(resolverContext.getBinder()));
registerBean(resolverContext, SecretsManagerProperties.class, loadProperties(resolverContext.getBinder()));
registerBean(resolverContext, CredentialsProperties.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.PropertySource;
import org.springframework.test.context.TestPropertySource;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
Expand Down Expand Up @@ -169,6 +171,17 @@ void resolvesPropertyFromSecretsManager_PlainTextSecret_WithoutSlashes() {
}
}

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

try (ConfigurableApplicationContext context = runApplication(application,
"classpath:config.properties")) {
assertThat(context.getEnvironment().getProperty("another-parameter")).isEqualTo("from properties file");
}
}

@Test
void clientIsConfiguredWithConfigurerProvidedToBootstrapRegistry() {
SpringApplication application = new SpringApplication(App.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.config.import=aws-secretsmanager:/config/spring,classpath:config_second.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
another-parameter=from properties file

0 comments on commit bb94631

Please sign in to comment.