use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse 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.GetSecretValueResponse in project secrets-manager by bancolombia.
the class AWSSecretManagerConnector method getSecret.
private String getSecret(String secretName, SecretsManagerClient client) throws SecretException {
GetSecretValueRequest getSecretValueRequest = GetSecretValueRequest.builder().secretId(secretName).build();
GetSecretValueResponse getSecretValueResult = client.getSecretValue(getSecretValueRequest);
if (getSecretValueResult == null) {
throw new SecretException("Secret value is null");
} else {
if (getSecretValueResult.secretString() != null) {
return getSecretValueResult.secretString();
}
throw new SecretException("Secret value is not a String");
}
}
use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project aws-lambda-powertools-java by awslabs.
the class ParamManagerIntegrationTest method secretsProvider_get.
@Test
public void secretsProvider_get() {
SecretsProvider secretsProvider = ParamManager.getSecretsProvider(secretsManagerClient);
String expectedValue = "Value1";
GetSecretValueResponse response = GetSecretValueResponse.builder().secretString(expectedValue).build();
when(secretsManagerClient.getSecretValue(secretsCaptor.capture())).thenReturn(response);
assertThat(secretsProvider.get("keys")).isEqualTo(expectedValue);
assertThat(secretsCaptor.getValue().secretId()).isEqualTo("keys");
// second time is from cache
assertThat(secretsProvider.get("keys")).isEqualTo(expectedValue);
verify(secretsManagerClient, times(1)).getSecretValue(any(GetSecretValueRequest.class));
}
use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project aws-lambda-powertools-java by awslabs.
the class SecretsProviderTest method getValue.
@Test
public void getValue() {
String key = "Key1";
String expectedValue = "Value1";
GetSecretValueResponse response = GetSecretValueResponse.builder().secretString(expectedValue).build();
Mockito.when(client.getSecretValue(paramCaptor.capture())).thenReturn(response);
String value = provider.getValue(key);
assertThat(value).isEqualTo(expectedValue);
assertThat(paramCaptor.getValue().secretId()).isEqualTo(key);
}
use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project signers by ConsenSys.
the class AwsSecretsManagerTest method updateIfDifferentSecretValue.
private void updateIfDifferentSecretValue(final String secretName, final String secretValue) {
final GetSecretValueResponse getSecretValueResponse = testSecretsManagerClient.getSecretValue(GetSecretValueRequest.builder().secretId(secretName).build());
final boolean hasDifferentSecretValue = !getSecretValueResponse.secretString().equals(secretValue);
if (hasDifferentSecretValue) {
testSecretsManagerClient.updateSecret(UpdateSecretRequest.builder().secretId(secretName).secretString(secretValue).build());
}
}
Aggregations