Search in sources :

Example 76 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider 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 77 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider 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)

Example 78 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider in project pipeline-aws-plugin by jenkinsci.

the class SerializableAWSCredentialsProviderTest method serializeBasicAWSCredentials.

@Test
public void serializeBasicAWSCredentials() throws Exception {
    BasicAWSCredentials awsCreds = new BasicAWSCredentials(ACCESS_KEY_ID, SECRET_KEY_ID);
    AWSCredentialsProvider provider = new AWSStaticCredentialsProvider(awsCreds);
    SerializableAWSCredentialsProvider serializedProvider = new SerializableAWSCredentialsProvider(provider);
    Assert.assertEquals(ACCESS_KEY_ID, serializedProvider.getCredentials().getAWSAccessKeyId());
    Assert.assertEquals(SECRET_KEY_ID, serializedProvider.getCredentials().getAWSSecretKey());
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 79 with AWSStaticCredentialsProvider

use of com.amazonaws.auth.AWSStaticCredentialsProvider in project OsmAnd-tools by osmandapp.

the class StorageService method getStorageProviderById.

private StorageType getStorageProviderById(String id) {
    id = id.trim();
    StorageType st = storageProviders.get(id);
    if (st != null) {
        return st;
    }
    if (id.equals(LOCAL_STORAGE)) {
        st = new StorageType();
        st.local = true;
    } else {
        String prefix = "storage.datasource." + id + ".";
        String endpointUrl = env.getProperty(prefix + "endpoint");
        checkNotNull(endpointUrl, "endpoint", id);
        String region = env.getProperty(prefix + "region");
        checkNotNull(region, "endpoint", id);
        String bucket = env.getProperty(prefix + "bucket");
        checkNotNull(region, "bucket", id);
        String accessKey = env.getProperty(prefix + "accesskey");
        String secretKey = env.getProperty(prefix + "secretkey");
        AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard().withEndpointConfiguration(new EndpointConfiguration(endpointUrl, region));
        if (!Algorithms.isEmpty(accessKey)) {
            builder = builder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
        }
        AmazonS3 s3 = builder.build();
        st = new StorageType();
        st.bucket = bucket;
        st.s3Conn = s3;
    }
    storageProviders.put(id, st);
    return st;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)79 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)57 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)18 AWSCredentials (com.amazonaws.auth.AWSCredentials)17 Test (org.junit.Test)14 ClientConfiguration (com.amazonaws.ClientConfiguration)13 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)11 AmazonS3 (com.amazonaws.services.s3.AmazonS3)11 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)11 SdkClientException (com.amazonaws.SdkClientException)10 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)9 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)9 AmazonClientException (com.amazonaws.AmazonClientException)8 Regions (com.amazonaws.regions.Regions)8 Test (org.junit.jupiter.api.Test)7 EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)6 File (java.io.File)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 AWSLambda (com.amazonaws.services.lambda.AWSLambda)4 Segment (com.amazonaws.xray.entities.Segment)4