You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@asterixdb.apache.org by AsterixDB Code Review <do...@asterix-gerrit.ics.uci.edu> on 2023/07/31 14:22:13 UTC

Change in asterixdb[master]: testing default credentials behavior

From Hussain Towaileb <hu...@gmail.com>:

Hussain Towaileb has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17683 )


Change subject: testing default credentials behavior
......................................................................

testing default credentials behavior

Change-Id: I5123e837cddc195511fd97219ba68bc8c0190d5c
---
M asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/aws/s3/S3Utils.java
1 file changed, 59 insertions(+), 49 deletions(-)



  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/83/17683/1

diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/aws/s3/S3Utils.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/aws/s3/S3Utils.java
index 6775bf12b..d4599d4 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/aws/s3/S3Utils.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/util/aws/s3/S3Utils.java
@@ -52,6 +52,7 @@
 import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
 import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
 import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
 import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider;
 import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
 import software.amazon.awssdk.core.exception.SdkException;
@@ -96,56 +97,56 @@
         // Credentials
         AwsCredentialsProvider credentialsProvider;
 
-        // nothing provided, anonymous authentication
-        if (instanceProfile == null && accessKeyId == null && secretAccessKey == null && sessionToken == null) {
-            credentialsProvider = AnonymousCredentialsProvider.create();
-        } else if (instanceProfile != null) {
+//        // nothing provided, anonymous authentication
+//        if (instanceProfile == null && accessKeyId == null && secretAccessKey == null && sessionToken == null) {
+//            credentialsProvider = AnonymousCredentialsProvider.create();
+//        } else if (instanceProfile != null) {
+//
+//            // only "true" value is allowed
+//            if (!instanceProfile.equalsIgnoreCase("true")) {
+//                throw new CompilationException(INVALID_PARAM_VALUE_ALLOWED_VALUE, INSTANCE_PROFILE_FIELD_NAME, "true");
+//            }
+//
+//            // no other authentication parameters are allowed
+//            if (accessKeyId != null) {
+//                throw new CompilationException(PARAM_NOT_ALLOWED_IF_PARAM_IS_PRESENT, ACCESS_KEY_ID_FIELD_NAME,
+//                        INSTANCE_PROFILE_FIELD_NAME);
+//            }
+//            if (secretAccessKey != null) {
+//                throw new CompilationException(PARAM_NOT_ALLOWED_IF_PARAM_IS_PRESENT, SECRET_ACCESS_KEY_FIELD_NAME,
+//                        INSTANCE_PROFILE_FIELD_NAME);
+//            }
+//            if (sessionToken != null) {
+//                throw new CompilationException(PARAM_NOT_ALLOWED_IF_PARAM_IS_PRESENT, SESSION_TOKEN_FIELD_NAME,
+//                        INSTANCE_PROFILE_FIELD_NAME);
+//            }
+//            credentialsProvider = InstanceProfileCredentialsProvider.create();
+//        } else if (accessKeyId != null || secretAccessKey != null) {
+//            // accessKeyId authentication
+//            if (accessKeyId == null) {
+//                throw new CompilationException(REQUIRED_PARAM_IF_PARAM_IS_PRESENT, ACCESS_KEY_ID_FIELD_NAME,
+//                        SECRET_ACCESS_KEY_FIELD_NAME);
+//            }
+//            if (secretAccessKey == null) {
+//                throw new CompilationException(REQUIRED_PARAM_IF_PARAM_IS_PRESENT, SECRET_ACCESS_KEY_FIELD_NAME,
+//                        ACCESS_KEY_ID_FIELD_NAME);
+//            }
+//
+//            // use session token if provided
+//            if (sessionToken != null) {
+//                credentialsProvider = StaticCredentialsProvider
+//                        .create(AwsSessionCredentials.create(accessKeyId, secretAccessKey, sessionToken));
+//            } else {
+//                credentialsProvider =
+//                        StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKeyId, secretAccessKey));
+//            }
+//        } else {
+//            // if only session token is provided, accessKeyId is required
+//            throw new CompilationException(REQUIRED_PARAM_IF_PARAM_IS_PRESENT, ACCESS_KEY_ID_FIELD_NAME,
+//                    SESSION_TOKEN_FIELD_NAME);
+//        }
 
-            // only "true" value is allowed
-            if (!instanceProfile.equalsIgnoreCase("true")) {
-                throw new CompilationException(INVALID_PARAM_VALUE_ALLOWED_VALUE, INSTANCE_PROFILE_FIELD_NAME, "true");
-            }
-
-            // no other authentication parameters are allowed
-            if (accessKeyId != null) {
-                throw new CompilationException(PARAM_NOT_ALLOWED_IF_PARAM_IS_PRESENT, ACCESS_KEY_ID_FIELD_NAME,
-                        INSTANCE_PROFILE_FIELD_NAME);
-            }
-            if (secretAccessKey != null) {
-                throw new CompilationException(PARAM_NOT_ALLOWED_IF_PARAM_IS_PRESENT, SECRET_ACCESS_KEY_FIELD_NAME,
-                        INSTANCE_PROFILE_FIELD_NAME);
-            }
-            if (sessionToken != null) {
-                throw new CompilationException(PARAM_NOT_ALLOWED_IF_PARAM_IS_PRESENT, SESSION_TOKEN_FIELD_NAME,
-                        INSTANCE_PROFILE_FIELD_NAME);
-            }
-            credentialsProvider = InstanceProfileCredentialsProvider.create();
-        } else if (accessKeyId != null || secretAccessKey != null) {
-            // accessKeyId authentication
-            if (accessKeyId == null) {
-                throw new CompilationException(REQUIRED_PARAM_IF_PARAM_IS_PRESENT, ACCESS_KEY_ID_FIELD_NAME,
-                        SECRET_ACCESS_KEY_FIELD_NAME);
-            }
-            if (secretAccessKey == null) {
-                throw new CompilationException(REQUIRED_PARAM_IF_PARAM_IS_PRESENT, SECRET_ACCESS_KEY_FIELD_NAME,
-                        ACCESS_KEY_ID_FIELD_NAME);
-            }
-
-            // use session token if provided
-            if (sessionToken != null) {
-                credentialsProvider = StaticCredentialsProvider
-                        .create(AwsSessionCredentials.create(accessKeyId, secretAccessKey, sessionToken));
-            } else {
-                credentialsProvider =
-                        StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKeyId, secretAccessKey));
-            }
-        } else {
-            // if only session token is provided, accessKeyId is required
-            throw new CompilationException(REQUIRED_PARAM_IF_PARAM_IS_PRESENT, ACCESS_KEY_ID_FIELD_NAME,
-                    SESSION_TOKEN_FIELD_NAME);
-        }
-
-        builder.credentialsProvider(credentialsProvider);
+        builder.credentialsProvider(DefaultCredentialsProvider.create());
 
         // Validate the region
         List<Region> regions = S3Client.serviceMetadata().regions();

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17683
To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Change-Id: I5123e837cddc195511fd97219ba68bc8c0190d5c
Gerrit-Change-Number: 17683
Gerrit-PatchSet: 1
Gerrit-Owner: Hussain Towaileb <hu...@gmail.com>
Gerrit-MessageType: newchange