Search in sources :

Example 1 with GetParametersByPathRequest

use of com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest 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;
}
Also used : HashMap(java.util.HashMap) GetParametersByPathResult(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult) GetParametersByPathRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest)

Example 2 with GetParametersByPathRequest

use of com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest 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);
        }
    }
}
Also used : Set(java.util.Set) Parameter(com.amazonaws.services.simplesystemsmanagement.model.Parameter) GetParametersByPathResult(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult) GetParametersByPathRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest) PropertySource(org.springframework.cloud.config.environment.PropertySource)

Example 3 with GetParametersByPathRequest

use of com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest in project spring-cloud-aws by awspring.

the class AwsParamStorePropertySource method init.

public void init() {
    GetParametersByPathRequest paramsRequest = new GetParametersByPathRequest().withPath(context).withRecursive(true).withWithDecryption(true);
    getParameters(paramsRequest);
}
Also used : GetParametersByPathRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest)

Aggregations

GetParametersByPathRequest (com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest)3 GetParametersByPathResult (com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult)2 Parameter (com.amazonaws.services.simplesystemsmanagement.model.Parameter)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 PropertySource (org.springframework.cloud.config.environment.PropertySource)1