Align AWS Parameter Store Factory bean name with profile name (#2336)
Co-authored-by: Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com>
This commit is contained in:
@@ -31,6 +31,7 @@ import org.springframework.boot.context.properties.bind.Binder;
|
||||
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
|
||||
@@ -62,7 +63,8 @@ public final class CompositeUtils {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -237,7 +237,11 @@ public class EnvironmentRepositoryConfiguration {
|
||||
@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);
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
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;
|
||||
@@ -55,6 +56,19 @@ public class EnvironmentRepositoryConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@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()
|
||||
|
||||
Reference in New Issue
Block a user