use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class SecretsClientTest method getSecretValue_validSecretId_returnsSecretValue.
@Test
public void getSecretValue_validSecretId_returnsSecretValue() {
GetSecretValueResponse secretValueResponse = GetSecretValueResponse.builder().secretString(SECRET_VALUE).build();
when(secretsManagerClient.getSecretValue((GetSecretValueRequest) any())).thenReturn(secretValueResponse);
String response = secretsClient.getSecretValue(SECRET_ID);
assertEquals(response, SECRET_VALUE);
}
use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project secrets-manager by bancolombia.
the class AWSSecretManagerConnectorTest method prepareClient.
private void prepareClient(String data) {
SecretsManagerClientBuilder clientBuilderMock = Mockito.mock(SecretsManagerClientBuilder.class);
SecretsManagerClient clientMock = Mockito.mock(SecretsManagerClient.class);
GetSecretValueResponse responseMock = GetSecretValueResponse.builder().secretString(data).build();
PowerMockito.mockStatic(SecretsManagerClient.class);
when(SecretsManagerClient.builder()).thenReturn(clientBuilderMock);
when(clientBuilderMock.credentialsProvider(any())).thenReturn(clientBuilderMock);
when(clientBuilderMock.region(any())).thenReturn(clientBuilderMock);
when(clientBuilderMock.build()).thenReturn(clientMock);
when(clientMock.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(responseMock);
}
use of software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse in project aws-lambda-powertools-java by awslabs.
the class SecretsProviderTest method getValueBase64.
@Test
public void getValueBase64() {
String key = "Key2";
String expectedValue = "Value2";
byte[] valueb64 = Base64.getEncoder().encode(expectedValue.getBytes());
GetSecretValueResponse response = GetSecretValueResponse.builder().secretBinary(SdkBytes.fromByteArray(valueb64)).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 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.GetSecretValueResponse in project tessera by ConsenSys.
the class AWSKeyVaultServiceTest method getSecretSecretManagerRerurnsNull.
@Test
public void getSecretSecretManagerRerurnsNull() {
String secretName = "name";
Map<String, String> getSecretData = Map.of(AWSKeyVaultService.SECRET_NAME_KEY, secretName);
GetSecretValueResponse secretValueResponse = null;
when(secretsManager.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(secretValueResponse);
try {
keyVaultService.getSecret(getSecretData);
failBecauseExceptionWasNotThrown(VaultSecretNotFoundException.class);
} catch (VaultSecretNotFoundException vaultSecretNotFoundException) {
verify(secretsManager).getSecretValue(any(GetSecretValueRequest.class));
assertThat(vaultSecretNotFoundException).hasMessage("The requested secret '" + secretName + "' was not found in AWS Secrets Manager");
}
}
Aggregations