use of com.amazonaws.services.simplesystemsmanagement.model.Parameter 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.Parameter 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.Parameter in project spring-cloud-config by spring-cloud.
the class AwsParameterStoreEnvironmentRepository method addParametersToProperties.
private void addParametersToProperties(String path, List<Parameter> parameters, Map<String, String> properties) {
for (Parameter parameter : parameters) {
String name = StringUtils.delete(parameter.getName(), path).replace(DEFAULT_PATH_SEPARATOR, ".");
properties.put(name, parameter.getValue());
}
}
use of com.amazonaws.services.simplesystemsmanagement.model.Parameter in project spring-cloud-config by spring-cloud.
the class AwsParameterStoreEnvironmentRepositoryTests method splitParametersIntoChunks.
private List<Set<Parameter>> splitParametersIntoChunks(Set<Parameter> parameters) {
AtomicInteger counter = new AtomicInteger();
Collector<Parameter, ?, Map<Integer, Set<Parameter>>> collector = Collectors.groupingBy(p -> counter.getAndIncrement() / environmentProperties.getMaxResults(), Collectors.toSet());
return new ArrayList<>(parameters.stream().collect(collector).values());
}
use of com.amazonaws.services.simplesystemsmanagement.model.Parameter in project spring-cloud-config by spring-cloud.
the class AwsParameterStoreEnvironmentRepositoryTests method setupAwsSsmClientMocks.
private void setupAwsSsmClientMocks(Environment environment, boolean withSlashesForPropertyName, boolean paginatedResponse) {
for (PropertySource ps : environment.getPropertySources()) {
String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin());
GetParametersByPathRequest request = new GetParametersByPathRequest().withPath(path).withRecursive(environmentProperties.isRecursive()).withWithDecryption(environmentProperties.isDecryptValues()).withMaxResults(environmentProperties.getMaxResults());
Set<Parameter> parameters = getParameters(ps, path, withSlashesForPropertyName);
GetParametersByPathResult response = new GetParametersByPathResult().withParameters(parameters);
if (paginatedResponse && environmentProperties.getMaxResults() < parameters.size()) {
List<Set<Parameter>> chunks = splitParametersIntoChunks(parameters);
String nextToken = null;
for (int i = 0; i < chunks.size(); i++) {
Set<Parameter> chunk = chunks.get(i);
if (i == 0) {
nextToken = generateNextToken();
GetParametersByPathResult responseClone = response.clone().withParameters(chunk).withNextToken(nextToken);
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);
} else {
String newNextToken = generateNextToken();
GetParametersByPathRequest requestClone = request.clone().withNextToken(nextToken);
GetParametersByPathResult responseClone = response.clone().withParameters(chunk).withNextToken(newNextToken);
when(awsSsmClientMock.getParametersByPath(eq(requestClone))).thenReturn(responseClone);
nextToken = newNextToken;
}
}
} else {
when(awsSsmClientMock.getParametersByPath(eq(request))).thenReturn(response);
}
}
}
Aggregations