use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest 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);
}
}
use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest 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();
}
}
use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class SecretsClient method getSecretValue.
/**
* Wrapper for getSecretValue function in SecretsManagerClient.
* @param secretId - secretArn for the secret
* @return secret value as String
* @throws EdgeConnectorForKVSException - Wrapper to all exception thrown by SecretsManagerClient
*/
public String getSecretValue(@NonNull String secretId) throws EdgeConnectorForKVSException {
try {
log.info("Retrieving Secret Value for " + secretId);
GetSecretValueRequest secretValueRequest = GetSecretValueRequest.builder().secretId(secretId).versionStage(VERSION_STAGE).build();
GetSecretValueResponse secretValueResponse = this.secretsManagerClient.getSecretValue(secretValueRequest);
return secretValueResponse.secretString();
} catch (Exception e) {
final String errorMessage = String.format("Could not getSecretValue for secretId: %s", secretId);
log.error(errorMessage);
throw new EdgeConnectorForKVSException(errorMessage, e);
}
}
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 getBinaryValue.
private static SdkBytes getBinaryValue(SecretsManagerClient secretsClient, String secretName) {
GetSecretValueRequest valueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
GetSecretValueResponse valueResponse = secretsClient.getSecretValue(valueRequest);
return valueResponse.secretBinary();
}
Aggregations