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

Commit 6336dff

Browse files
committed
Add new parameter-store module and starter
This commit introduces the following changes: * Deprecate `spring-cloud-aws-parameter-store-config` module * Deperecate `spring-cloud-starter-aws-parameter-store-config` module * Create `spring-cloud-aws-parameter-store` * Create `spring-cloud-starter-aws-parameter-store` New module is not aware of spring boot and the starter has not classes.
1 parent 29d67bb commit 6336dff

File tree

16 files changed

+893
-3
lines changed

16 files changed

+893
-3
lines changed

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@
5858
<module>spring-cloud-aws-jdbc</module>
5959
<module>spring-cloud-aws-messaging</module>
6060
<module>spring-cloud-aws-autoconfigure</module>
61+
<module>spring-cloud-aws-parameter-store</module>
6162
<module>spring-cloud-aws-parameter-store-config</module>
6263
<module>spring-cloud-aws-secrets-manager-config</module>
6364
<module>spring-cloud-starter-aws</module>
6465
<module>spring-cloud-starter-aws-jdbc</module>
6566
<module>spring-cloud-starter-aws-messaging</module>
67+
<module>spring-cloud-starter-aws-parameter-store</module>
6668
<module>spring-cloud-starter-aws-parameter-store-config</module>
6769
<module>spring-cloud-starter-aws-secrets-manager-config</module>
6870
<module>spring-cloud-aws-integration-test</module>

