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();
}
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();
}
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;
}
}
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));
}
Aggregations