Search in sources :

Example 1 with GetParametersByPathResult

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);
}
Also used : GetParametersByPathResult(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult) GetParametersByPathRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest) Test(org.junit.jupiter.api.Test)

Example 2 with GetParametersByPathResult

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()));
    }
}
Also used : GetParametersByPathResult(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult) Parameter(com.amazonaws.services.simplesystemsmanagement.model.Parameter)

Example 3 with GetParametersByPathResult

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");
}
Also used : GetParametersByPathResult(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult) Parameter(com.amazonaws.services.simplesystemsmanagement.model.Parameter) GetParametersByPathRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest) Test(org.junit.jupiter.api.Test)

Example 4 with GetParametersByPathResult

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);
}
Also used : GetParametersByPathResult(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult) GetParametersByPathRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest) Test(org.junit.jupiter.api.Test)

Example 5 with GetParametersByPathResult

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

Aggregations

GetParametersByPathResult (com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult)9 GetParametersByPathRequest (com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest)8 Test (org.junit.jupiter.api.Test)5 Parameter (com.amazonaws.services.simplesystemsmanagement.model.Parameter)4 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 Test (org.junit.Test)1 Environment (org.springframework.cloud.config.environment.Environment)1 PropertySource (org.springframework.cloud.config.environment.PropertySource)1