spring-cloud-aws-autoconfigure/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</dependency>
4646
<dependency>
4747
<groupId>org.springframework.cloud</groupId>
48-
<artifactId>spring-cloud-aws-parameter-store-config</artifactId>
48+
<artifactId>spring-cloud-aws-parameter-store</artifactId>
4949
<optional>true</optional>
5050
</dependency>
5151
<dependency>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.aws.autoconfigure.config;
18+
19+
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
20+
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient;
21+
22+
import org.springframework.beans.factory.ObjectProvider;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
26+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
27+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
28+
import org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean;
29+
import org.springframework.cloud.aws.core.region.RegionProvider;
30+
import org.springframework.cloud.aws.core.region.StaticRegionProvider;
31+
import org.springframework.cloud.aws.parameterstore.AwsParamStorePropertySourceLocator;
32+
import org.springframework.context.annotation.Bean;
33+
import org.springframework.context.annotation.Configuration;
34+
35+
/**
36+
* Spring Cloud Bootstrap Configuration for setting up an
37+
* {@link AwsParamStorePropertySourceLocator} and its dependencies.
38+
*
39+
* @author Joris Kuipers
40+
* @author Matej Nedic
41+
* @author Eddú Meléndez
42+
* @since 2.3
43+
*/
44+
@Configuration(proxyBeanMethods = false)
45+
@EnableConfigurationProperties(ParameterStoreProperties.class)
46+
@ConditionalOnMissingClass("org.springframework.cloud.aws.autoconfigure.paramstore.AwsParamStoreBootstrapConfiguration")
47+
@ConditionalOnClass({ AWSSimpleSystemsManagement.class,
48+
AwsParamStorePropertySourceLocator.class })
49+
@ConditionalOnProperty(prefix = "spring.cloud.aws.parameterstore", name = "enabled",
50+
matchIfMissing = true)
51+
public class AwsParameterStoreBootstrapConfiguration {
52+
53+
private final RegionProvider regionProvider;
54+
55+
private final ParameterStoreProperties properties;
56+
57+
public AwsParameterStoreBootstrapConfiguration(ParameterStoreProperties properties,
58+
ObjectProvider<RegionProvider> regionProvider) {
59+
this.regionProvider = properties.getRegion() == null
60+
? regionProvider.getIfAvailable()
61+
: new StaticRegionProvider(properties.getRegion());
62+
this.properties = properties;
63+
}
64+
65+
@Bean
66+
@ConditionalOnMissingBean
67+
public AmazonWebserviceClientFactoryBean<AWSSimpleSystemsManagementClient> ssmClient() {
68+
return new AmazonWebserviceClientFactoryBean<>(
69+
AWSSimpleSystemsManagementClient.class, null, this.regionProvider);
70+
}
71+
72+
@Bean
73+
public AwsParamStorePropertySourceLocator awsParamStorePropertySourceLocator(
74+
AWSSimpleSystemsManagement ssmClient) {
75+
AwsParamStorePropertySourceLocator propertySourceLocator = new AwsParamStorePropertySourceLocator(
76+
ssmClient);
77+
propertySourceLocator.setName(this.properties.getName());
78+
propertySourceLocator.setPrefix(this.properties.getPrefix());
79+
propertySourceLocator.setDefaultContext(this.properties.getDefaultContext());
80+
propertySourceLocator.setFailFast(this.properties.isFailFast());
81+
propertySourceLocator.setProfileSeparator(this.properties.getProfileSeparator());
82+
83+
return propertySourceLocator;
84+
}
85+
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.aws.autoconfigure.config;
18+
19+
import java.util.regex.Pattern;
20+
21+
import org.springframework.boot.context.properties.ConfigurationProperties;
22+
import org.springframework.util.StringUtils;
23+
import org.springframework.validation.Errors;
24+
import org.springframework.validation.Validator;
25+
26+
/**
27+
* Configuration properties for the AWS Parameter Store integration.
28+
*
29+
* @author Joris Kuipers
30+
* @author Matej Nedic
31+
* @author Eddú Meléndez
32+
* @since 2.3
33+
*/
34+
@ConfigurationProperties(prefix = "spring.cloud.aws.parameterstore")
35+
public class ParameterStoreProperties implements Validator {
36+
37+
/**
38+
* Pattern used for prefix validation.
39+
*/
40+
private static final Pattern PREFIX_PATTERN = Pattern
41+
.compile("(/[a-zA-Z0-9.\\-_]+)*");
42+
43+
/**
44+
* Pattern used for profileSeparator validation.
45+
*/
46+
private static final Pattern PROFILE_SEPARATOR_PATTERN = Pattern
47+
.compile("[a-zA-Z0-9.\\-_/\\\\]+");
48+
49+
/**
50+
* Prefix indicating first level for every property. Value must start with a forward
51+
* slash followed by a valid path segment or be empty. Defaults to "/config".
52+
*/
53+
private String prefix = "/config";
54+
55+
private String defaultContext = "application";
56+
57+
private String profileSeparator = "_";
58+
59+
/**
60+
* If region value is not null or empty it will be used in creation of
61+
* AWSSimpleSystemsManagement.
62+
*/
63+
private String region;
64+
65+
/** Throw exceptions during config lookup if true, otherwise, log warnings. */
66+
private boolean failFast = true;
67+
68+
/**
69+
* Alternative to spring.application.name to use in looking up values in AWS Parameter
70+
* Store.
71+
*/
72+
private String name;
73+
74+
/** Is AWS Parameter Store support enabled. */
75+
private boolean enabled = true;
76+
77+
@Override
78+
public boolean supports(Class clazz) {
79+
return ParameterStoreProperties.class.isAssignableFrom(clazz);
80+
}
81+
82+
@Override
83+
public void validate(Object target, Errors errors) {
84+
ParameterStoreProperties properties = (ParameterStoreProperties) target;
85+
86+
if (StringUtils.isEmpty(properties.getPrefix())) {
87+
errors.rejectValue("prefix", "NotEmpty",
88+
"prefix should not be empty or null.");
89+
}
90+
91+
if (StringUtils.isEmpty(properties.getDefaultContext())) {
92+
errors.rejectValue("defaultContext", "NotEmpty",
93+
"defaultContext should not be empty or null.");
94+
}
95+
96+
if (StringUtils.isEmpty(properties.getProfileSeparator())) {
97+
errors.rejectValue("profileSeparator", "NotEmpty",
98+
"profileSeparator should not be empty or null.");
99+
}
100+
101+
if (!PREFIX_PATTERN.matcher(properties.getPrefix()).matches()) {
102+
errors.rejectValue("prefix", "Pattern",
103+
"The prefix must have pattern of: " + PREFIX_PATTERN.toString());
104+
}
105+
if (!PROFILE_SEPARATOR_PATTERN.matcher(properties.getProfileSeparator())
106+
.matches()) {
107+
errors.rejectValue("profileSeparator", "Pattern",
108+
"The profileSeparator must have pattern of: "
109+
+ PROFILE_SEPARATOR_PATTERN.toString());
110+
}
111+
}
112+
113+
public String getPrefix() {
114+
return prefix;
115+
}
116+
117+
public void setPrefix(String prefix) {
118+
this.prefix = prefix;
119+
}
120+
121+
public String getDefaultContext() {
122+
return defaultContext;
123+
}
124+
125+
public void setDefaultContext(String defaultContext) {
126+
this.defaultContext = defaultContext;
127+
}
128+
129+
public String getProfileSeparator() {
130+
return profileSeparator;
131+
}
132+
133+
public void setProfileSeparator(String profileSeparator) {
134+
this.profileSeparator = profileSeparator;
135+
}
136+
137+
public boolean isFailFast() {
138+
return failFast;
139+
}
140+
141+
public void setFailFast(boolean failFast) {
142+
this.failFast = failFast;
143+
}
144+
145+
public String getName() {
146+
return name;
147+
}
148+
149+
public void setName(String name) {
150+
this.name = name;
151+
}
152+
153+
public boolean isEnabled() {
154+
return enabled;
155+
}
156+
157+
public void setEnabled(boolean enabled) {
158+
this.enabled = enabled;
159+
}
160+
161+
public String getRegion() {
162+
return region;
163+
}
164+
165+
public void setRegion(final String region) {
166+
this.region = region;
167+
}
168+
169+
}

spring-cloud-aws-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@
4747
"name": "cloud.aws.stack.enabled",
4848
"description": "Enables Stack integration.",
4949
"type": "java.lang.Boolean"
50+
},
51+
{
52+
"defaultValue": true,
53+
"name": "spring.cloud.aws.parameterstore,.enabled",
54+
"description": "Enables ParameterStore integration.",
55+
"type": "java.lang.Boolean"
5056
}
5157
]
5258
}

