use of com.amazonaws.auth.BasicSessionCredentials in project eureka by Netflix.
the class AwsAsgUtil method retrieveAutoScalingGroupCrossAccount.
private AutoScalingGroup retrieveAutoScalingGroupCrossAccount(String asgAccount, String asgName) {
logger.debug("Getting cross account ASG for asgName: {}, asgAccount: {}", asgName, asgAccount);
Credentials credentials = stsCredentials.get(asgAccount);
if (credentials == null || credentials.getExpiration().getTime() < System.currentTimeMillis() + 1000) {
stsCredentials.put(asgAccount, initializeStsSession(asgAccount));
credentials = stsCredentials.get(asgAccount);
}
ClientConfiguration clientConfiguration = new ClientConfiguration().withConnectionTimeout(serverConfig.getASGQueryTimeoutMs());
AmazonAutoScaling autoScalingClient = new AmazonAutoScalingClient(new BasicSessionCredentials(credentials.getAccessKeyId(), credentials.getSecretAccessKey(), credentials.getSessionToken()), clientConfiguration);
String region = clientConfig.getRegion();
if (!region.equals("us-east-1")) {
autoScalingClient.setEndpoint("autoscaling." + region + ".amazonaws.com");
}
DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(asgName);
DescribeAutoScalingGroupsResult result = autoScalingClient.describeAutoScalingGroups(request);
List<AutoScalingGroup> asgs = result.getAutoScalingGroups();
if (asgs.isEmpty()) {
return null;
} else {
return asgs.get(0);
}
}
use of com.amazonaws.auth.BasicSessionCredentials in project pipeline-aws-plugin by jenkinsci.
the class AWSClientFactory method handleStaticCredentials.
private static AWSCredentialsProvider handleStaticCredentials(EnvVars vars) {
String accessKey = vars.get(AWS_ACCESS_KEY_ID);
String secretAccessKey = vars.get(AWS_SECRET_ACCESS_KEY);
if (accessKey != null && secretAccessKey != null) {
String sessionToken = vars.get(AWS_SESSION_TOKEN);
if (sessionToken != null) {
return new AWSStaticCredentialsProvider(new BasicSessionCredentials(accessKey, secretAccessKey, sessionToken));
}
return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretAccessKey));
}
return null;
}
use of com.amazonaws.auth.BasicSessionCredentials in project pipeline-aws-plugin by jenkinsci.
the class SerializableAWSCredentialsProviderTest method serializeBasicSessionCredentials.
@Test
public void serializeBasicSessionCredentials() throws Exception {
BasicSessionCredentials awsCreds = new BasicSessionCredentials(ACCESS_KEY_ID, SECRET_KEY_ID, SESSION_TOKEN);
AWSCredentialsProvider provider = new AWSStaticCredentialsProvider(awsCreds);
SerializableAWSCredentialsProvider serializedProvider = new SerializableAWSCredentialsProvider(provider);
BasicSessionCredentials serializedCredentials = (BasicSessionCredentials) serializedProvider.getCredentials();
Assert.assertEquals(ACCESS_KEY_ID, serializedCredentials.getAWSAccessKeyId());
Assert.assertEquals(SECRET_KEY_ID, serializedCredentials.getAWSSecretKey());
Assert.assertEquals(SESSION_TOKEN, serializedCredentials.getSessionToken());
}
Aggregations