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

Align AWS Parameter Store Factory bean name with profile name #2336

Merged
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 @@ -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