Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get PrestoS3FileSystem to work with the AWS Default Credentials Provider #741

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
Expand Down Expand Up @@ -168,19 +169,23 @@ else if (config.getPinGlueClientToCurrentRegion()) {
}
}

asyncGlueClientBuilder.setCredentials(getAwsCredentialsProvider(config));

return asyncGlueClientBuilder.build();
}

private static AWSCredentialsProvider getAwsCredentialsProvider(GlueHiveMetastoreConfig config)
{
if (config.getAwsAccessKey().isPresent() && config.getAwsSecretKey().isPresent()) {
AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(
new BasicAWSCredentials(config.getAwsAccessKey().get(), config.getAwsSecretKey().get()));
asyncGlueClientBuilder.setCredentials(credentialsProvider);
return new AWSStaticCredentialsProvider(
new BasicAWSCredentials(config.getAwsAccessKey().get(), config.getAwsSecretKey().get()));
}
else if (config.getIamRole().isPresent()) {
AWSCredentialsProvider credentialsProvider = new STSAssumeRoleSessionCredentialsProvider
.Builder(config.getIamRole().get(), "presto-session")
.build();
asyncGlueClientBuilder.setCredentials(credentialsProvider);
return new STSAssumeRoleSessionCredentialsProvider
.Builder(config.getIamRole().get(), "presto-session")
.build();
}

return asyncGlueClientBuilder.build();
return DefaultAWSCredentialsProviderChain.getInstance();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.metrics.RequestMetricCollector;
import com.amazonaws.regions.Region;
Expand Down Expand Up @@ -151,7 +152,7 @@ private AWSCredentialsProvider getAwsCredentialsProvider(Configuration conf, Hiv
return getCustomAWSCredentialsProvider(conf, providerClass);
}

throw new RuntimeException("S3 credentials not configured");
return DefaultAWSCredentialsProviderChain.getInstance();
}

private static AWSCredentialsProvider getCustomAWSCredentialsProvider(Configuration conf, String providerClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
Expand Down Expand Up @@ -764,7 +765,7 @@ private AWSCredentialsProvider createAwsCredentialsProvider(URI uri, Configurati
return getCustomAWSCredentialsProvider(uri, conf, providerClass);
}

throw new RuntimeException("S3 credentials not configured");
return DefaultAWSCredentialsProviderChain.getInstance();
}

private static AWSCredentialsProvider getCustomAWSCredentialsProvider(URI uri, Configuration conf, String providerClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3Client;
Expand Down Expand Up @@ -155,15 +156,16 @@ public void testAssumeRoleCredentials()
}
}

@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "S3 credentials not configured")
public void testInstanceCredentialsDisabled()
@Test
public void testDefaultCredentials()
throws Exception
{
Configuration config = new Configuration();
config.setBoolean(S3_USE_INSTANCE_CREDENTIALS, false);

try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) {
fs.initialize(new URI("s3n://test-bucket/"), config);
assertInstanceOf(getAwsCredentialsProvider(fs), DefaultAWSCredentialsProviderChain.class);
}
}

Expand Down