Search in sources :

Example 6 with GetSecretValueResponse

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project tessera by ConsenSys.

the class AWSKeyVaultServiceTest method getSecret.

@Test
public void getSecret() {
    String secretName = "name";
    Map<String, String> getSecretData = Map.of(AWSKeyVaultService.SECRET_NAME_KEY, secretName);
    GetSecretValueResponse secretValueResponse = GetSecretValueResponse.builder().secretString("secret").build();
    when(secretsManager.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResponse);
    assertThat(keyVaultService.getSecret(getSecretData)).isEqualTo("secret");
    verify(secretsManager).getSecretValue(any(GetSecretValueRequest.class));
}
Also used : GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) Test(org.junit.Test)

Example 7 with GetSecretValueResponse

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project aws-doc-sdk-examples by awsdocs.

the class GetSecretValue method getValue.

// snippet-start:[secretsmanager.java2.get_secret.main]
public static void getValue(SecretsManagerClient secretsClient, String secretName) {
    try {
        GetSecretValueRequest valueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
        GetSecretValueResponse valueResponse = secretsClient.getSecretValue(valueRequest);
        String secret = valueResponse.secretString();
        System.out.println(secret);
    } catch (SecretsManagerException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)

Example 8 with GetSecretValueResponse

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project spring-cloud-aws by awspring.

the class SecretsManagerPropertySource method readSecretValue.

private void readSecretValue(GetSecretValueRequest secretValueRequest) {
    GetSecretValueResponse secretValueResponse = source.getSecretValue(secretValueRequest);
    try {
        Map<String, Object> secretMap = jsonMapper.readValue(secretValueResponse.secretString(), new TypeReference<Map<String, Object>>() {
        });
        for (Map.Entry<String, Object> secretEntry : secretMap.entrySet()) {
            LOG.debug("Populating property retrieved from AWS Secrets Manager: " + secretEntry.getKey());
            properties.put(secretEntry.getKey(), secretEntry.getValue());
        }
    } catch (JsonParseException e) {
        // If the secret is not a JSON string, then it is a simple "plain text" string
        LOG.debug("Populating property retrieved from AWS Secrets Manager: " + secretValueResponse.name());
        properties.put(secretValueResponse.name(), secretValueResponse.secretString());
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
Also used : GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) JsonParseException(com.fasterxml.jackson.core.JsonParseException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 9 with GetSecretValueResponse

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project cu-kfs by CU-CommunityApps.

the class AwsSecretServiceImpl method retrieveSecretFromAws.

protected String retrieveSecretFromAws(String fullAwsKey) {
    SecretsManagerClient client = buildSecretsManagerClient();
    try {
        GetSecretValueRequest valueRequest = GetSecretValueRequest.builder().secretId(fullAwsKey).build();
        GetSecretValueResponse valueResponse = client.getSecretValue(valueRequest);
        return valueResponse.secretString();
    } catch (SecretsManagerException e) {
        LOG.error("retrieveSecretFromAws, had an error getting value for secret " + fullAwsKey, e);
        throw new RuntimeException(e);
    } finally {
        client.close();
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

Example 10 with GetSecretValueResponse

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project aws-mysql-jdbc by awslabs.

the class AWSSecretsManagerPlugin method getCurrentCredentials.

Secret getCurrentCredentials() throws SecretsManagerException, JsonProcessingException {
    final GetSecretValueResponse valueResponse = this.secretsManagerClient.getSecretValue(this.getSecretValueRequest);
    final ObjectMapper mapper = new ObjectMapper();
    return mapper.readValue(valueResponse.secretString(), Secret.class);
}
Also used : GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

GetSecretValueResponse (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)21 GetSecretValueRequest (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest)15 Test (org.junit.jupiter.api.Test)6 SecretsManagerException (software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException)4 VaultSecretNotFoundException (com.quorum.tessera.key.vault.VaultSecretNotFoundException)2 Test (org.junit.Test)2 SecretsManagerClient (software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)2 ResourceNotFoundException (software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException)2 SecretException (co.com.bancolombia.secretsmanager.api.exceptions.SecretException)1 EdgeConnectorForKVSException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)1 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 RetryPolicy (net.jodah.failsafe.RetryPolicy)1 SdkClientException (software.amazon.awssdk.core.exception.SdkClientException)1 SecretsManagerClientBuilder (software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder)1 InvalidParameterException (software.amazon.awssdk.services.secretsmanager.model.InvalidParameterException)1 InvalidRequestException (software.amazon.awssdk.services.secretsmanager.model.InvalidRequestException)1