Search in sources :

Example 6 with SsmClient

use of software.amazon.awssdk.services.ssm.SsmClient in project aws-doc-sdk-examples by awsdocs.

the class GetParameter method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <paraName>\n\n" + "Where:\n" + "    paraName - the name of the parameter.\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String paraName = args[0];
    Region region = Region.US_EAST_1;
    SsmClient ssmClient = SsmClient.builder().region(region).build();
    getParaValue(ssmClient, paraName);
    ssmClient.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) SsmClient(software.amazon.awssdk.services.ssm.SsmClient)

Example 7 with SsmClient

use of software.amazon.awssdk.services.ssm.SsmClient in project aws-doc-sdk-examples by awsdocs.

the class DescribeOpsItems method main.

public static void main(String[] args) {
    Region region = Region.US_EAST_1;
    SsmClient ssmClient = SsmClient.builder().region(region).build();
    describeItems(ssmClient);
    ssmClient.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) SsmClient(software.amazon.awssdk.services.ssm.SsmClient)

Example 8 with SsmClient

use of software.amazon.awssdk.services.ssm.SsmClient in project hippo by NHS-digital-website.

the class AwsRemoteSecrets method getRemoteValue.

@Override
public String getRemoteValue(String key) {
    AwsCredentialsProviderChain provider = AwsCredentialsProviderChain.of(StaticCredentialsProvider.create(AwsBasicCredentials.create(properties.getProperty("accessKey"), properties.getProperty("secretKey"))), // used by localhost
    EnvironmentVariableCredentialsProvider.create());
    try (SsmClient ssmClient = SsmClient.builder().credentialsProvider(provider).region(this.region).build()) {
        GetParameterRequest parameterRequest = GetParameterRequest.builder().name(key).withDecryption(true).build();
        GetParameterResponse parameterResponse = ssmClient.getParameter(parameterRequest);
        return parameterResponse.parameter().value();
    } catch (ParameterNotFoundException e) {
        log.warn(format("The remote parameter '%s' was not found", key));
        return null;
    }
}
Also used : GetParameterRequest(software.amazon.awssdk.services.ssm.model.GetParameterRequest) GetParameterResponse(software.amazon.awssdk.services.ssm.model.GetParameterResponse) ParameterNotFoundException(software.amazon.awssdk.services.ssm.model.ParameterNotFoundException) SsmClient(software.amazon.awssdk.services.ssm.SsmClient)

Example 9 with SsmClient

use of software.amazon.awssdk.services.ssm.SsmClient in project athenz by yahoo.

the class ConfigProviderAwsParametersStoreTest method testConfigProviderAwsParametersStore.

@Test
public void testConfigProviderAwsParametersStore() {
    ConfigProviderAwsParametersStore provider = new ConfigProviderAwsParametersStore() {

        @Override
        protected SsmClient buildSsmClient() {
            SsmClient mockSsmClient = Mockito.mock(SsmClient.class);
            Mockito.when(mockSsmClient.getParametersByPath(Mockito.any(GetParametersByPathRequest.class))).thenAnswer(invocation -> {
                GetParametersByPathRequest request = invocation.getArgument(0);
                assertEquals(request.path(), "/test/prefix");
                assertTrue(request.recursive());
                // Mock 3 response pages.
                GetParametersByPathResponse response = Mockito.mock(GetParametersByPathResponse.class);
                String nextToken = request.nextToken();
                if (nextToken == null) {
                    Mockito.when(response.parameters()).thenAnswer(invocation2 -> Arrays.asList(buildParameter("/test/prefix/01", "value-01"), buildParameter("02", "value-02")));
                    Mockito.when(response.nextToken()).thenReturn("A");
                } else if (nextToken.equals("A")) {
                    Mockito.when(response.parameters()).thenAnswer(invocation2 -> Arrays.asList(buildParameter("/test/prefix/11", "value-11"), buildParameter("12", "value-12")));
                    Mockito.when(response.nextToken()).thenReturn("B");
                } else if (nextToken.equals("B")) {
                    Mockito.when(response.parameters()).thenAnswer(invocation2 -> Arrays.asList(buildParameter("/test/prefix/21", "value-21"), buildParameter("22", "value-22")));
                    Mockito.when(response.nextToken()).thenReturn(null);
                } else {
                    fail("Unexpected nextToken()");
                }
                return response;
            });
            return mockSsmClient;
        }
    };
    assertNull(provider.tryToBuildConfigSource("non-relevant"));
    ConfigProviderAwsParametersStore.ConfigSourceAwsParametersStore source = provider.tryToBuildConfigSource("aws-param-store://test/prefix");
    assertNotNull(source);
    assertEquals(source.toString(), "AWS-Parameters-Store path \"/test/prefix\"");
    assertEquals(source.path, "/test/prefix");
    assertEquals(source.parameterNamesRedundantPrefix, "/test/prefix/");
    Map<String, String> unsortedEntries = source.getConfigEntries().stream().collect(Collectors.toMap(entry -> entry.key, entry -> entry.value));
    Map<String, String> sortedEntries = new TreeMap<>(unsortedEntries);
    assertEquals("{\"01\":\"value-01\",\"02\":\"value-02\",\"11\":\"value-11\",\"12\":\"value-12\",\"21\":\"value-21\",\"22\":\"value-22\"}", Utils.jsonSerializeForLog(sortedEntries));
}
Also used : GetParametersByPathRequest(software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest) Mockito(org.mockito.Mockito) GetParametersByPathResponse(software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse) Arrays(java.util.Arrays) TreeMap(java.util.TreeMap) Assert(org.testng.Assert) SsmClient(software.amazon.awssdk.services.ssm.SsmClient) Map(java.util.Map) Test(org.testng.annotations.Test) Parameter(software.amazon.awssdk.services.ssm.model.Parameter) Collectors(java.util.stream.Collectors) Utils(com.yahoo.athenz.common.server.util.Utils) GetParametersByPathResponse(software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse) GetParametersByPathRequest(software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest) TreeMap(java.util.TreeMap) SsmClient(software.amazon.awssdk.services.ssm.SsmClient) Test(org.testng.annotations.Test)

Aggregations

SsmClient (software.amazon.awssdk.services.ssm.SsmClient)9 Region (software.amazon.awssdk.regions.Region)6 ResourceException (com.yahoo.athenz.common.server.rest.ResourceException)1 Utils (com.yahoo.athenz.common.server.util.Utils)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 Mockito (org.mockito.Mockito)1 Assert (org.testng.Assert)1 Test (org.testng.annotations.Test)1 GetParameterRequest (software.amazon.awssdk.services.ssm.model.GetParameterRequest)1 GetParameterResponse (software.amazon.awssdk.services.ssm.model.GetParameterResponse)1 GetParametersByPathRequest (software.amazon.awssdk.services.ssm.model.GetParametersByPathRequest)1 GetParametersByPathResponse (software.amazon.awssdk.services.ssm.model.GetParametersByPathResponse)1 Parameter (software.amazon.awssdk.services.ssm.model.Parameter)1 ParameterNotFoundException (software.amazon.awssdk.services.ssm.model.ParameterNotFoundException)1