|
36 | 36 | @InterfaceAudience.Public
|
37 | 37 | @InterfaceStability.Evolving
|
38 | 38 | public class ProfileAWSCredentialsProvider extends AbstractAWSCredentialProvider {
|
39 |
| - private static final Logger LOG = LoggerFactory.getLogger(ProfileAWSCredentialsProvider.class); |
| 39 | + private static final Logger LOG = LoggerFactory.getLogger(ProfileAWSCredentialsProvider.class); |
40 | 40 |
|
41 |
| - public static final String NAME |
42 |
| - = "org.apache.hadoop.fs.s3a.auth.ProfileAWSCredentialsProvider"; |
| 41 | + public static final String NAME |
| 42 | + = "org.apache.hadoop.fs.s3a.auth.ProfileAWSCredentialsProvider"; |
43 | 43 |
|
44 |
| - /** Conf setting for credentials file path*/ |
45 |
| - public static final String PROFILE_FILE = "fs.s3a.auth.profile.file"; |
| 44 | + /** Conf setting for credentials file path*/ |
| 45 | + public static final String PROFILE_FILE = "fs.s3a.auth.profile.file"; |
46 | 46 |
|
47 |
| - /** Conf setting for profile name*/ |
48 |
| - public static final String PROFILE_NAME = "fs.s3a.auth.profile.name"; |
| 47 | + /** Conf setting for profile name*/ |
| 48 | + public static final String PROFILE_NAME = "fs.s3a.auth.profile.name"; |
49 | 49 |
|
50 |
| - /** Environment variable for credentials file path*/ |
51 |
| - public static final String CREDENTIALS_FILE_ENV = "AWS_SHARED_CREDENTIALS_FILE"; |
52 |
| - /** Environment variable for profile name*/ |
53 |
| - public static final String PROFILE_ENV = "AWS_PROFILE"; |
| 50 | + /** Environment variable for credentials file path*/ |
| 51 | + public static final String CREDENTIALS_FILE_ENV = "AWS_SHARED_CREDENTIALS_FILE"; |
| 52 | + /** Environment variable for profile name*/ |
| 53 | + public static final String PROFILE_ENV = "AWS_PROFILE"; |
54 | 54 |
|
55 |
| - private final ProfileCredentialsProvider pcp; |
| 55 | + private final ProfileCredentialsProvider pcp; |
56 | 56 |
|
57 |
| - private static Path getCredentialsPath(Configuration conf) { |
58 |
| - String credentialsFile = conf.get(PROFILE_FILE, null); |
59 |
| - if (credentialsFile == null) { |
60 |
| - credentialsFile = SystemUtils.getEnvironmentVariable(CREDENTIALS_FILE_ENV, null); |
61 |
| - if (credentialsFile != null) { |
62 |
| - LOG.debug("Fetched credentials file path from environment variable"); |
63 |
| - } |
64 |
| - } |
65 |
| - else { |
66 |
| - LOG.debug("Fetched credentials file path from conf"); |
67 |
| - } |
68 |
| - if (credentialsFile == null) { |
69 |
| - LOG.debug("Using default credentials file path"); |
70 |
| - return FileSystems.getDefault().getPath(SystemUtils.getUserHome().getPath(),".aws", "credentials"); |
71 |
| - } |
72 |
| - else { |
73 |
| - return FileSystems.getDefault().getPath(credentialsFile); |
74 |
| - } |
| 57 | + private static Path getCredentialsPath(Configuration conf) { |
| 58 | + String credentialsFile = conf.get(PROFILE_FILE, null); |
| 59 | + if (credentialsFile == null) { |
| 60 | + credentialsFile = SystemUtils.getEnvironmentVariable(CREDENTIALS_FILE_ENV, null); |
| 61 | + if (credentialsFile != null) { |
| 62 | + LOG.debug("Fetched credentials file path from environment variable"); |
| 63 | + } |
75 | 64 | }
|
76 |
| - |
77 |
| - private static String getCredentialsName(Configuration conf) { |
78 |
| - String profileName = conf.get(PROFILE_NAME, null); |
79 |
| - if (profileName == null) { |
80 |
| - profileName = SystemUtils.getEnvironmentVariable(PROFILE_ENV, null); |
81 |
| - if (profileName == null) { |
82 |
| - profileName = "default"; |
83 |
| - LOG.debug("Using default profile name"); |
84 |
| - } |
85 |
| - else { |
86 |
| - LOG.debug("Fetched profile name from environment variable"); |
87 |
| - } |
88 |
| - } |
89 |
| - else { |
90 |
| - LOG.debug("Fetched profile name from conf"); |
91 |
| - } |
92 |
| - return profileName; |
| 65 | + else { |
| 66 | + LOG.debug("Fetched credentials file path from conf"); |
93 | 67 | }
|
94 |
| - |
95 |
| - public ProfileAWSCredentialsProvider(URI uri, Configuration conf) { |
96 |
| - super(uri, conf); |
97 |
| - ProfileCredentialsProvider.Builder builder = ProfileCredentialsProvider.builder(); |
98 |
| - builder.profileName(getCredentialsName(conf)) |
99 |
| - .profileFile(ProfileFile.builder() |
100 |
| - .content(getCredentialsPath(conf)) |
101 |
| - .type(ProfileFile.Type.CREDENTIALS) |
102 |
| - .build()); |
103 |
| - pcp = builder.build(); |
| 68 | + if (credentialsFile == null) { |
| 69 | + LOG.debug("Using default credentials file path"); |
| 70 | + return FileSystems.getDefault().getPath(SystemUtils.getUserHome().getPath(),".aws", "credentials"); |
| 71 | + } |
| 72 | + else { |
| 73 | + return FileSystems.getDefault().getPath(credentialsFile); |
104 | 74 | }
|
| 75 | + } |
105 | 76 |
|
106 |
| - public AwsCredentials resolveCredentials() { |
107 |
| - return pcp.resolveCredentials(); |
| 77 | + private static String getCredentialsName(Configuration conf) { |
| 78 | + String profileName = conf.get(PROFILE_NAME, null); |
| 79 | + if (profileName == null) { |
| 80 | + profileName = SystemUtils.getEnvironmentVariable(PROFILE_ENV, null); |
| 81 | + if (profileName == null) { |
| 82 | + profileName = "default"; |
| 83 | + LOG.debug("Using default profile name"); |
| 84 | + } |
| 85 | + else { |
| 86 | + LOG.debug("Fetched profile name from environment variable"); |
| 87 | + } |
108 | 88 | }
|
| 89 | + else { |
| 90 | + LOG.debug("Fetched profile name from conf"); |
| 91 | + } |
| 92 | + return profileName; |
| 93 | + } |
| 94 | + |
| 95 | + public ProfileAWSCredentialsProvider(URI uri, Configuration conf) { |
| 96 | + super(uri, conf); |
| 97 | + ProfileCredentialsProvider.Builder builder = ProfileCredentialsProvider.builder(); |
| 98 | + builder.profileName(getCredentialsName(conf)) |
| 99 | + .profileFile(ProfileFile.builder() |
| 100 | + .content(getCredentialsPath(conf)) |
| 101 | + .type(ProfileFile.Type.CREDENTIALS) |
| 102 | + .build()); |
| 103 | + pcp = builder.build(); |
| 104 | + } |
| 105 | + |
| 106 | + public AwsCredentials resolveCredentials() { |
| 107 | + return pcp.resolveCredentials(); |
| 108 | + } |
109 | 109 | }
|
0 commit comments