Search in sources :

Example 6 with GetSecretValueRequest

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest in project thunder by RohanNagar.

the class SecretsManagerSecretProvider method lookup.

/**
 * Gets the secret value from AWS secrets manager. If there is an {@link SdkClientException}
 * when connecting to Secrets Manager, this method will retry lookup {@code maxRetries} number
 * of times, each after a {@code retryDelaySeconds} period of time.
 *
 * @param name the name of the secret to fetch
 * @return the value of the secret if it exists, otherwise null
 */
@Override
public String lookup(String name) {
    if (secretsClient == null) {
        initializeClient();
    }
    GetSecretValueRequest valueRequest = GetSecretValueRequest.builder().secretId(name).build();
    // Set up a retry policy to retry fetching secrets when unable to connect.
    RetryPolicy<Object> retryPolicy = new RetryPolicy<>().handle(SdkClientException.class).withDelay(Duration.ofSeconds(retryDelaySeconds)).withMaxRetries(maxRetries).onFailedAttempt(e -> LOG.error("Unable to connect to AWS Secrets Manager. Retrying after 30 seconds...", e.getLastFailure()));
    try {
        GetSecretValueResponse valueResponse = Failsafe.with(retryPolicy).get(() -> secretsClient.getSecretValue(valueRequest));
        return valueResponse.secretString();
    } catch (SecretsManagerException e) {
        LOG.error("Secret {} could not be read from AWS Secrets Manager", name, e);
        return null;
    }
}
Also used : SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) RetryPolicy(net.jodah.failsafe.RetryPolicy)

Example 7 with GetSecretValueRequest

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest in project radixdlt by radixdlt.

the class AWSSecretManager method getValue.

private static String getValue(SecretsManagerClient secretsClient, String secretName) {
    GetSecretValueRequest valueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
    GetSecretValueResponse valueResponse = secretsClient.getSecretValue(valueRequest);
    return valueResponse.secretString();
}
Also used : GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)

Example 8 with GetSecretValueRequest

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest in project radixdlt by radixdlt.

the class AWSSecretManager method getBinaryValue.

private static SdkBytes getBinaryValue(SecretsManagerClient secretsClient, String secretName) {
    GetSecretValueRequest valueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
    GetSecretValueResponse valueResponse = secretsClient.getSecretValue(valueRequest);
    return valueResponse.secretBinary();
}
Also used : GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)

Example 9 with GetSecretValueRequest

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest in project signers by ConsenSys.

the class AwsSecretsManager method fetchSecret.

public Optional<String> fetchSecret(final String secretName) {
    try {
        final GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
        final GetSecretValueResponse valueResponse = secretsManagerClient.getSecretValue(getSecretValueRequest);
        return Optional.of(valueResponse.secretString());
    } catch (final ResourceNotFoundException e) {
        return Optional.empty();
    } catch (final SecretsManagerException e) {
        throw new RuntimeException("Failed to fetch secret from AWS Secrets Manager.", e);
    }
}
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) ResourceNotFoundException(software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException)

Example 10 with GetSecretValueRequest

use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest 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

GetSecretValueRequest (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest)10 GetSecretValueResponse (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)9 SecretsManagerException (software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException)4 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 VaultSecretNotFoundException (com.quorum.tessera.key.vault.VaultSecretNotFoundException)1 RetryPolicy (net.jodah.failsafe.RetryPolicy)1 SdkClientException (software.amazon.awssdk.core.exception.SdkClientException)1 SecretsManagerClient (software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)1 InvalidParameterException (software.amazon.awssdk.services.secretsmanager.model.InvalidParameterException)1 InvalidRequestException (software.amazon.awssdk.services.secretsmanager.model.InvalidRequestException)1