use of shaded.com.google.common.base.Supplier 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;
}
};
}
use of shaded.com.google.common.base.Supplier 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);
}
}
Aggregations