Search in sources :

Example 1 with SessionCredentials

use of org.jclouds.aws.domain.SessionCredentials in project artifact-manager-s3-plugin by jenkinsci.

the class S3BlobStore method getCredentialsSupplier.

@Override
public Supplier<Credentials> getCredentialsSupplier() throws IOException {
    // get user credentials from env vars, profiles,...
    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
    // Assume we are using session credentials
    AWSSessionCredentials awsCredentials = (AWSSessionCredentials) builder.getCredentials().getCredentials();
    if (awsCredentials == null) {
        throw new IOException("Unable to get credentials from environment");
    }
    SessionCredentials sessionCredentials = SessionCredentials.builder().accessKeyId(// 
    awsCredentials.getAWSAccessKeyId()).secretAccessKey(// 
    awsCredentials.getAWSSecretKey()).sessionToken(// 
    awsCredentials.getSessionToken()).build();
    return new Supplier<Credentials>() {

        @Override
        public Credentials get() {
            return sessionCredentials;
        }
    };
}
Also used : AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) SessionCredentials(org.jclouds.aws.domain.SessionCredentials) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) Supplier(shaded.com.google.common.base.Supplier) IOException(java.io.IOException)

Example 2 with SessionCredentials

use of org.jclouds.aws.domain.SessionCredentials in project artifact-manager-s3-plugin by jenkinsci.

the class JCloudsArtifactManager method getContext.

private static BlobStoreContext getContext(String blobContainer) throws IOException {
    // TODO allow configuration
    // get user credentials from env vars, profiles,...
    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
    try {
        builder.build().doesBucketExistV2(blobContainer);
    } catch (RuntimeException x) {
        throw new IOException(x);
    }
    // Assume we are using session credentials
    AWSSessionCredentials awsCredentials = (AWSSessionCredentials) builder.getCredentials().getCredentials();
    if (awsCredentials == null) {
        throw new IOException("Unable to detect AWS session credentials");
    }
    SessionCredentials sessionCredentials = SessionCredentials.builder().accessKeyId(// 
    awsCredentials.getAWSAccessKeyId()).secretAccessKey(// 
    awsCredentials.getAWSSecretKey()).sessionToken(// 
    awsCredentials.getSessionToken()).build();
    Supplier<Credentials> credentialsSupplier = new Supplier<Credentials>() {

        @Override
        public Credentials get() {
            return sessionCredentials;
        }
    };
    ProviderRegistry.registerProvider(AWSS3ProviderMetadata.builder().build());
    try {
        return ContextBuilder.newBuilder("aws-s3").credentialsSupplier(credentialsSupplier).buildView(BlobStoreContext.class);
    } catch (NoSuchElementException x) {
        throw new IOException(x);
    }
}
Also used : SessionCredentials(org.jclouds.aws.domain.SessionCredentials) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) Supplier(shaded.com.google.common.base.Supplier) IOException(java.io.IOException) SessionCredentials(org.jclouds.aws.domain.SessionCredentials) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) Credentials(org.jclouds.domain.Credentials) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)2 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)2 IOException (java.io.IOException)2 SessionCredentials (org.jclouds.aws.domain.SessionCredentials)2 Supplier (shaded.com.google.common.base.Supplier)2 NoSuchElementException (java.util.NoSuchElementException)1 Credentials (org.jclouds.domain.Credentials)1