use of com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult in project spring-cloud-aws by awspring.
the class AwsParamStorePropertySourceLocatorTest method contextExpectedToHave4Elements.
@Test
void contextExpectedToHave4Elements() {
AwsParamStoreProperties properties = new AwsParamStoreProperties();
properties.setPrefix("application");
properties.setName("messaging-service");
GetParametersByPathResult firstResult = getFirstResult();
GetParametersByPathResult nextResult = getNextResult();
when(this.ssmClient.getParametersByPath(any(GetParametersByPathRequest.class))).thenReturn(firstResult, nextResult);
AwsParamStorePropertySourceLocator locator = new AwsParamStorePropertySourceLocator(this.ssmClient, properties);
this.env.setActiveProfiles("test");
locator.locate(this.env);
assertThat(locator.getContexts()).hasSize(4);
}
use of com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult in project spring-cloud-aws by awspring.
the class AwsParamStorePropertySource method getParameters.
private void getParameters(GetParametersByPathRequest paramsRequest) {
GetParametersByPathResult paramsResult = this.source.getParametersByPath(paramsRequest);
for (Parameter parameter : paramsResult.getParameters()) {
String key = parameter.getName().replace(this.context, "").replace('/', '.').replaceAll("_(\\d)_", "[$1]");
LOG.debug("Populating property retrieved from AWS Parameter Store: " + key);
this.properties.put(key, parameter.getValue());
}
if (paramsResult.getNextToken() != null) {
getParameters(paramsRequest.withNextToken(paramsResult.getNextToken()));
}
}
use of com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult in project spring-cloud-aws by awspring.
the class AwsParamStorePropertySourceTest method followsNextToken.
@Test
void followsNextToken() {
GetParametersByPathResult firstResult = new GetParametersByPathResult().withNextToken("next").withParameters(new Parameter().withName("/config/myservice/key1").withValue("value1"), new Parameter().withName("/config/myservice/key2").withValue("value2"));
GetParametersByPathResult nextResult = new GetParametersByPathResult().withParameters(new Parameter().withName("/config/myservice/key3").withValue("value3"), new Parameter().withName("/config/myservice/key4").withValue("value4"));
when(ssmClient.getParametersByPath(any(GetParametersByPathRequest.class))).thenReturn(firstResult, nextResult);
propertySource.init();
assertThat(propertySource.getPropertyNames()).containsExactly("key1", "key2", "key3", "key4");
assertThat(propertySource.getProperty("key3")).isEqualTo("value3");
}
use of com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult in project spring-cloud-aws by awspring.
the class AwsParamStorePropertySourceLocatorTest method contextExpectedToHave2Elements.
@Test
void contextExpectedToHave2Elements() {
AwsParamStoreProperties properties = new AwsParamStoreProperties();
properties.setPrefix("application");
properties.setName("application");
GetParametersByPathResult firstResult = getFirstResult();
GetParametersByPathResult nextResult = getNextResult();
when(this.ssmClient.getParametersByPath(any(GetParametersByPathRequest.class))).thenReturn(firstResult, nextResult);
AwsParamStorePropertySourceLocator locator = new AwsParamStorePropertySourceLocator(this.ssmClient, properties);
this.env.setActiveProfiles("test");
locator.locate(this.env);
assertThat(locator.getContexts()).hasSize(2);
}
use of com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult in project spring-cloud-config by spring-cloud.
the class AwsParameterStoreEnvironmentRepository method getPropertiesByParameterPath.
private Map<String, String> getPropertiesByParameterPath(String path) {
Map<String, String> result = new HashMap<>();
GetParametersByPathRequest request = new GetParametersByPathRequest().withPath(path).withRecursive(environmentProperties.isRecursive()).withWithDecryption(environmentProperties.isDecryptValues()).withMaxResults(environmentProperties.getMaxResults());
GetParametersByPathResult response = awsSsmClient.getParametersByPath(request);
if (response != null) {
addParametersToProperties(path, response.getParameters(), result);
while (StringUtils.hasLength(response.getNextToken())) {
response = awsSsmClient.getParametersByPath(request.withNextToken(response.getNextToken()));
addParametersToProperties(path, response.getParameters(), result);
}
}
return result;
}
Aggregations