-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ProfileAWSCredentialsProvider test
- Loading branch information
vnarayanan
committed
Feb 5, 2025
1 parent
303f92c
commit 4f98399
Showing
5 changed files
with
85 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
...ools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/ProfileAWSCredentialsProvider.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/auth/ProfileAWSCredentialsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.apache.hadoop.fs.s3a.auth; | ||
Check failure on line 1 in hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/auth/ProfileAWSCredentialsProvider.java
|
||
|
||
import software.amazon.awssdk.auth.credentials.AwsCredentials; | ||
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; | ||
import software.amazon.awssdk.profiles.ProfileFile; | ||
|
||
import org.apache.hadoop.classification.InterfaceAudience; | ||
import org.apache.hadoop.classification.InterfaceStability; | ||
|
||
import org.apache.commons.lang3.SystemUtils; | ||
import org.apache.hadoop.conf.Configuration; | ||
|
||
import java.net.URI; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.Path; | ||
|
||
@InterfaceAudience.Public | ||
@InterfaceStability.Evolving | ||
public class ProfileAWSCredentialsProvider extends AbstractAWSCredentialProvider { | ||
public static final String NAME | ||
= "org.apache.hadoop.fs.s3a.auth.ProfileAWSCredentialsProvider"; | ||
public static final String PROFILE_FILE = "fs.s3a.auth.profile.file"; | ||
public static final String PROFILE_NAME = "fs.s3a.auth.profile.name"; | ||
|
||
private final ProfileCredentialsProvider pcp; | ||
|
||
private static Path getCredentialsPath(Configuration conf) { | ||
String credentialsFile = conf.get(PROFILE_FILE, null); | ||
if (credentialsFile == null) { | ||
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; | ||
} | ||
|
||
private static String getCredentialsName(Configuration conf) { | ||
String profileName = conf.get(PROFILE_NAME, null); | ||
if (profileName == null) { | ||
profileName = SystemUtils.getEnvironmentVariable("AWS_PROFILE", "default"); | ||
} | ||
return profileName; | ||
} | ||
|
||
public ProfileAWSCredentialsProvider(URI uri, Configuration conf) { | ||
super(uri, conf); | ||
ProfileCredentialsProvider.Builder builder = ProfileCredentialsProvider.builder(); | ||
builder.profileName(getCredentialsName(conf)).profileFile(ProfileFile.builder().content(getCredentialsPath(conf)).type(ProfileFile.Type.CREDENTIALS).build()); | ||
pcp = builder.build(); | ||
} | ||
|
||
public AwsCredentials resolveCredentials() { | ||
return pcp.resolveCredentials(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters