Search in sources :

Example 1 with GetParameterResult

use of com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult in project aws-java-serverless by hermanlintvelt.

the class SecureParameterService method getParameterValue.

public static String getParameterValue(String name, boolean withDecryption) {
    final AWSSimpleSystemsManagement client = AWSSimpleSystemsManagementClientBuilder.defaultClient();
    GetParameterRequest request = new GetParameterRequest();
    request.withName(name).setWithDecryption(withDecryption);
    GetParameterResult result = client.getParameter(request);
    LOG.debug("SSM result for param " + name + ": " + result);
    if (result.getParameter() != null) {
        return result.getParameter().getValue();
    } else {
        return null;
    }
}
Also used : GetParameterRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParameterRequest) GetParameterResult(com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult) AWSSimpleSystemsManagement(com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement)

Example 2 with GetParameterResult

use of com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult in project di-authentication-api by alphagov.

the class ConfigurationServiceTest method getDocAppCredentialSigningPublicKeyShouldGetECPublicKeyObjectFromParameterStorePEM.

@Test
void getDocAppCredentialSigningPublicKeyShouldGetECPublicKeyObjectFromParameterStorePEM() throws JOSEException {
    var privateKey = new ECKeyGenerator(Curve.P_256).keyID("my-key-id").generate();
    var publicKey = privateKey.toPublicJWK();
    var pem = publicKeyToPem(publicKey);
    var ssmClient = mock(AWSSimpleSystemsManagement.class);
    var request = new GetParameterRequest().withWithDecryption(true).withName("test-doc-app-public-signing-key");
    when(ssmClient.getParameter(eq(request))).thenReturn(new GetParameterResult().withParameter(new Parameter().withName("test-doc-app-public-signing-key").withValue(pem)));
    ConfigurationService configurationService = new ConfigurationService(ssmClient);
    var result = configurationService.getDocAppCredentialSigningPublicKey();
    assertThat(result, equalTo(publicKey.toECPublicKey(new BouncyCastleProvider())));
}
Also used : GetParameterRequest(com.amazonaws.services.simplesystemsmanagement.model.GetParameterRequest) GetParameterResult(com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult) ECKeyGenerator(com.nimbusds.jose.jwk.gen.ECKeyGenerator) Parameter(com.amazonaws.services.simplesystemsmanagement.model.Parameter) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Test(org.junit.jupiter.api.Test)

Aggregations

GetParameterRequest (com.amazonaws.services.simplesystemsmanagement.model.GetParameterRequest)2 GetParameterResult (com.amazonaws.services.simplesystemsmanagement.model.GetParameterResult)2 AWSSimpleSystemsManagement (com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement)1 Parameter (com.amazonaws.services.simplesystemsmanagement.model.Parameter)1 ECKeyGenerator (com.nimbusds.jose.jwk.gen.ECKeyGenerator)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 Test (org.junit.jupiter.api.Test)1