diff --git a/extensions/s3-extensions/src/main/java/io/druid/storage/s3/S3StorageDruidModule.java b/extensions/s3-extensions/src/main/java/io/druid/storage/s3/S3StorageDruidModule.java index 792136ae8b9..3d2434365ae 100644 --- a/extensions/s3-extensions/src/main/java/io/druid/storage/s3/S3StorageDruidModule.java +++ b/extensions/s3-extensions/src/main/java/io/druid/storage/s3/S3StorageDruidModule.java @@ -19,13 +19,7 @@ package io.druid.storage.s3; -import com.amazonaws.AmazonClientException; import com.amazonaws.auth.AWSCredentialsProvider; -import com.amazonaws.auth.AWSCredentialsProviderChain; -import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; -import com.amazonaws.auth.InstanceProfileCredentialsProvider; -import com.amazonaws.auth.SystemPropertiesCredentialsProvider; -import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.fasterxml.jackson.databind.Module; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; @@ -68,18 +62,14 @@ public class S3StorageDruidModule implements DruidModule binder.bind(S3TaskLogs.class).in(LazySingleton.class); } - private static class ConfigDrivenAwsCredentialsConfigProvider implements AWSCredentialsProvider + @Provides + @LazySingleton + public AWSCredentialsProvider getAWSCredentialsProvider(final AWSCredentialsConfig config) { - private AWSCredentialsConfig config; - - public ConfigDrivenAwsCredentialsConfigProvider(AWSCredentialsConfig config) { - this.config = config; - } - - @Override - public com.amazonaws.auth.AWSCredentials getCredentials() - { - if (!Strings.isNullOrEmpty(config.getAccessKey()) && !Strings.isNullOrEmpty(config.getSecretKey())) { + if (!Strings.isNullOrEmpty(config.getAccessKey()) && !Strings.isNullOrEmpty(config.getSecretKey())) { + return new AWSCredentialsProvider() { + @Override + public com.amazonaws.auth.AWSCredentials getCredentials() { return new com.amazonaws.auth.AWSCredentials() { @Override public String getAWSAccessKeyId() { @@ -92,57 +82,14 @@ public class S3StorageDruidModule implements DruidModule } }; } - throw new AmazonClientException("Unable to load AWS credentials from druid AWSCredentialsConfig"); - } - - @Override - public void refresh() {} - } - - private static class LazyFileSessionCredentialsProvider implements AWSCredentialsProvider - { - private AWSCredentialsConfig config; - private FileSessionCredentialsProvider provider; - - public LazyFileSessionCredentialsProvider(AWSCredentialsConfig config) { - this.config = config; - } - - private FileSessionCredentialsProvider getUnderlyingProvider() { - if (provider == null) { - synchronized (config) { - if (provider == null) { - provider = new FileSessionCredentialsProvider(config.getFileSessionCredentials()); - } - } - } - return provider; - } - - @Override - public com.amazonaws.auth.AWSCredentials getCredentials() - { - return getUnderlyingProvider().getCredentials(); - } - @Override - public void refresh() { - getUnderlyingProvider().refresh(); + @Override + public void refresh() {} + }; + } else { + return new FileSessionCredentialsProvider(config.getFileSessionCredentials()); } } - - @Provides - @LazySingleton - public AWSCredentialsProvider getAWSCredentialsProvider(final AWSCredentialsConfig config) - { - return new AWSCredentialsProviderChain( - new ConfigDrivenAwsCredentialsConfigProvider(config), - new LazyFileSessionCredentialsProvider(config), - new EnvironmentVariableCredentialsProvider(), - new SystemPropertiesCredentialsProvider(), - new ProfileCredentialsProvider(), - new InstanceProfileCredentialsProvider()); - } @Provides @LazySingleton diff --git a/pom.xml b/pom.xml index 939770ab5de..dd85ddcd820 100644 --- a/pom.xml +++ b/pom.xml @@ -135,7 +135,7 @@ com.amazonaws aws-java-sdk - 1.8.11 + 1.6.0.1 javax.mail