Skip to content

Commit d7d1d7a

Browse files
Merge branch '2.3.x' of https://github.com/awspring/spring-cloud-aws into 2.3.x
2 parents f8d23f4 + 3cb6589 commit d7d1d7a

File tree

16 files changed

+105
-54
lines changed

16 files changed

+105
-54
lines changed

spring-cloud-aws-parameter-store-config/src/main/java/io/awspring/cloud/paramstore/AwsParamStorePropertySource.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest;
2525
import com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult;
2626
import com.amazonaws.services.simplesystemsmanagement.model.Parameter;
27-
import org.slf4j.Logger;
28-
import org.slf4j.LoggerFactory;
27+
import org.apache.commons.logging.Log;
28+
import org.apache.commons.logging.LogFactory;
2929

3030
import org.springframework.core.env.EnumerablePropertySource;
3131

@@ -39,7 +39,7 @@
3939
*/
4040
public class AwsParamStorePropertySource extends EnumerablePropertySource<AWSSimpleSystemsManagement> {
4141

42-
private static final Logger LOGGER = LoggerFactory.getLogger(AwsParamStorePropertySource.class);
42+
private static Log LOG = LogFactory.getLog(AwsParamStorePropertySource.class);
4343

4444
private final String context;
4545

@@ -71,7 +71,7 @@ private void getParameters(GetParametersByPathRequest paramsRequest) {
7171
GetParametersByPathResult paramsResult = this.source.getParametersByPath(paramsRequest);
7272
for (Parameter parameter : paramsResult.getParameters()) {
7373
String key = parameter.getName().replace(this.context, "").replace('/', '.');
74-
LOGGER.debug("Populating property retrieved from AWS Parameter Store: {}", key);
74+
LOG.debug("Populating property retrieved from AWS Parameter Store: " + key);
7575
this.properties.put(key, parameter.getValue());
7676
}
7777
if (paramsResult.getNextToken() != null) {

spring-cloud-aws-parameter-store-config/src/main/java/io/awspring/cloud/paramstore/AwsParamStorePropertySourceLocator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.util.Set;
2525

2626
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
27-
import org.apache.commons.logging.Log;
28-
import org.apache.commons.logging.LogFactory;
2927

3028
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
3129
import org.springframework.core.env.CompositePropertySource;
@@ -54,8 +52,6 @@ public class AwsParamStorePropertySourceLocator implements PropertySourceLocator
5452

5553
private final Set<String> contexts = new LinkedHashSet<>();
5654

57-
private Log logger = LogFactory.getLog(getClass());
58-
5955
public AwsParamStorePropertySourceLocator(AWSSimpleSystemsManagement ssmClient,
6056
AwsParamStoreProperties properties) {
6157
this.ssmClient = ssmClient;
@@ -74,7 +70,7 @@ public PropertySource<?> locate(Environment environment) {
7470

7571
ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
7672

77-
AwsParamStorePropertySources sources = new AwsParamStorePropertySources(this.properties, this.logger);
73+
AwsParamStorePropertySources sources = new AwsParamStorePropertySources(this.properties);
7874

7975
List<String> profiles = Arrays.asList(env.getActiveProfiles());
8076
List<String> contexts = sources.getAutomaticContexts(profiles);

spring-cloud-aws-parameter-store-config/src/main/java/io/awspring/cloud/paramstore/AwsParamStorePropertySources.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement;
2323
import org.apache.commons.logging.Log;
24+
import org.apache.commons.logging.LogFactory;
2425

2526
/**
2627
* Is responsible for creating {@link AwsParamStorePropertySource} and determining
@@ -32,13 +33,12 @@
3233
*/
3334
public class AwsParamStorePropertySources {
3435

35-
private final AwsParamStoreProperties properties;
36+
private static Log LOG = LogFactory.getLog(AwsParamStorePropertySources.class);
3637

37-
private final Log log;
38+
private final AwsParamStoreProperties properties;
3839

39-
public AwsParamStorePropertySources(AwsParamStoreProperties properties, Log log) {
40+
public AwsParamStorePropertySources(AwsParamStoreProperties properties) {
4041
this.properties = properties;
41-
this.log = log;
4242
}
4343

4444
/**
@@ -93,7 +93,7 @@ private void addProfiles(List<String> contexts, String baseContext, List<String>
9393
*/
9494
public AwsParamStorePropertySource createPropertySource(String context, boolean optional,
9595
AWSSimpleSystemsManagement client) {
96-
log.info("Loading property from AWS Parameter Store with name: " + context + ", optional: " + optional);
96+
LOG.info("Loading property from AWS Parameter Store with name: " + context + ", optional: " + optional);
9797
try {
9898
AwsParamStorePropertySource propertySource = new AwsParamStorePropertySource(context, client);
9999
propertySource.init();
@@ -105,7 +105,7 @@ public AwsParamStorePropertySource createPropertySource(String context, boolean
105105
throw new AwsParameterPropertySourceNotFoundException(e);
106106
}
107107
else {
108-
log.warn("Unable to load AWS parameter from " + context + ". " + e.getMessage());
108+
LOG.warn("Unable to load AWS parameter from " + context + ". " + e.getMessage());
109109
}
110110
}
111111
return null;

spring-cloud-aws-parameter-store-config/src/test/java/io/awspring/cloud/paramstore/AwsParamStorePropertySourcesTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
import java.util.Collections;
2020
import java.util.List;
2121

22-
import org.apache.commons.logging.Log;
2322
import org.junit.jupiter.api.BeforeEach;
2423
import org.junit.jupiter.api.Test;
2524

2625
import static org.assertj.core.api.Assertions.assertThat;
27-
import static org.mockito.Mockito.mock;
2826

2927
/**
3028
* Unit test for {@link AwsParamStorePropertySourceLocator}.
@@ -33,8 +31,6 @@
3331
*/
3432
class AwsParamStorePropertySourcesTest {
3533

36-
private final Log logMock = mock(Log.class);
37-
3834
private AwsParamStoreProperties properties;
3935

4036
@BeforeEach
@@ -46,7 +42,7 @@ void setUp() {
4642

4743
@Test
4844
void getAutomaticContextsWithSingleProfile() {
49-
AwsParamStorePropertySources propertySource = new AwsParamStorePropertySources(properties, logMock);
45+
AwsParamStorePropertySources propertySource = new AwsParamStorePropertySources(properties);
5046

5147
List<String> contexts = propertySource.getAutomaticContexts(Collections.singletonList("production"));
5248

@@ -57,7 +53,7 @@ void getAutomaticContextsWithSingleProfile() {
5753

5854
@Test
5955
void getAutomaticContextsWithoutProfile() {
60-
AwsParamStorePropertySources propertySource = new AwsParamStorePropertySources(properties, logMock);
56+
AwsParamStorePropertySources propertySource = new AwsParamStorePropertySources(properties);
6157

6258
List<String> contexts = propertySource.getAutomaticContexts(Collections.emptyList());
6359

@@ -70,7 +66,7 @@ void getAutomaticContextsWithSingleProfileWithPrefixEmpty() {
7066
AwsParamStoreProperties properties = new AwsParamStoreProperties();
7167
properties.setName("messaging-service");
7268
properties.setPrefix("");
73-
AwsParamStorePropertySources propertySource = new AwsParamStorePropertySources(properties, logMock);
69+
AwsParamStorePropertySources propertySource = new AwsParamStorePropertySources(properties);
7470

7571
List<String> contexts = propertySource.getAutomaticContexts(Collections.singletonList("production"));
7672

spring-cloud-aws-samples/spring-cloud-aws-parameter-store-sample/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# importing single parameter
22
spring.config.import=aws-parameterstore:/config/spring/
3+
logging.level.io.awspring.cloud.paramstore=debug
34

45
# importing multiple parameters
56
# spring.config.import: aws-parameterstore:/config/spring;/config/common

spring-cloud-aws-samples/spring-cloud-aws-secrets-manager-sample/infrastructure/lib/infrastructure-stack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class InfrastructureStack extends cdk.Stack {
1010
generateSecretString: {
1111
secretStringTemplate: '{}',
1212
generateStringKey: 'password',
13+
excludeCharacters: '#$' // Spring tries to interpolate any ${} and #{}
1314
}
1415
});
1516
}

spring-cloud-aws-samples/spring-cloud-aws-secrets-manager-sample/src/main/resources/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# importing single secret
22
spring.config.import: aws-secretsmanager:/secrets/spring-cloud-aws-sample-app
3+
logging.level.io.awspring.cloud.secretsmanager: debug
34

45
# importing multiple secrets
56
# spring.config.import: aws-secretsmanager:/secrets/spring-cloud-aws-sample-app;/secret/common

spring-cloud-aws-secrets-manager-config/src/main/java/io/awspring/cloud/secretsmanager/AwsSecretsManagerPropertySource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.fasterxml.jackson.core.JsonProcessingException;
2828
import com.fasterxml.jackson.core.type.TypeReference;
2929
import com.fasterxml.jackson.databind.ObjectMapper;
30+
import org.apache.commons.logging.Log;
31+
import org.apache.commons.logging.LogFactory;
3032

3133
import org.springframework.core.env.EnumerablePropertySource;
3234

@@ -40,6 +42,8 @@
4042
*/
4143
public class AwsSecretsManagerPropertySource extends EnumerablePropertySource<AWSSecretsManager> {
4244

45+
private static Log LOG = LogFactory.getLog(AwsSecretsManagerPropertySource.class);
46+
4347
private final ObjectMapper jsonMapper = new ObjectMapper();
4448

4549
private final String context;
@@ -79,6 +83,7 @@ private void readSecretValue(GetSecretValueRequest secretValueRequest) {
7983
});
8084

8185
for (Map.Entry<String, Object> secretEntry : secretMap.entrySet()) {
86+
LOG.debug("Populating property retrieved from AWS Secrets Manager: " + secretEntry.getKey());
8287
properties.put(secretEntry.getKey(), secretEntry.getValue());
8388
}
8489
}

spring-cloud-aws-secrets-manager-config/src/main/java/io/awspring/cloud/secretsmanager/AwsSecretsManagerPropertySourceLocator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.util.Set;
2525

2626
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
27-
import org.apache.commons.logging.Log;
28-
import org.apache.commons.logging.LogFactory;
2927

3028
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
3129
import org.springframework.core.env.CompositePropertySource;
@@ -57,8 +55,6 @@ public class AwsSecretsManagerPropertySourceLocator implements PropertySourceLoc
5755

5856
private final Set<String> contexts = new LinkedHashSet<>();
5957

60-
private Log logger = LogFactory.getLog(getClass());
61-
6258
public AwsSecretsManagerPropertySourceLocator(String propertySourceName, AWSSecretsManager smClient,
6359
AwsSecretsManagerProperties properties) {
6460
this.propertySourceName = propertySourceName;
@@ -82,7 +78,7 @@ public PropertySource<?> locate(Environment environment) {
8278

8379
ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
8480

85-
AwsSecretsManagerPropertySources sources = new AwsSecretsManagerPropertySources(properties, logger);
81+
AwsSecretsManagerPropertySources sources = new AwsSecretsManagerPropertySources(properties);
8682

8783
List<String> profiles = Arrays.asList(env.getActiveProfiles());
8884
List<String> contexts = sources.getAutomaticContexts(profiles);

spring-cloud-aws-secrets-manager-config/src/main/java/io/awspring/cloud/secretsmanager/AwsSecretsManagerPropertySources.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
2323
import org.apache.commons.logging.Log;
24+
import org.apache.commons.logging.LogFactory;
2425

2526
/**
2627
* Is responsible for creating {@link AwsSecretsManagerPropertySource} and determining
@@ -32,13 +33,12 @@
3233
*/
3334
public class AwsSecretsManagerPropertySources {
3435

35-
private final AwsSecretsManagerProperties properties;
36+
private static Log LOG = LogFactory.getLog(AwsSecretsManagerPropertySources.class);
3637

37-
private final Log log;
38+
private final AwsSecretsManagerProperties properties;
3839

39-
public AwsSecretsManagerPropertySources(AwsSecretsManagerProperties properties, Log log) {
40+
public AwsSecretsManagerPropertySources(AwsSecretsManagerProperties properties) {
4041
this.properties = properties;
41-
this.log = log;
4242
}
4343

4444
public List<String> getAutomaticContexts(List<String> profiles) {
@@ -81,7 +81,7 @@ private void addProfiles(List<String> contexts, String baseContext, List<String>
8181
*/
8282
public AwsSecretsManagerPropertySource createPropertySource(String context, boolean optional,
8383
AWSSecretsManager client) {
84-
log.info("Loading secrets from AWS Secret Manager secret with name: " + context + ", optional: " + optional);
84+
LOG.info("Loading secrets from AWS Secret Manager secret with name: " + context + ", optional: " + optional);
8585
try {
8686
AwsSecretsManagerPropertySource propertySource = new AwsSecretsManagerPropertySource(context, client);
8787
propertySource.init();
@@ -93,7 +93,7 @@ public AwsSecretsManagerPropertySource createPropertySource(String context, bool
9393
throw new AwsSecretsManagerPropertySourceNotFoundException(e);
9494
}
9595
else {
96-
log.warn("Unable to load AWS secret from " + context + ". " + e.getMessage());
96+
LOG.warn("Unable to load AWS secret from " + context + ". " + e.getMessage());
9797
}
9898
}
9999
return null;

0 commit comments

Comments
 (0)