use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse 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.GetSecretValueResponse in project spring-cloud-aws by awspring.
the class SecretsManagerPropertySourceTest method shouldParsePlainTextSecretValue.
@Test
void shouldParsePlainTextSecretValue() {
GetSecretValueResponse secretValueResult = GetSecretValueResponse.builder().secretString("my secret").name("secret name").build();
when(client.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult);
propertySource.init();
assertThat(propertySource.getPropertyNames()).containsExactly("secret name");
assertThat(propertySource.getProperty("secret name")).isEqualTo("my secret");
}
use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project spring-cloud-aws by awspring.
the class SecretsManagerPropertySourceTest method shouldParseSecretValue.
@Test
void shouldParseSecretValue() {
GetSecretValueResponse secretValueResult = GetSecretValueResponse.builder().secretString("{\"key1\": \"value1\", \"key2\": \"value2\"}").build();
when(client.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResult);
propertySource.init();
assertThat(propertySource.getPropertyNames()).containsExactly("key1", "key2");
assertThat(propertySource.getProperty("key1")).isEqualTo("value1");
assertThat(propertySource.getProperty("key2")).isEqualTo("value2");
}
use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse 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.GetSecretValueResponse 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