Search in sources :

Example 26 with BasicSessionCredentials

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);
    }
}
Also used : DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) Credentials(com.amazonaws.services.securitytoken.model.Credentials) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration)

Example 27 with BasicSessionCredentials

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;
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 28 with BasicSessionCredentials

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());
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Aggregations

BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)28 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)9 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)8 Credentials (com.amazonaws.services.securitytoken.model.Credentials)6 AWSCredentials (com.amazonaws.auth.AWSCredentials)5 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)5 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)5 Test (org.junit.Test)5 AssumeRoleRequest (com.amazonaws.services.securitytoken.model.AssumeRoleRequest)4 AssumeRoleResult (com.amazonaws.services.securitytoken.model.AssumeRoleResult)4 AmazonServiceException (com.amazonaws.AmazonServiceException)3 ClientConfiguration (com.amazonaws.ClientConfiguration)3 SdkClientException (com.amazonaws.SdkClientException)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)3 AmazonClientException (com.amazonaws.AmazonClientException)2 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)2 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)2 AWSSecurityTokenService (com.amazonaws.services.securitytoken.AWSSecurityTokenService)2 IOException (java.io.IOException)2 AWSCredentialsProviderChain (com.amazonaws.auth.AWSCredentialsProviderChain)1