From 1e1129ed5f80f9b6aa00734684775df7f60c012a Mon Sep 17 00:00:00 2001 From: waziqi Date: Wed, 27 Dec 2023 14:33:44 -0500 Subject: [PATCH] nrt_utils support defaultCredentialsProvider --- .../incremental/DeleteIncrementalSnapshotsCommand.java | 5 +++-- .../incremental/IncrementalDataCleanupCommand.java | 5 +++-- .../incremental/ListIncrementalSnapshotsCommand.java | 5 +++-- .../incremental/RestoreIncrementalCommand.java | 5 +++-- .../incremental/SnapshotIncrementalCommand.java | 5 +++-- .../tools/nrt_utils/state/GetRemoteStateCommand.java | 5 +++-- .../tools/nrt_utils/state/PutRemoteStateCommand.java | 5 +++-- .../tools/nrt_utils/state/StateCommandUtils.java | 10 ++++++---- .../nrt_utils/state/UpdateGlobalIndexStateCommand.java | 5 +++-- 9 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/DeleteIncrementalSnapshotsCommand.java b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/DeleteIncrementalSnapshotsCommand.java index 7f0279b94..a4911f0c0 100644 --- a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/DeleteIncrementalSnapshotsCommand.java +++ b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/DeleteIncrementalSnapshotsCommand.java @@ -69,12 +69,13 @@ public class DeleteIncrementalSnapshotsCommand implements Callable { @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; diff --git a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/IncrementalDataCleanupCommand.java b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/IncrementalDataCleanupCommand.java index 54a1d6e0c..26fbffd9d 100644 --- a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/IncrementalDataCleanupCommand.java +++ b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/IncrementalDataCleanupCommand.java @@ -70,12 +70,13 @@ public class IncrementalDataCleanupCommand implements Callable { @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; diff --git a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/ListIncrementalSnapshotsCommand.java b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/ListIncrementalSnapshotsCommand.java index cb42c93b7..9b0dc2d01 100644 --- a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/ListIncrementalSnapshotsCommand.java +++ b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/ListIncrementalSnapshotsCommand.java @@ -54,12 +54,13 @@ public class ListIncrementalSnapshotsCommand implements Callable { @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; diff --git a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/RestoreIncrementalCommand.java b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/RestoreIncrementalCommand.java index a01128f65..4da1053ae 100644 --- a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/RestoreIncrementalCommand.java +++ b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/RestoreIncrementalCommand.java @@ -78,12 +78,13 @@ public class RestoreIncrementalCommand implements Callable { @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; diff --git a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/SnapshotIncrementalCommand.java b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/SnapshotIncrementalCommand.java index 1fb650d01..3a0fcfd7e 100644 --- a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/SnapshotIncrementalCommand.java +++ b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/incremental/SnapshotIncrementalCommand.java @@ -74,12 +74,13 @@ public class SnapshotIncrementalCommand implements Callable { @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; diff --git a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/GetRemoteStateCommand.java b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/GetRemoteStateCommand.java index e2d2e97cd..c3eaee52c 100644 --- a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/GetRemoteStateCommand.java +++ b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/GetRemoteStateCommand.java @@ -59,12 +59,13 @@ public class GetRemoteStateCommand implements Callable { @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; diff --git a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/PutRemoteStateCommand.java b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/PutRemoteStateCommand.java index 096afb62e..ee2dd35b3 100644 --- a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/PutRemoteStateCommand.java +++ b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/PutRemoteStateCommand.java @@ -60,12 +60,13 @@ public class PutRemoteStateCommand implements Callable { @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; diff --git a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/StateCommandUtils.java b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/StateCommandUtils.java index 50a388da2..14b9c3716 100644 --- a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/StateCommandUtils.java +++ b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/StateCommandUtils.java @@ -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; @@ -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) { diff --git a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/UpdateGlobalIndexStateCommand.java b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/UpdateGlobalIndexStateCommand.java index 3eb3a9781..c754687ec 100644 --- a/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/UpdateGlobalIndexStateCommand.java +++ b/src/main/java/com/yelp/nrtsearch/tools/nrt_utils/state/UpdateGlobalIndexStateCommand.java @@ -59,12 +59,13 @@ public class UpdateGlobalIndexStateCommand implements Callable { @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;