-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-19384. S3A: Add support for ProfileCredentialsProvider #7284
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
Changes from 2 commits
cee3b68
303f92c
4f98399
05b5295
e62e1b9
4da825c
52c722f
3b20f6b
d83e7fb
825d372
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package org.apache.hadoop.fs.s3a; | ||
|
Check failure on line 1 in hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/ProfileAWSCredentialsProvider.java
|
||
|
|
||
| import org.apache.commons.lang3.SystemUtils; | ||
|
||
| import org.apache.hadoop.classification.InterfaceAudience; | ||
| import org.apache.hadoop.classification.InterfaceStability; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import software.amazon.awssdk.auth.credentials.AwsCredentials; | ||
| import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
| import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; | ||
| import software.amazon.awssdk.profiles.ProfileFile; | ||
|
|
||
| import java.net.URI; | ||
| import java.nio.file.FileSystems; | ||
| import java.nio.file.Path; | ||
|
|
||
| @InterfaceAudience.Public | ||
| @InterfaceStability.Stable | ||
|
||
| public class ProfileAWSCredentialsProvider implements AwsCredentialsProvider { | ||
|
||
| public static final String NAME | ||
| = "org.apache.hadoop.fs.s3a.ProfileAWSCredentialsProvider"; | ||
|
|
||
| private ProfileCredentialsProvider pcp; | ||
|
||
|
|
||
| private static Path getCredentialsPath() { | ||
| String credentialsFile = SystemUtils.getEnvironmentVariable("AWS_SHARED_CREDENTIALS_FILE", null); | ||
| Path path = (credentialsFile == null) ? | ||
| FileSystems.getDefault().getPath(SystemUtils.getUserHome().getPath(),".aws","credentials") | ||
|
||
| : FileSystems.getDefault().getPath(credentialsFile); | ||
| return path; | ||
| } | ||
|
|
||
| public ProfileAWSCredentialsProvider(URI uri, Configuration conf) { | ||
| ProfileCredentialsProvider.Builder builder = ProfileCredentialsProvider.builder(); | ||
| builder.profileName("default").profileFile(ProfileFile.builder().content(getCredentialsPath()).type(ProfileFile.Type.CREDENTIALS).build()); | ||
| pcp = builder.build(); | ||
| } | ||
|
|
||
| public ProfileAWSCredentialsProvider(Configuration conf) { | ||
| ProfileCredentialsProvider.Builder builder = ProfileCredentialsProvider.builder(); | ||
| builder.profileName("default").profileFile(ProfileFile.builder().content(getCredentialsPath()).build()); | ||
|
||
| pcp = builder.build(); | ||
| } | ||
| public AwsCredentials resolveCredentials() { | ||
| return pcp.resolveCredentials(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |
| import org.apache.hadoop.fs.s3a.Constants; | ||
| import org.apache.hadoop.fs.s3a.S3AUtils; | ||
| import org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider; | ||
| import org.apache.hadoop.fs.s3a.ProfileAWSCredentialsProvider; | ||
| import org.apache.hadoop.fs.s3a.TemporaryAWSCredentialsProvider; | ||
| import org.apache.hadoop.fs.s3a.adapter.AwsV1BindingSupport; | ||
| import org.apache.hadoop.fs.s3a.impl.InstantiationIOException; | ||
|
|
@@ -84,7 +85,8 @@ public final class CredentialProviderListFactory { | |
| EnvironmentVariableCredentialsProvider.class, | ||
| IAMInstanceCredentialsProvider.class, | ||
| SimpleAWSCredentialsProvider.class, | ||
| TemporaryAWSCredentialsProvider.class)); | ||
| TemporaryAWSCredentialsProvider.class, | ||
| ProfileAWSCredentialsProvider.class)); | ||
|
||
|
|
||
| /** V1 credential provider: {@value}. */ | ||
| public static final String ANONYMOUS_CREDENTIALS_V1 = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this optional but document it