Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Add new parameter-store module and starter #682

Closed
Closed
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
7 changes: 7 additions & 0 deletions docs/src/main/asciidoc/_configprops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@
|cloud.aws.sqs.region || The specific region for SQS integration.
|cloud.aws.stack.auto | true | Enables the automatic stack name detection for the application.
|cloud.aws.stack.name | | The name of the manually configured stack name that will be used to retrieve the resources.
|spring.cloud.aws.parameterstore.default-context | application |
|spring.cloud.aws.parameterstore.enabled | true | Is AWS Parameter Store support enabled.
|spring.cloud.aws.parameterstore.fail-fast | true | Throw exceptions during config lookup if true, otherwise, log warnings.
|spring.cloud.aws.parameterstore.name | | Alternative to spring.application.name to use in looking up values in AWS Parameter Store.
|spring.cloud.aws.parameterstore.prefix | /config | Prefix indicating first level for every property. Value must start with a forward slash followed by a valid path segment or be empty. Defaults to "/config".
|spring.cloud.aws.parameterstore.profile-separator | _ |
|spring.cloud.aws.parameterstore.region | | The specific region for Parameter Store integration.

|===
43 changes: 43 additions & 0 deletions docs/src/main/asciidoc/spring-cloud-aws.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,49 @@ You can configure the following settings in a Spring Cloud `bootstrap.properties
|`aws.paramstore.enabled`
|`true`
|Can be used to disable the Parameter Store Configuration support even though the auto-configuration is on the classpath.

|`aws.paramstore.region`
|`_`
|The specific region for Parameter Store integration.
|===

There is a new starter `spring-cloud-starter-aws-parameter-store` and it offers new configuration properties.

[cols="3*", options="header"]
|===
|property
|default
|explanation

|`spring.cloud.aws.parameterstore.prefix`
|`/config`
|Prefix indicating first level for every property loaded from the Parameter Store.
Value must start with a forward slash followed by one or more valid path segments or be empty.

|`spring.cloud.aws.parameterstore.defaultContext`
|`application`
|Name of the context that defines properties shared across all services

|`spring.cloud.aws.parameterstore.profileSeparator`
|`_`
|String that separates an appended profile from the context name. Can only contain
dots, dashes, forward slashes, backward slashes and underscores next to alphanumeric characters.

|`spring.cloud.aws.parameterstore.failFast`
|`true`
|Indicates if an error while retrieving the parameters should fail starting the application.

|`spring.cloud.aws.parameterstore.name`
|the configured value for `spring.application.name`
|Name to use when constructing the path for the properties to look up for this specific service.

|`spring.cloud.aws.parameterstore.enabled`
|`true`
|Can be used to disable the Parameter Store Configuration support even though the auto-configuration is on the classpath.

|`spring.cloud.aws.parameterstore.region`
|`_`
|The specific region for Parameter Store integration.
|===

[TIP]
Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@
<module>spring-cloud-aws-jdbc</module>
<module>spring-cloud-aws-messaging</module>
<module>spring-cloud-aws-autoconfigure</module>
<module>spring-cloud-aws-parameter-store</module>
<module>spring-cloud-aws-parameter-store-config</module>
<module>spring-cloud-aws-secrets-manager-config</module>
<module>spring-cloud-starter-aws</module>
<module>spring-cloud-starter-aws-jdbc</module>
<module>spring-cloud-starter-aws-messaging</module>
<module>spring-cloud-starter-aws-parameter-store</module>
<module>spring-cloud-starter-aws-parameter-store-config</module>
<module>spring-cloud-starter-aws-secrets-manager-config</module>
<module>spring-cloud-aws-integration-test</module>
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-aws-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-parameter-store-config</artifactId>
<artifactId>spring-cloud-aws-parameter-store</artifactId>
<optional>true</optional>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2013-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.aws.autoconfigure.config;

import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean;
import org.springframework.cloud.aws.core.region.RegionProvider;
import org.springframework.cloud.aws.core.region.StaticRegionProvider;
import org.springframework.cloud.aws.parameterstore.AwsParamStorePropertySourceLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Spring Cloud Bootstrap Configuration for setting up an
* {@link AwsParamStorePropertySourceLocator} and its dependencies.
*
* @author Joris Kuipers
* @author Matej Nedic
* @author Eddú Meléndez
* @since 2.3
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(ParameterStoreProperties.class)
@ConditionalOnMissingClass("org.springframework.cloud.aws.autoconfigure.paramstore.AwsParamStoreBootstrapConfiguration")
@ConditionalOnClass({ AWSSimpleSystemsManagement.class, AwsParamStorePropertySourceLocator.class })
@ConditionalOnProperty(prefix = "spring.cloud.aws.parameterstore", name = "enabled", matchIfMissing = true)
public class AwsParameterStoreBootstrapConfiguration {

private final RegionProvider regionProvider;

private final ParameterStoreProperties properties;

public AwsParameterStoreBootstrapConfiguration(ParameterStoreProperties properties,
ObjectProvider<RegionProvider> regionProvider) {
this.regionProvider = properties.getRegion() == null ? regionProvider.getIfAvailable()
: new StaticRegionProvider(properties.getRegion());
this.properties = properties;
}

@Bean
@ConditionalOnMissingBean
public AmazonWebserviceClientFactoryBean<AWSSimpleSystemsManagementClient> ssmClient() {
return new AmazonWebserviceClientFactoryBean<>(AWSSimpleSystemsManagementClient.class, null,
this.regionProvider);
}

@Bean
public AwsParamStorePropertySourceLocator awsParamStorePropertySourceLocator(AWSSimpleSystemsManagement ssmClient) {
AwsParamStorePropertySourceLocator propertySourceLocator = new AwsParamStorePropertySourceLocator(ssmClient);
propertySourceLocator.setName(this.properties.getName());
propertySourceLocator.setPrefix(this.properties.getPrefix());
propertySourceLocator.setDefaultContext(this.properties.getDefaultContext());
propertySourceLocator.setFailFast(this.properties.isFailFast());
propertySourceLocator.setProfileSeparator(this.properties.getProfileSeparator());

return propertySourceLocator;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* Copyright 2013-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.aws.autoconfigure.config;

import java.util.regex.Pattern;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

/**
* Configuration properties for the AWS Parameter Store integration.
*
* @author Joris Kuipers
* @author Matej Nedic
* @author Eddú Meléndez
* @since 2.3
*/
@ConfigurationProperties(prefix = "spring.cloud.aws.parameterstore")
public class ParameterStoreProperties implements Validator {

/**
* Pattern used for prefix validation.
*/
private static final Pattern PREFIX_PATTERN = Pattern.compile("(/[a-zA-Z0-9.\\-_]+)*");

/**
* Pattern used for profileSeparator validation.
*/
private static final Pattern PROFILE_SEPARATOR_PATTERN = Pattern.compile("[a-zA-Z0-9.\\-_/\\\\]+");

/**
* Prefix indicating first level for every property. Value must start with a forward
* slash followed by a valid path segment or be empty. Defaults to "/config".
*/
private String prefix = "/config";

private String defaultContext = "application";

private String profileSeparator = "_";

/**
* If region value is not null or empty it will be used in creation of
* AWSSimpleSystemsManagement.
*/
private String region;

/** Throw exceptions during config lookup if true, otherwise, log warnings. */
private boolean failFast = true;

/**
* Alternative to spring.application.name to use in looking up values in AWS Parameter
* Store.
*/
private String name;

/** Is AWS Parameter Store support enabled. */
private boolean enabled = true;

@Override
public boolean supports(Class clazz) {
return ParameterStoreProperties.class.isAssignableFrom(clazz);
}

@Override
public void validate(Object target, Errors errors) {
ParameterStoreProperties properties = (ParameterStoreProperties) target;

if (StringUtils.isEmpty(properties.getPrefix())) {
errors.rejectValue("prefix", "NotEmpty", "prefix should not be empty or null.");
}

if (StringUtils.isEmpty(properties.getDefaultContext())) {
errors.rejectValue("defaultContext", "NotEmpty", "defaultContext should not be empty or null.");
}

if (StringUtils.isEmpty(properties.getProfileSeparator())) {
errors.rejectValue("profileSeparator", "NotEmpty", "profileSeparator should not be empty or null.");
}

if (!PREFIX_PATTERN.matcher(properties.getPrefix()).matches()) {
errors.rejectValue("prefix", "Pattern", "The prefix must have pattern of: " + PREFIX_PATTERN.toString());
}
if (!PROFILE_SEPARATOR_PATTERN.matcher(properties.getProfileSeparator()).matches()) {
errors.rejectValue("profileSeparator", "Pattern",
"The profileSeparator must have pattern of: " + PROFILE_SEPARATOR_PATTERN.toString());
}
}

public String getPrefix() {
return prefix;
}

public void setPrefix(String prefix) {
this.prefix = prefix;
}

public String getDefaultContext() {
return defaultContext;
}

public void setDefaultContext(String defaultContext) {
this.defaultContext = defaultContext;
}

public String getProfileSeparator() {
return profileSeparator;
}

public void setProfileSeparator(String profileSeparator) {
this.profileSeparator = profileSeparator;
}

public boolean isFailFast() {
return failFast;
}

public void setFailFast(boolean failFast) {
this.failFast = failFast;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String getRegion() {
return region;
}

public void setRegion(final String region) {
this.region = region;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"name": "cloud.aws.stack.enabled",
"description": "Enables Stack integration.",
"type": "java.lang.Boolean"
},
{
"defaultValue": true,
"name": "spring.cloud.aws.parameterstore.enabled",
"description": "Enables ParameterStore integration.",
"type": "java.lang.Boolean"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.aws.autoconfigure.config.AwsParameterStoreBootstrapConfiguration

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.aws.autoconfigure.context.ContextInstanceDataAutoConfiguration,\
org.springframework.cloud.aws.autoconfigure.context.ContextCredentialsAutoConfiguration,\
Expand Down
Loading