Search in sources :

Example 21 with GetSecretValueResponse

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

the class AWSKeyVaultService method getSecret.

@Override
public String getSecret(Map<String, String> getSecretData) {
    final String secretName = getSecretData.get(SECRET_NAME_KEY);
    GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
    GetSecretValueResponse secretValueResponse;
    try {
        secretValueResponse = secretsManager.getSecretValue(getSecretValueRequest);
    } catch (ResourceNotFoundException e) {
        throw new VaultSecretNotFoundException("The requested secret '" + secretName + "' was not found in AWS Secrets Manager");
    } catch (InvalidRequestException | InvalidParameterException e) {
        throw new AWSSecretsManagerException(e);
    }
    if (secretValueResponse != null && secretValueResponse.secretString() != null) {
        return secretValueResponse.secretString();
    }
    throw new VaultSecretNotFoundException("The requested secret '" + secretName + "' was not found in AWS Secrets Manager");
}
Also used : InvalidParameterException(software.amazon.awssdk.services.secretsmanager.model.InvalidParameterException) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) VaultSecretNotFoundException(com.quorum.tessera.key.vault.VaultSecretNotFoundException) InvalidRequestException(software.amazon.awssdk.services.secretsmanager.model.InvalidRequestException) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) ResourceNotFoundException(software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException)

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