use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project bazel-buildfarm by bazelbuild.
the class AwsMetricsPublisher method getAwsSecret.
@SuppressWarnings("unchecked")
private void getAwsSecret(String secretName) {
AWSSecretsManager client = AWSSecretsManagerClientBuilder.standard().withRegion(region).build();
GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest().withSecretId(secretName);
GetSecretValueResult getSecretValueResult;
try {
getSecretValueResult = client.getSecretValue(getSecretValueRequest);
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("Could not get secret %s from AWS.", secretName));
return;
}
String secret;
if (getSecretValueResult.getSecretString() != null) {
secret = getSecretValueResult.getSecretString();
} else {
secret = new String(Base64.getDecoder().decode(getSecretValueResult.getSecretBinary()).array());
}
if (secret != null) {
try {
final ObjectMapper objectMapper = new ObjectMapper();
final HashMap<String, String> secretMap = objectMapper.readValue(secret, HashMap.class);
accessKeyId = secretMap.get("access_key");
secretKey = secretMap.get("secret_key");
} catch (IOException e) {
logger.log(Level.SEVERE, String.format("Could not parse secret %s from AWS", secretName));
}
}
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-secretsmanager-caching-java by aws.
the class SecretCacheObject method getSecretValue.
/**
* Return the cached result from AWS Secrets Manager for GetSecretValue.
*
* @return The cached GetSecretValue result.
*/
public GetSecretValueResult getSecretValue() {
synchronized (lock) {
refresh();
if (null == this.data) {
if (null != this.exception) {
throw this.exception;
}
}
GetSecretValueResult gsv = this.getSecretValue(this.getResult());
// If there is no cached result, return null.
if (null == gsv) {
return null;
}
// We want to clone the result to prevent callers from modifying
// the cached data.
gsv = gsv.clone();
// The prior clone did not perform a deep clone of all objects.
// Handle cloning the byte buffer it one exists.
gsv.setSecretBinary(clone(gsv.getSecretBinary()));
gsv.setVersionStages(clone(gsv.getVersionStages()));
return gsv;
}
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-secretsmanager-caching-java by aws.
the class SecretCache method getSecretBinary.
/**
* Method to retrieve a binary secret from AWS Secrets Manager.
*
* @param secretId
* The identifier for the secret being requested.
* @return The binary secret
*/
public ByteBuffer getSecretBinary(final String secretId) {
SecretCacheItem secret = this.getCachedSecret(secretId);
GetSecretValueResult gsv = secret.getSecretValue();
if (null == gsv) {
return null;
}
return gsv.getSecretBinary();
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-secretsmanager-caching-java by aws.
the class SecretCache method getSecretString.
/**
* Method to retrieve a string secret from AWS Secrets Manager.
*
* @param secretId
* The identifier for the secret being requested.
* @return The string secret
*/
public String getSecretString(final String secretId) {
SecretCacheItem secret = this.getCachedSecret(secretId);
GetSecretValueResult gsv = secret.getSecretValue();
if (null == gsv) {
return null;
}
return gsv.getSecretString();
}
use of com.amazonaws.services.secretsmanager.model.GetSecretValueResult in project aws-athena-query-federation by awslabs.
the class CacheableSecretsManagerTest method resolveSecrets.
@Test
public void resolveSecrets() {
when(mockSecretsManager.getSecretValue(any(GetSecretValueRequest.class))).thenAnswer((InvocationOnMock invocation) -> {
GetSecretValueRequest request = invocation.getArgumentAt(0, GetSecretValueRequest.class);
String result = request.getSecretId();
if (result.equalsIgnoreCase("unknown")) {
throw new RuntimeException("Unknown secret!");
}
return new GetSecretValueResult().withSecretString(result);
});
String oneSecret = "${OneSecret}";
String oneExpected = "OneSecret";
assertEquals(oneExpected, cachableSecretsManager.resolveSecrets(oneSecret));
String twoSecrets = "ThisIsMyStringWith${TwoSecret}SuperSecret${Secrets}";
String twoExpected = "ThisIsMyStringWithTwoSecretSuperSecretSecrets";
assertEquals(twoExpected, cachableSecretsManager.resolveSecrets(twoSecrets));
String noSecrets = "ThisIsMyStringWithTwoSecretSuperSecretSecrets";
String noSecretsExpected = "ThisIsMyStringWithTwoSecretSuperSecretSecrets";
assertEquals(noSecretsExpected, cachableSecretsManager.resolveSecrets(noSecrets));
String commonErrors = "ThisIsM}yStringWi${thTwoSecretS{uperSecretSecrets";
String commonErrorsExpected = "ThisIsM}yStringWi${thTwoSecretS{uperSecretSecrets";
assertEquals(commonErrorsExpected, cachableSecretsManager.resolveSecrets(commonErrors));
String unknownSecret = "This${Unknown}";
try {
cachableSecretsManager.resolveSecrets(unknownSecret);
fail("Should not see this!");
} catch (RuntimeException ex) {
}
}
Aggregations