spring-cloud-aws-autoconfigure/src/main/resources/META-INF/spring.factories

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
2+
org.springframework.cloud.aws.autoconfigure.config.AwsParameterStoreBootstrapConfiguration
3+
14
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
25
org.springframework.cloud.aws.autoconfigure.context.ContextInstanceDataAutoConfiguration,\
36
org.springframework.cloud.aws.autoconfigure.context.ContextCredentialsAutoConfiguration,\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.aws.autoconfigure.config;
18+
19+
import com.amazonaws.regions.Regions;
20+
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient;
21+
import org.junit.jupiter.api.Test;
22+
23+
import org.springframework.boot.autoconfigure.AutoConfigurations;
24+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
25+
import org.springframework.test.util.ReflectionTestUtils;
26+
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
29+
/**
30+
* Unit test for {@link AwsParameterStoreBootstrapConfiguration}.
31+
*
32+
* @author Matej Nedic
33+
* @author Eddú Meléndez
34+
*/
35+
class AwsParameterStoreBootstrapConfigurationTest {
36+
37+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
38+
.withConfiguration(
39+
AutoConfigurations.of(AwsParameterStoreBootstrapConfiguration.class));
40+
41+
@Test
42+
void testWithDefaultRegion() {
43+
this.contextRunner.run(context -> {
44+
AWSSimpleSystemsManagementClient client = context
45+
.getBean(AWSSimpleSystemsManagementClient.class);
46+
Object region = ReflectionTestUtils.getField(client, "signingRegion");
47+
assertThat(region).isEqualTo(Regions.DEFAULT_REGION.getName());
48+
});
49+
}
50+
51+
@Test
52+
void testWithStaticRegion() {
53+
this.contextRunner
54+
.withPropertyValues("spring.cloud.aws.parameterstore.region:us-east-1")
55+
.run(context -> {
56+
AWSSimpleSystemsManagementClient client = context
57+
.getBean(AWSSimpleSystemsManagementClient.class);
58+
Object region = ReflectionTestUtils.getField(client, "signingRegion");
59+
assertThat(region).isEqualTo("us-east-1");
60+
});
61+
}
62+
63+
@Test
64+
void testUserAgent() {
65+
this.contextRunner.run(context -> {
66+
AWSSimpleSystemsManagementClient client = context
67+
.getBean(AWSSimpleSystemsManagementClient.class);
68+
assertThat(client.getClientConfiguration().getUserAgentSuffix())
69+
.startsWith("spring-cloud-aws/");
70+
});
71+
}
72+
73+
}

spring-cloud-aws-dependencies/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494
<artifactId>spring-cloud-starter-aws-messaging</artifactId>
9595
<version>${project.version}</version>
9696
</dependency>
97+
<dependency>
98+
<groupId>org.springframework.cloud</groupId>
99+
<artifactId>spring-cloud-starter-aws-parameter-store</artifactId>
100+
<version>${project.version}</version>
101+
</dependency>
97102
<dependency>
98103
<groupId>org.springframework.cloud</groupId>
99104
<artifactId>spring-cloud-starter-aws-parameter-store-config</artifactId>
@@ -129,6 +134,11 @@
129134
<artifactId>spring-cloud-aws-autoconfigure</artifactId>
130135
<version>${project.version}</version>
131136
</dependency>
137+
<dependency>
138+
<groupId>org.springframework.cloud</groupId>
139+
<artifactId>spring-cloud-aws-parameter-store</artifactId>
140+
<version>${project.version}</version>
141+
</dependency>
132142
<dependency>
133143
<groupId>org.springframework.cloud</groupId>
134144
<artifactId>spring-cloud-aws-parameter-store-config</artifactId>

0 commit comments

Comments
 (0)