Skip to content

Commit

Permalink
Align AWS Parameter Store Factory bean name with profile name (#2336)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Baxter <[email protected]>
  • Loading branch information
Ryan Baxter and ryanjbaxter authored Oct 13, 2023
1 parent 26cb818 commit ccfec57
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.cloud.config.server.environment.EnvironmentRepositoryFactory;
import org.springframework.core.env.Environment;
import org.springframework.core.type.MethodMetadata;
import org.springframework.util.StringUtils;

/**
* @author Dylan Roberts
Expand Down Expand Up @@ -62,7 +63,8 @@ public static List<String> getCompositeTypeList(Environment environment) {
public static String getFactoryName(String type, ConfigurableListableBeanFactory beanFactory) {
String[] factoryNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory,
EnvironmentRepositoryFactory.class, true, false);
return Arrays.stream(factoryNames).filter(n -> n.startsWith(type)).findFirst().orElse(null);
return Arrays.stream(factoryNames).filter(n -> StringUtils.startsWithIgnoreCase(n, type)).findFirst()
.orElse(null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ public AwsSecretsManagerEnvironmentRepositoryFactory awsSecretsManagerEnvironmen
@ConditionalOnClass(SsmClient.class)
static class AwsParameterStoreFactoryConfig {

@Bean
//set the bean name explicitly since we assume the bean name will start with the profile
//name in the case of a composite configuration. The profile name is awsparamstore
//but the method name starts with awsParameterStore and the logic in CompositeUtils.getFactoryName
//will not find a match
@Bean(name = "awsparamstoreenvironmentrepositoryfactory")
public AwsParameterStoreEnvironmentRepositoryFactory awsParameterStoreEnvironmentRepositoryFactory(
ConfigServerProperties server) {
return new AwsParameterStoreEnvironmentRepositoryFactory(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.config.server.environment.AwsParameterStoreEnvironmentRepositoryFactory;
import org.springframework.cloud.config.server.environment.ConfigTokenProvider;
import org.springframework.cloud.config.server.environment.EnvironmentConfigTokenProvider;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
Expand Down Expand Up @@ -55,6 +56,19 @@ public void configTokenProviderCanBeOverridden() {
});
}

@Test
public void awsParamStoreFactoryBeanExistsWithComposite() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EnvironmentRepositoryConfiguration.class, TestBeans.class))
.withPropertyValues("spring.profiles.active=composite",
"spring.cloud.config.server.composite[0].type=awsparamstore",
"spring.cloud.config.server.composite[1].type=git",
"spring.cloud.config.server.composite[1].uri=https://test.com/Some-Test-Repo.git")
.run((context) -> {
assertThat(context.getBean(AwsParameterStoreEnvironmentRepositoryFactory.class)).isNotNull();
});
}

@Test
public void customGitCredentialsProvider() {
new ApplicationContextRunner()
Expand Down

0 comments on commit ccfec57

Please sign in to comment.