Search in sources :

Example 6 with GetParametersByPathResult

use of com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult in project spring-cloud-config by spring-cloud.

the class AwsParameterStoreEnvironmentRepositoryTests method testFindOneWithNoParametersInThePaths.

@Test
public void testFindOneWithNoParametersInThePaths() {
    // Arrange
    String application = configServerProperties.getDefaultApplicationName();
    String profile = configServerProperties.getDefaultProfile();
    String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
    Environment expected = new Environment(application, profiles, null, null, null);
    when(awsSsmClientMock.getParametersByPath(any(GetParametersByPathRequest.class))).thenReturn(new GetParametersByPathResult());
    // Act
    Environment result = repository.findOne(application, profile, null);
    // Assert
    assertThat(result).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected);
}
Also used : Environment(org.springframework.cloud.config.environment.Environment) GetParametersByPathResult(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult) GetParametersByPathRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest) Test(org.junit.Test)

Example 7 with GetParametersByPathResult

use of com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult 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 8 with GetParametersByPathResult

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

the class AwsParamStorePropertySourceLocatorTest method contextSpecificOrderExpected.

@Test
void contextSpecificOrderExpected() {
    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);
    List<String> contextToBeTested = new ArrayList<>(locator.getContexts());
    assertThat(contextToBeTested.get(0)).isEqualTo("application/messaging-service_test/");
    assertThat(contextToBeTested.get(1)).isEqualTo("application/messaging-service/");
    assertThat(contextToBeTested.get(2)).isEqualTo("application/application_test/");
    assertThat(contextToBeTested.get(3)).isEqualTo("application/application/");
}
Also used : ArrayList(java.util.ArrayList) GetParametersByPathResult(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathResult) GetParametersByPathRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParametersByPathRequest) Test(org.junit.jupiter.api.Test)

Example 9 with GetParametersByPathResult

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

the class AwsParamStorePropertySourceTest method arrayParameterNames.

@Test
void arrayParameterNames() {
    GetParametersByPathResult result = new GetParametersByPathResult().withParameters(new Parameter().withName("/config/myservice/key_0_.value").withValue("value1"), new Parameter().withName("/config/myservice/key_0_.nested_0_.nestedValue").withValue("key_nestedValue1"), new Parameter().withName("/config/myservice/key_0_.nested_1_.nestedValue").withValue("key_nestedValue2"), new Parameter().withName("/config/myservice/key_1_.value").withValue("value2"), new Parameter().withName("/config/myservice/key_1_.nested_0_.nestedValue").withValue("key_nestedValue1"), new Parameter().withName("/config/myservice/key_1_.nested_1_.nestedValue").withValue("key_nestedValue2"));
    when(ssmClient.getParametersByPath(any(GetParametersByPathRequest.class))).thenReturn(result);
    propertySource.init();
    assertSoftly(it -> {
        it.assertThat(propertySource.getPropertyNames()).containsExactly("key[0].value", "key[0].nested[0].nestedValue", "key[0].nested[1].nestedValue", "key[1].value", "key[1].nested[0].nestedValue", "key[1].nested[1].nestedValue");
        it.assertThat(propertySource.getProperty("key[0].value")).isEqualTo("value1");
        it.assertThat(propertySource.getProperty("key[1].nested[1].nestedValue")).isEqualTo("key_nestedValue2");
    });
}
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)

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