Skip to content

Commit

Permalink
Merge branch '4.0.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Oct 13, 2023
2 parents d16b208 + ccfec57 commit 5695920
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) -> {

Check failure on line 67 in spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfigurationTests.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

EnvironmentRepositoryConfigurationTests.awsParamStoreFactoryBeanExistsWithComposite

Unstarted application context org.springframework.boot.test.context.assertj.AssertableApplicationContext[startupFailure=org.springframework.beans.factory.UnsatisfiedDependencyException] failed to start
Raw output
java.lang.IllegalStateException: Unstarted application context org.springframework.boot.test.context.assertj.AssertableApplicationContext[startupFailure=org.springframework.beans.factory.UnsatisfiedDependencyException] failed to start
	at org.springframework.cloud.config.server.config.EnvironmentRepositoryConfigurationTests.lambda$awsParamStoreFactoryBeanExistsWithComposite$1(EnvironmentRepositoryConfigurationTests.java:68)
	at org.springframework.cloud.config.server.config.EnvironmentRepositoryConfigurationTests.awsParamStoreFactoryBeanExistsWithComposite(EnvironmentRepositoryConfigurationTests.java:67)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configServerHealthIndicator' defined in org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration$ConfigServerActuatorConfiguration: Unsatisfied dependency expressed through method 'configServerHealthIndicator' parameter 0: Error creating bean with name 'searchPathCompositeEnvironmentRepository' defined in org.springframework.cloud.config.server.config.CompositeRepositoryConfiguration: Unsatisfied dependency expressed through method 'searchPathCompositeEnvironmentRepository' parameter 0: Error creating bean with name 'awsparamstore-env-repo0': Failed to instantiate [org.springframework.cloud.config.server.environment.AwsParameterStoreEnvironmentRepository]: Factory method 'build' threw exception with message: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@7b443339: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@1daa412e: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or  system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@54af3dc1: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@10455701: Unable to retrieve region information from EC2 Metadata service. Please make sure the application is running on EC2.]
	at org.springframework.cloud.config.server.config.EnvironmentRepositoryConfigurationTests.awsParamStoreFactoryBeanExistsWithComposite(EnvironmentRepositoryConfigurationTests.java:67)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'searchPathCompositeEnvironmentRepository' defined in org.springframework.cloud.config.server.config.CompositeRepositoryConfiguration: Unsatisfied dependency expressed through method 'searchPathCompositeEnvironmentRepository' parameter 0: Error creating bean with name 'awsparamstore-env-repo0': Failed to instantiate [org.springframework.cloud.config.server.environment.AwsParameterStoreEnvironmentRepository]: Factory method 'build' threw exception with message: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@7b443339: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@1daa412e: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or  system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@54af3dc1: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@10455701: Unable to retrieve region information from EC2 Metadata service. Please make sure the application is running on EC2.]
	at org.springframework.cloud.config.server.config.EnvironmentRepositoryConfigurationTests.awsParamStoreFactoryBeanExistsWithComposite(EnvironmentRepositoryConfigurationTests.java:67)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'awsparamstore-env-repo0': Failed to instantiate [org.springframework.cloud.config.server.environment.AwsParameterStoreEnvironmentRepository]: Factory method 'build' threw exception with message: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@7b443339: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@1daa412e: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or  system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@54af3dc1: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@10455701: Unable to retrieve region information from EC2 Metadata service. Please make sure the application is running on EC2.]
	at org.springframework.cloud.config.server.config.EnvironmentRepositoryConfigurationTests.awsParamStoreFactoryBeanExistsWithComposite(EnvironmentRepositoryConfigurationTests.java:67)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.config.server.environment.AwsParameterStoreEnvironmentRepository]: Factory method 'build' threw exception with message: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@7b443339: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@1daa412e: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or  system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@54af3dc1: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@10455701: Unable to retrieve region information from EC2 Metadata service. Please make sure the application is running on EC2.]
	at org.springframework.cloud.config.server.config.EnvironmentRepositoryConfigurationTests.awsParamStoreFactoryBeanExistsWithComposite(EnvironmentRepositoryConfigurationTests.java:67)
Caused by: software.amazon.awssdk.core.exception.SdkClientException: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@7b443339: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@1daa412e: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or  system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@54af3dc1: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@10455701: Unable to retrieve region information from EC2 Metadata service. Please make sure the application is running on EC2.]
	at org.springframework.cloud.config.server.config.EnvironmentRepositoryConfigurationTests.awsParamStoreFactoryBeanExistsWithComposite(EnvironmentRepositoryConfigurationTests.java:67)
assertThat(context.getBean(AwsParameterStoreEnvironmentRepositoryFactory.class)).isNotNull();
});
}

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

0 comments on commit 5695920

Please sign in to comment.