diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index 9c33e3bc..cba39815 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -972,10 +972,10 @@ spring: endpoint: https://ssm.eu-west-2.amazonaws.com origin: aws:parameter: prefix: /config/service - profileSeparator: _ + profile-separator: _ recursive: true - decryptValues: true - maxResults: 5 + decrypt-values: true + max-results: 5 ---- The following table describes the AWS Parameter Store configuration properties. @@ -1004,7 +1004,7 @@ The following table describes the AWS Parameter Store configuration properties. |`/config` |Prefix indicating L1 level in the parameter hierarchy for every property loaded from the AWS Parameter Store. -|*profileSeparator* +|*profile-separator* |no |`-` |String that separates an appended profile from the context name. @@ -1014,12 +1014,12 @@ The following table describes the AWS Parameter Store configuration properties. |`true` |Flag to indicate the retrieval of all AWS parameters within a hierarchy. -|*decryptValues* +|*decrypt-values* |no |`true` |Flag to indicate the retrieval of all AWS parameters with their value decrypted. -|*maxResults* +|*max-results* |no |`10` |The maximum number of items to return for an AWS Parameter Store API call. @@ -1033,8 +1033,8 @@ Versioned parameters are already supported with the default behaviour of returni ==== - When no application is specified `application` is the default, and when no profile is specified `default` is used. - Valid values for `awsparamstore.prefix` must start with a forward slash followed by one or more valid path segments or be empty. -- Valid values for `awsparamstore.profileSeparator` can only contain dots, dashes and underscores. -- Valid values for `awsparamstore.maxResults` must be within the *[1, 10]* range. +- Valid values for `awsparamstore.profile-separator` can only contain dots, dashes and underscores. +- Valid values for `awsparamstore.max-results` must be within the *[1, 10]* range. ==== ==== AWS Secrets Manager Backend diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java index a1692f5f..76cf0299 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.java @@ -116,14 +116,16 @@ import org.springframework.vault.core.VaultTemplate; @EnableConfigurationProperties({ SvnKitEnvironmentProperties.class, CredhubEnvironmentProperties.class, JdbcEnvironmentProperties.class, NativeEnvironmentProperties.class, VaultEnvironmentProperties.class, RedisEnvironmentProperties.class, AwsS3EnvironmentProperties.class, - AwsSecretsManagerEnvironmentProperties.class, AwsParameterStoreEnvironmentProperties.class, GoogleSecretManagerEnvironmentProperties.class }) + AwsSecretsManagerEnvironmentProperties.class, AwsParameterStoreEnvironmentProperties.class, + GoogleSecretManagerEnvironmentProperties.class }) @Import({ CompositeRepositoryConfiguration.class, JdbcRepositoryConfiguration.class, VaultConfiguration.class, VaultRepositoryConfiguration.class, SpringVaultRepositoryConfiguration.class, CredhubConfiguration.class, CredhubRepositoryConfiguration.class, SvnRepositoryConfiguration.class, NativeRepositoryConfiguration.class, GitRepositoryConfiguration.class, RedisRepositoryConfiguration.class, GoogleCloudSourceConfiguration.class, AwsS3RepositoryConfiguration.class, AwsSecretsManagerRepositoryConfiguration.class, - AwsParameterStoreRepositoryConfiguration.class,, - GoogleSecretManagerRepositoryConfiguration.class, DefaultRepositoryConfiguration.class }) + AwsParameterStoreRepositoryConfiguration.class, GoogleSecretManagerRepositoryConfiguration.class, + // DefaultRepositoryConfiguration must be last + DefaultRepositoryConfiguration.class }) public class EnvironmentRepositoryConfiguration { @Bean diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentProperties.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentProperties.java index c2768513..8dc68cff 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentProperties.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentProperties.java @@ -32,8 +32,7 @@ import org.springframework.validation.annotation.Validated; */ @Validated @ConfigurationProperties("spring.cloud.config.server.awsparamstore") -public class AwsParameterStoreEnvironmentProperties - implements EnvironmentRepositoryProperties { +public class AwsParameterStoreEnvironmentProperties implements EnvironmentRepositoryProperties { static final String DEFAULT_PATH_SEPARATOR = "/"; diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepository.java index c454291f..5bb5f082 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepository.java @@ -87,32 +87,28 @@ public class AwsParameterStoreEnvironmentRepository implements EnvironmentReposi String profileSeparator = environmentProperties.getProfileSeparator(); String defaultProfile = configServerProperties.getDefaultProfile(); - List orderedProfiles = Stream - .concat(Arrays.stream(profiles).filter(p -> !p.equals(defaultProfile)), - Arrays.stream(new String[] { defaultProfile })) - .collect(Collectors.toList()); + List orderedProfiles = Stream.concat(Arrays.stream(profiles).filter(p -> !p.equals(defaultProfile)), + Arrays.stream(new String[] { defaultProfile })).collect(Collectors.toList()); if (application.equals(defaultApplication)) { for (String profile : orderedProfiles) { - result.add(prefix + DEFAULT_PATH_SEPARATOR + defaultApplication - + profileSeparator + profile + DEFAULT_PATH_SEPARATOR); + result.add(prefix + DEFAULT_PATH_SEPARATOR + defaultApplication + profileSeparator + profile + + DEFAULT_PATH_SEPARATOR); } } else { for (String profile : orderedProfiles) { - result.add(prefix + DEFAULT_PATH_SEPARATOR + application - + profileSeparator + profile + DEFAULT_PATH_SEPARATOR); + result.add(prefix + DEFAULT_PATH_SEPARATOR + application + profileSeparator + profile + + DEFAULT_PATH_SEPARATOR); - result.add(prefix + DEFAULT_PATH_SEPARATOR + defaultApplication - + profileSeparator + profile + DEFAULT_PATH_SEPARATOR); + result.add(prefix + DEFAULT_PATH_SEPARATOR + defaultApplication + profileSeparator + profile + + DEFAULT_PATH_SEPARATOR); } - result.add(prefix + DEFAULT_PATH_SEPARATOR + application - + DEFAULT_PATH_SEPARATOR); + result.add(prefix + DEFAULT_PATH_SEPARATOR + application + DEFAULT_PATH_SEPARATOR); } - result.add(prefix + DEFAULT_PATH_SEPARATOR + defaultApplication - + DEFAULT_PATH_SEPARATOR); + result.add(prefix + DEFAULT_PATH_SEPARATOR + defaultApplication + DEFAULT_PATH_SEPARATOR); return result; } @@ -141,8 +137,8 @@ public class AwsParameterStoreEnvironmentRepository implements EnvironmentReposi private Map getPropertiesByParameterPath(String path) { Map result = new HashMap<>(); - GetParametersByPathRequest request = new GetParametersByPathRequest() - .withPath(path).withRecursive(environmentProperties.isRecursive()) + GetParametersByPathRequest request = new GetParametersByPathRequest().withPath(path) + .withRecursive(environmentProperties.isRecursive()) .withWithDecryption(environmentProperties.isDecryptValues()) .withMaxResults(environmentProperties.getMaxResults()); @@ -161,11 +157,9 @@ public class AwsParameterStoreEnvironmentRepository implements EnvironmentReposi return result; } - private void addParametersToProperties(String path, List parameters, - Map properties) { + private void addParametersToProperties(String path, List parameters, Map properties) { for (Parameter parameter : parameters) { - String name = StringUtils.delete(parameter.getName(), path) - .replace(DEFAULT_PATH_SEPARATOR, "."); + String name = StringUtils.delete(parameter.getName(), path).replace(DEFAULT_PATH_SEPARATOR, "."); properties.put(name, parameter.getValue()); } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryFactory.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryFactory.java index 9ee52d91..8219feff 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryFactory.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryFactory.java @@ -32,16 +32,13 @@ public class AwsParameterStoreEnvironmentRepositoryFactory implements private final ConfigServerProperties configServerProperties; - public AwsParameterStoreEnvironmentRepositoryFactory( - ConfigServerProperties configServerProperties) { + public AwsParameterStoreEnvironmentRepositoryFactory(ConfigServerProperties configServerProperties) { this.configServerProperties = configServerProperties; } @Override - public AwsParameterStoreEnvironmentRepository build( - AwsParameterStoreEnvironmentProperties environmentProperties) { - AWSSimpleSystemsManagementClientBuilder clientBuilder = AWSSimpleSystemsManagementClientBuilder - .standard(); + public AwsParameterStoreEnvironmentRepository build(AwsParameterStoreEnvironmentProperties environmentProperties) { + AWSSimpleSystemsManagementClientBuilder clientBuilder = AWSSimpleSystemsManagementClientBuilder.standard(); String region = environmentProperties.getRegion(); @@ -62,8 +59,7 @@ public class AwsParameterStoreEnvironmentRepositoryFactory implements AWSSimpleSystemsManagement client = clientBuilder.build(); - return new AwsParameterStoreEnvironmentRepository(client, configServerProperties, - environmentProperties); + return new AwsParameterStoreEnvironmentRepository(client, configServerProperties, environmentProperties); } } diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java index 7c0efed7..e9f6b19b 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/AwsParameterStoreEnvironmentRepositoryTests.java @@ -97,8 +97,8 @@ public class AwsParameterStoreEnvironmentRepositoryTests { } }; - private final AWSSimpleSystemsManagement awsSsmClientMock = mock( - AWSSimpleSystemsManagement.class, "aws-ssm-client-mock"); + private final AWSSimpleSystemsManagement awsSsmClientMock = mock(AWSSimpleSystemsManagement.class, + "aws-ssm-client-mock"); private final ConfigServerProperties configServerProperties = new ConfigServerProperties(); @@ -118,12 +118,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(defaultApp, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -134,8 +132,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -148,12 +145,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(defaultApp, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -164,8 +159,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -189,8 +183,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -203,12 +196,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/"; - PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, - SHARED_PRODUCTION_PROPERTIES); + PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(defaultApp, profiles, null, null, null); expected.addAll(Arrays.asList(sharedProdParamsPs, sharedParamsPs)); @@ -219,8 +210,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -233,12 +223,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -249,8 +237,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -261,12 +248,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -277,8 +262,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -300,8 +284,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -312,12 +295,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/"; - PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, - SHARED_PRODUCTION_PROPERTIES); + PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedProdParamsPs, sharedParamsPs)); @@ -328,8 +309,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -342,12 +322,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -358,8 +336,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -370,12 +347,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -386,8 +361,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -409,8 +383,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -421,12 +394,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/"; - PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, - SHARED_PRODUCTION_PROPERTIES); + PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedProdParamsPs, sharedParamsPs)); @@ -437,8 +408,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -451,25 +421,23 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(defaultProfile); String appSpecificDefaultParamsPsName = "aws:ssm:parameter:/config/service-default/"; - PropertySource appSpecificDefaultParamsPs = new PropertySource( - appSpecificDefaultParamsPsName, APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); + PropertySource appSpecificDefaultParamsPs = new PropertySource(appSpecificDefaultParamsPsName, + APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/"; PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName, APPLICATION_SPECIFIC_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); - expected.addAll(Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs, - appSpecificParamsPs, sharedParamsPs)); + expected.addAll( + Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs, appSpecificParamsPs, sharedParamsPs)); setupAwsSsmClientMocks(expected); @@ -477,8 +445,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -489,25 +456,23 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String appSpecificDefaultParamsPsName = "aws:ssm:parameter:/config/service-default/"; - PropertySource appSpecificDefaultParamsPs = new PropertySource( - appSpecificDefaultParamsPsName, APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); + PropertySource appSpecificDefaultParamsPs = new PropertySource(appSpecificDefaultParamsPsName, + APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/"; PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName, APPLICATION_SPECIFIC_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); - expected.addAll(Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs, - appSpecificParamsPs, sharedParamsPs)); + expected.addAll( + Arrays.asList(appSpecificDefaultParamsPs, sharedDefaultParamsPs, appSpecificParamsPs, sharedParamsPs)); setupAwsSsmClientMocks(expected); @@ -515,8 +480,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -531,8 +495,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { APPLICATION_SPECIFIC_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(appSpecificParamsPs, sharedParamsPs)); @@ -543,8 +506,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -555,25 +517,23 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String appSpecificProdParamsPsName = "aws:ssm:parameter:/config/service-production/"; - PropertySource appSpecificProdParamsPs = new PropertySource( - appSpecificProdParamsPsName, APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES); + PropertySource appSpecificProdParamsPs = new PropertySource(appSpecificProdParamsPsName, + APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES); String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/"; - PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, - SHARED_PRODUCTION_PROPERTIES); + PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES); String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/"; PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName, APPLICATION_SPECIFIC_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); - expected.addAll(Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs, - appSpecificParamsPs, sharedParamsPs)); + expected.addAll( + Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs, appSpecificParamsPs, sharedParamsPs)); setupAwsSsmClientMocks(expected); @@ -581,8 +541,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -593,34 +552,30 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String appSpecificProdParamsPsName = "aws:ssm:parameter:/config/service-production/"; - PropertySource appSpecificProdParamsPs = new PropertySource( - appSpecificProdParamsPsName, APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES); + PropertySource appSpecificProdParamsPs = new PropertySource(appSpecificProdParamsPsName, + APPLICATION_SPECIFIC_PRODUCTION_PROPERTIES); String sharedProdParamsPsName = "aws:ssm:parameter:/config/application-production/"; - PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, - SHARED_PRODUCTION_PROPERTIES); + PropertySource sharedProdParamsPs = new PropertySource(sharedProdParamsPsName, SHARED_PRODUCTION_PROPERTIES); String appSpecificDefaultParamsPsName = "aws:ssm:parameter:/config/service-default/"; - PropertySource appSpecificDefaultParamsPs = new PropertySource( - appSpecificDefaultParamsPsName, APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); + PropertySource appSpecificDefaultParamsPs = new PropertySource(appSpecificDefaultParamsPsName, + APPLICATION_SPECIFIC_DEFAULT_PROPERTIES); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String appSpecificParamsPsName = "aws:ssm:parameter:/config/service/"; PropertySource appSpecificParamsPs = new PropertySource(appSpecificParamsPsName, APPLICATION_SPECIFIC_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); - expected.addAll(Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs, - appSpecificDefaultParamsPs, sharedDefaultParamsPs, appSpecificParamsPs, - sharedParamsPs)); + expected.addAll(Arrays.asList(appSpecificProdParamsPs, sharedProdParamsPs, appSpecificDefaultParamsPs, + sharedDefaultParamsPs, appSpecificParamsPs, sharedParamsPs)); setupAwsSsmClientMocks(expected); @@ -628,8 +583,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -652,17 +606,14 @@ public class AwsParameterStoreEnvironmentRepositoryTests { PropertySource overridesPs = new PropertySource("overrides", overrides); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); - expected.addAll( - Arrays.asList(overridesPs, sharedDefaultParamsPs, sharedParamsPs)); + expected.addAll(Arrays.asList(overridesPs, sharedDefaultParamsPs, sharedParamsPs)); setupAwsSsmClientMocks(expected); @@ -670,8 +621,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -682,12 +632,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { String[] profiles = StringUtils.commaDelimitedListToStringArray(profile); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -698,8 +646,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -712,12 +659,10 @@ public class AwsParameterStoreEnvironmentRepositoryTests { environmentProperties.setMaxResults(1); String sharedDefaultParamsPsName = "aws:ssm:parameter:/config/application-default/"; - PropertySource sharedDefaultParamsPs = new PropertySource( - sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); + PropertySource sharedDefaultParamsPs = new PropertySource(sharedDefaultParamsPsName, SHARED_DEFAULT_PROPERTIES); String sharedParamsPsName = "aws:ssm:parameter:/config/application/"; - PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, - SHARED_PROPERTIES); + PropertySource sharedParamsPs = new PropertySource(sharedParamsPsName, SHARED_PROPERTIES); Environment expected = new Environment(application, profiles, null, null, null); expected.addAll(Arrays.asList(sharedDefaultParamsPs, sharedParamsPs)); @@ -728,8 +673,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } @Test @@ -748,33 +692,28 @@ public class AwsParameterStoreEnvironmentRepositoryTests { Environment result = repository.findOne(application, profile, null); // Assert - assertThat(result).usingRecursiveComparison().withStrictTypeChecking() - .isEqualTo(expected); + assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected); } private void setupAwsSsmClientMocks(Environment environment) { setupAwsSsmClientMocks(environment, false, false); } - private void setupAwsSsmClientMocks(Environment environment, - boolean withSlashesForPropertyName, boolean paginatedResponse) { + private void setupAwsSsmClientMocks(Environment environment, boolean withSlashesForPropertyName, + boolean paginatedResponse) { for (PropertySource ps : environment.getPropertySources()) { - String path = StringUtils.delete(ps.getName(), - environmentProperties.getOrigin()); + String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin()); - GetParametersByPathRequest request = new GetParametersByPathRequest() - .withPath(path).withRecursive(environmentProperties.isRecursive()) + GetParametersByPathRequest request = new GetParametersByPathRequest().withPath(path) + .withRecursive(environmentProperties.isRecursive()) .withWithDecryption(environmentProperties.isDecryptValues()) .withMaxResults(environmentProperties.getMaxResults()); - Set parameters = getParameters(ps, path, - withSlashesForPropertyName); + Set parameters = getParameters(ps, path, withSlashesForPropertyName); - GetParametersByPathResult response = new GetParametersByPathResult() - .withParameters(parameters); + GetParametersByPathResult response = new GetParametersByPathResult().withParameters(parameters); - if (paginatedResponse - && environmentProperties.getMaxResults() < parameters.size()) { + if (paginatedResponse && environmentProperties.getMaxResults() < parameters.size()) { List> chunks = splitParametersIntoChunks(parameters); String nextToken = null; @@ -785,38 +724,33 @@ public class AwsParameterStoreEnvironmentRepositoryTests { if (i == 0) { nextToken = generateNextToken(); - GetParametersByPathResult responseClone = response.clone() - .withParameters(chunk).withNextToken(nextToken); + GetParametersByPathResult responseClone = response.clone().withParameters(chunk) + .withNextToken(nextToken); - when(awsSsmClientMock.getParametersByPath(eq(request))) - .thenReturn(responseClone); + when(awsSsmClientMock.getParametersByPath(eq(request))).thenReturn(responseClone); } else if (i == chunks.size() - 1) { GetParametersByPathRequest requestClone = request.clone().withNextToken(nextToken); GetParametersByPathResult responseClone = response.clone().withParameters(chunk); - when(awsSsmClientMock.getParametersByPath(eq(requestClone))) - .thenReturn(responseClone); + when(awsSsmClientMock.getParametersByPath(eq(requestClone))).thenReturn(responseClone); } else { String newNextToken = generateNextToken(); - GetParametersByPathRequest requestClone = request.clone() - .withNextToken(nextToken); + GetParametersByPathRequest requestClone = request.clone().withNextToken(nextToken); - GetParametersByPathResult responseClone = response.clone() - .withParameters(chunk).withNextToken(newNextToken); + GetParametersByPathResult responseClone = response.clone().withParameters(chunk) + .withNextToken(newNextToken); - when(awsSsmClientMock.getParametersByPath(eq(requestClone))) - .thenReturn(responseClone); + when(awsSsmClientMock.getParametersByPath(eq(requestClone))).thenReturn(responseClone); nextToken = newNextToken; } } } else { - when(awsSsmClientMock.getParametersByPath(eq(request))) - .thenReturn(response); + when(awsSsmClientMock.getParametersByPath(eq(request))).thenReturn(response); } } } @@ -825,23 +759,17 @@ public class AwsParameterStoreEnvironmentRepositoryTests { boolean withSlashesForPropertyName) { Function, Parameter> mapper = p -> new Parameter() .withName(path + (withSlashesForPropertyName - ? ((String) p.getKey()).replace(".", DEFAULT_PATH_SEPARATOR) - : p.getKey())) - .withType(ParameterType.String).withValue((String) p.getValue()) - .withVersion(1L); + ? ((String) p.getKey()).replace(".", DEFAULT_PATH_SEPARATOR) : p.getKey())) + .withType(ParameterType.String).withValue((String) p.getValue()).withVersion(1L); - return propertySource.getSource().entrySet().stream().map(mapper) - .collect(Collectors.toSet()); + return propertySource.getSource().entrySet().stream().map(mapper).collect(Collectors.toSet()); } private List> splitParametersIntoChunks(Set parameters) { AtomicInteger counter = new AtomicInteger(); Collector>> collector = Collectors - .groupingBy( - p -> counter.getAndIncrement() - / environmentProperties.getMaxResults(), - Collectors.toSet()); + .groupingBy(p -> counter.getAndIncrement() / environmentProperties.getMaxResults(), Collectors.toSet()); return new ArrayList<>(parameters.stream().collect(collector).values()); } @@ -849,8 +777,7 @@ public class AwsParameterStoreEnvironmentRepositoryTests { private String generateNextToken() { String random = randomAlphabetic(RandomUtils.nextInt(3, 33)); - return Base64.getEncoder() - .encodeToString(random.getBytes(StandardCharsets.UTF_8)); + return Base64.getEncoder().encodeToString(random.getBytes(StandardCharsets.UTF_8)); } }