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