use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project spring-cloud-config by spring-cloud.
the class AwsSecretsManagerEnvironmentRepositoryTests method setupAwsSmClientMocks.
private void setupAwsSmClientMocks(Environment environment) {
for (PropertySource ps : environment.getPropertySources()) {
String path = StringUtils.delete(ps.getName(), environmentProperties.getOrigin());
GetSecretValueRequest request = new GetSecretValueRequest().withSecretId(path);
String secrets = getSecrets(ps);
GetSecretValueResult response = new GetSecretValueResult().withSecretString(secrets);
when(awsSmClientMock.getSecretValue(eq(request))).thenReturn(response);
}
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project spring-cloud-config by spring-cloud.
the class AwsSecretsManagerEnvironmentRepository method findProperties.
private Map<Object, Object> findProperties(String path) {
Map<Object, Object> properties = new HashMap<>();
GetSecretValueRequest request = new GetSecretValueRequest().withSecretId(path);
try {
GetSecretValueResult response = awsSmClient.getSecretValue(request);
if (response != null) {
Map<String, Object> secretMap = objectMapper.readValue(response.getSecretString(), new TypeReference<Map<String, Object>>() {
});
for (Map.Entry<String, Object> secretEntry : secretMap.entrySet()) {
properties.put(secretEntry.getKey(), secretEntry.getValue());
}
}
} catch (ResourceNotFoundException | IOException e) {
log.debug(String.format("Skip adding propertySource. Unable to load secrets from AWS Secrets Manager for secretId=%s", path), e);
}
return properties;
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project kork by spinnaker.
the class SecretsManagerSecretEngine method decrypt.
@Override
public byte[] decrypt(EncryptedSecret encryptedSecret) {
String secretRegion = encryptedSecret.getParams().get(SECRET_REGION);
String secretName = encryptedSecret.getParams().get(SECRET_NAME);
String secretKey = encryptedSecret.getParams().get(SECRET_KEY);
if (encryptedSecret.isEncryptedFile()) {
GetSecretValueResult secretFileValue = getSecretValue(secretRegion, secretName);
if (secretFileValue.getSecretBinary() != null) {
return secretFileValue.getSecretBinary().array();
} else {
return secretFileValue.getSecretString().getBytes();
}
} else if (secretKey != null) {
return getSecretString(secretRegion, secretName, secretKey);
} else {
return getSecretString(secretRegion, secretName);
}
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project kork by spinnaker.
the class SecretsManagerSecretEngine method decrypt.
@Override
@NonNull
public UserSecret decrypt(@NonNull UserSecretReference reference) {
validate(reference);
Map<String, String> parameters = reference.getParameters();
String secretRegion = parameters.get(SECRET_REGION);
String secretName = parameters.get(SECRET_NAME);
String encoding = parameters.get(StandardSecretParameter.ENCODING.getParameterName());
GetSecretValueResult secretValue = getSecretValue(secretRegion, secretName);
ByteBuffer secretBinary = secretValue.getSecretBinary();
if (secretBinary != null) {
return userSecretMapper.deserialize(secretBinary.array(), encoding);
}
return userSecretMapper.deserialize(secretValue.getSecretString().getBytes(StandardCharsets.UTF_8), encoding);
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-appflow-custom-connector-java by awslabs.
the class CredentialsProvider method getCredentials.
private static Map<String, String> getCredentials(final AWSSecretsManager client, final String secretArn) {
AWSSecretsManager secretsManager = null;
GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest().withSecretId(secretArn);
try {
GetSecretValueResult secretValueResult;
if (client != null) {
secretValueResult = client.getSecretValue(getSecretValueRequest);
} else {
secretsManager = AWSSecretsManagerClientBuilder.defaultClient();
secretValueResult = secretsManager.getSecretValue(getSecretValueRequest);
}
ObjectMapper objectMapper = new ObjectMapper();
Map<String, String> credentials = objectMapper.readValue(secretValueResult.getSecretString(), HashMap.class);
return credentials;
} catch (Exception e) {
throw new RuntimeException(String.format("Unable to get secrets from SecretsManager. SecretArn [%s]: %s", secretArn, e.getMessage()), e);
} finally {
if (secretsManager != null) {
secretsManager.shutdown();
}
}
}
Aggregations