Skip to content

Commit

Permalink
nrt_utils support defaultCredentialsProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
waziqi89 committed Dec 27, 2023
1 parent 003e652 commit 1e1129e
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ public class DeleteIncrementalSnapshotsCommand implements Callable<Integer> {

@CommandLine.Option(
names = {"-c", "--credsFile"},
description = "File holding AWS credentials, uses default locations if not set")
description =
"File holding AWS credentials, uses default locations if not set; Will use DefaultCredentialProvider if this is unset.")
private String credsFile;

@CommandLine.Option(
names = {"-p", "--credsProfile"},
description = "Profile to use from creds file",
description = "Profile to use from creds file; Neglected when credsFile is unset.",
defaultValue = "default")
private String credsProfile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ public class IncrementalDataCleanupCommand implements Callable<Integer> {

@CommandLine.Option(
names = {"-c", "--credsFile"},
description = "File holding AWS credentials, uses default locations if not set")
description =
"File holding AWS credentials, uses default locations if not set; Will use DefaultCredentialProvider if this is unset.")
private String credsFile;

@CommandLine.Option(
names = {"-p", "--credsProfile"},
description = "Profile to use from creds file",
description = "Profile to use from creds file; Neglected when credsFile is unset.",
defaultValue = "default")
private String credsProfile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ public class ListIncrementalSnapshotsCommand implements Callable<Integer> {

@CommandLine.Option(
names = {"-c", "--credsFile"},
description = "File holding AWS credentials, uses default locations if not set")
description =
"File holding AWS credentials, uses default locations if not set; Will use DefaultCredentialProvider if this is unset.")
private String credsFile;

@CommandLine.Option(
names = {"-p", "--credsProfile"},
description = "Profile to use from creds file",
description = "Profile to use from creds file; Neglected when credsFile is unset.",
defaultValue = "default")
private String credsProfile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ public class RestoreIncrementalCommand implements Callable<Integer> {

@CommandLine.Option(
names = {"-c", "--credsFile"},
description = "File holding AWS credentials, uses default locations if not set")
description =
"File holding AWS credentials, uses default locations if not set; Will use DefaultCredentialProvider if this is unset.")
private String credsFile;

@CommandLine.Option(
names = {"-p", "--credsProfile"},
description = "Profile to use from creds file",
description = "Profile to use from creds file; Neglected when credsFile is unset.",
defaultValue = "default")
private String credsProfile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ public class SnapshotIncrementalCommand implements Callable<Integer> {

@CommandLine.Option(
names = {"-c", "--credsFile"},
description = "File holding AWS credentials, uses default locations if not set")
description =
"File holding AWS credentials, uses default locations if not set; Will use DefaultCredentialProvider if this is unset.")
private String credsFile;

@CommandLine.Option(
names = {"-p", "--credsProfile"},
description = "Profile to use from creds file",
description = "Profile to use from creds file; Neglected when credsFile is unset.",
defaultValue = "default")
private String credsProfile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ public class GetRemoteStateCommand implements Callable<Integer> {

@CommandLine.Option(
names = {"-c", "--credsFile"},
description = "File holding AWS credentials, uses default locations if not set")
description =
"File holding AWS credentials, uses default locations if not set; Will use DefaultCredentialProvider if this is unset.")
private String credsFile;

@CommandLine.Option(
names = {"-p", "--credsProfile"},
description = "Profile to use from creds file",
description = "Profile to use from creds file; Neglected when credsFile is unset.",
defaultValue = "default")
private String credsProfile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ public class PutRemoteStateCommand implements Callable<Integer> {

@CommandLine.Option(
names = {"-c", "--credsFile"},
description = "File holding AWS credentials, uses default locations if not set")
description =
"File holding AWS credentials, uses default locations if not set; Will use DefaultCredentialProvider if this is unset.")
private String credsFile;

@CommandLine.Option(
names = {"-p", "--credsProfile"},
description = "Profile to use from creds file",
description = "Profile to use from creds file; Neglected when credsFile is unset.",
defaultValue = "default")
private String credsProfile;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.auth.profile.ProfilesConfigFile;
import com.amazonaws.client.builder.AwsClientBuilder;
Expand Down Expand Up @@ -67,13 +68,14 @@ private StateCommandUtils() {}
*/
public static AmazonS3 createS3Client(
String bucketName, String region, String credsFile, String credsProfile, int maxRetry) {
ProfilesConfigFile profilesConfigFile = null;
AWSCredentialsProvider awsCredentialsProvider;
if (credsFile != null) {
Path botoCfgPath = Paths.get(credsFile);
profilesConfigFile = new ProfilesConfigFile(botoCfgPath.toFile());
ProfilesConfigFile profilesConfigFile = new ProfilesConfigFile(botoCfgPath.toFile());
awsCredentialsProvider = new ProfileCredentialsProvider(profilesConfigFile, credsProfile);
} else {
awsCredentialsProvider = new DefaultAWSCredentialsProviderChain();
}
AWSCredentialsProvider awsCredentialsProvider =
new ProfileCredentialsProvider(profilesConfigFile, credsProfile);

String clientRegion;
if (region == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ public class UpdateGlobalIndexStateCommand implements Callable<Integer> {

@CommandLine.Option(
names = {"-c", "--credsFile"},
description = "File holding AWS credentials, uses default locations if not set")
description =
"File holding AWS credentials, uses default locations if not set; Will use DefaultCredentialProvider if this is unset.")
private String credsFile;

@CommandLine.Option(
names = {"-p", "--credsProfile"},
description = "Profile to use from creds file",
description = "Profile to use from creds file; Neglected when credsFile is unset.",
defaultValue = "default")
private String credsProfile;

Expand Down

0 comments on commit 1e1129e

Please sign in to comment.