use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project JAQU-CAZ-Payments-API by InformedSolutions.
the class CredentialRetrievalManager method getSecretsValue.
private Map<String, String> getSecretsValue(String secretName) {
GetSecretValueResult getSecretValueResult = getGetSecretValueFor(secretName);
// this is a sample code provided by AWS in AWS Secret Manager console view
String secretString = getSecretValueResult.getSecretString() != null ? getSecretValueResult.getSecretString() : new String(Base64.getDecoder().decode(getSecretValueResult.getSecretBinary()).array());
try {
return objectMapper.readValue(secretString, new TypeReference<Map<String, String>>() {
});
} catch (JsonProcessingException e) {
log.error("Error while parsing AWS secrets:", e);
return Collections.emptyMap();
}
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project JAQU-CAZ-Payments-API by InformedSolutions.
the class CredentialRetrievalManagerTest method returnEmptyIfSecretStringCannotBeProcessed.
@Test
void returnEmptyIfSecretStringCannotBeProcessed() throws JsonProcessingException {
GetSecretValueResult getSecretValueResponse = mock(GetSecretValueResult.class);
Mockito.when(client.getSecretValue(Mockito.any(GetSecretValueRequest.class))).thenReturn(getSecretValueResponse);
Mockito.when(getSecretValueResponse.getSecretString()).thenReturn("{");
Optional<String> apiKey = credentialRetrievalManager.getCardApiKey(UUID.randomUUID());
assertThat(apiKey).isEmpty();
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project JAQU-CAZ-Payments-API by InformedSolutions.
the class CredentialRetrievalManagerTest method getApiKeyFromSecretBinaryString.
@Test
void getApiKeyFromSecretBinaryString() throws JsonProcessingException {
GetSecretValueResult getSecretValueResponse = mock(GetSecretValueResult.class);
Mockito.when(client.getSecretValue(Mockito.any(GetSecretValueRequest.class))).thenReturn(getSecretValueResponse);
Mockito.when(getSecretValueResponse.getSecretString()).thenReturn(null);
UUID cleanAirZoneId = UUID.fromString("105db9f8-cdd0-4b0c-b906-29ce979fdc29");
ObjectNode node = objectMapper.createObjectNode();
node.put(cleanAirZoneId.toString().replace("-", ""), "testApiKey");
Mockito.when(getSecretValueResponse.getSecretBinary()).thenReturn(ByteBuffer.wrap("eyIxMDVkYjlmOGNkZDA0YjBjYjkwNjI5Y2U5NzlmZGMyOSI6ICJ0ZXN0QXBpS2V5In0=".getBytes()));
Optional<String> apiKey = credentialRetrievalManager.getCardApiKey(cleanAirZoneId);
assertThat(apiKey).isPresent();
assertThat(apiKey).contains("testApiKey");
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project JAQU-CAZ-Payments-API by InformedSolutions.
the class CredentialRetrievalManagerTest method cannotGetApiKey.
@Test
void cannotGetApiKey() throws JsonProcessingException {
GetSecretValueResult getSecretValueResponse = mock(GetSecretValueResult.class);
Mockito.when(client.getSecretValue(Mockito.any(GetSecretValueRequest.class))).thenReturn(getSecretValueResponse);
Mockito.when(getSecretValueResponse.getSecretString()).thenReturn("{}");
Optional<String> apiKey = credentialRetrievalManager.getCardApiKey(UUID.randomUUID());
assertThat(apiKey).isEmpty();
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project datarouter by hotpads.
the class AwsSecretClient method read.
@Override
public final Secret read(String name) {
var request = new GetSecretValueRequest().withSecretId(name);
// .withVersionStage("")// related to AWS rotation
try {
GetSecretValueResult result;
try (var $ = TracerTool.startSpan("AWSSecretsManager getSecretValue", TraceSpanGroupType.CLOUD_STORAGE)) {
TracerTool.appendToSpanInfo(name);
result = client.getSecretValue(request);
}
return new Secret(name, result.getSecretString());
} catch (ResourceNotFoundException e) {
throw new SecretNotFoundException(name, e);
}
}
Aggregations