This is an automated email from the ASF dual-hosted git repository.
htowaileb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push:
new 879e6cf7de [NO ISSUE][OTH] Refactor S3Utils.buildAwsS3Client function
879e6cf7de is described below
commit 879e6cf7ded5aeff06fea57db71183a4198f950a
Author: Peeyush Gupta <[email protected]>
AuthorDate: Mon Mar 11 12:10:43 2024 -0700
[NO ISSUE][OTH] Refactor S3Utils.buildAwsS3Client function
- user model changes: no
- storage format changes: no
- interface changes: no
Change-Id: I63a40992cac3c6d5742e6a7ec3bc6721567d4349
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18198
Integration-Tests: Jenkins <[email protected]>
Tested-by: Jenkins <[email protected]>
Reviewed-by: Murtadha Hubail <[email protected]>
---
.../asterix/external/util/aws/s3/S3Utils.java | 65 ++++++++++++----------
1 file changed, 37 insertions(+), 28 deletions(-)
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 f028af3a5f..45e83b4216 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
@@ -116,6 +116,42 @@ public class S3Utils {
S3ClientBuilder builder = S3Client.builder();
+ // Credentials
+ AwsCredentialsProvider credentialsProvider =
+ buildCredentialsProvider(instanceProfile, accessKeyId,
secretAccessKey, sessionToken);
+
+ builder.credentialsProvider(credentialsProvider);
+
+ // Validate the region
+ List<Region> regions = S3Client.serviceMetadata().regions();
+ Optional<Region> selectedRegion = regions.stream().filter(region ->
region.id().equals(regionId)).findFirst();
+
+ if (selectedRegion.isEmpty()) {
+ throw new CompilationException(S3_REGION_NOT_SUPPORTED, regionId);
+ }
+ builder.region(selectedRegion.get());
+
+ // Validate the service endpoint if present
+ if (serviceEndpoint != null) {
+ try {
+ URI uri = new URI(serviceEndpoint);
+ try {
+ builder.endpointOverride(uri);
+ } catch (NullPointerException ex) {
+ throw new
CompilationException(ErrorCode.EXTERNAL_SOURCE_ERROR, ex,
getMessageOrToString(ex));
+ }
+ } catch (URISyntaxException ex) {
+ throw new
CompilationException(ErrorCode.EXTERNAL_SOURCE_ERROR, ex,
+ String.format("Invalid service endpoint %s",
serviceEndpoint));
+ }
+ }
+
+ return builder.build();
+ }
+
+ public static AwsCredentialsProvider buildCredentialsProvider(String
instanceProfile, String accessKeyId,
+ String secretAccessKey, String sessionToken) throws
CompilationException {
+
// Credentials
AwsCredentialsProvider credentialsProvider;
@@ -167,34 +203,7 @@ public class S3Utils {
throw new CompilationException(REQUIRED_PARAM_IF_PARAM_IS_PRESENT,
ACCESS_KEY_ID_FIELD_NAME,
SESSION_TOKEN_FIELD_NAME);
}
-
- builder.credentialsProvider(credentialsProvider);
-
- // Validate the region
- List<Region> regions = S3Client.serviceMetadata().regions();
- Optional<Region> selectedRegion = regions.stream().filter(region ->
region.id().equals(regionId)).findFirst();
-
- if (selectedRegion.isEmpty()) {
- throw new CompilationException(S3_REGION_NOT_SUPPORTED, regionId);
- }
- builder.region(selectedRegion.get());
-
- // Validate the service endpoint if present
- if (serviceEndpoint != null) {
- try {
- URI uri = new URI(serviceEndpoint);
- try {
- builder.endpointOverride(uri);
- } catch (NullPointerException ex) {
- throw new
CompilationException(ErrorCode.EXTERNAL_SOURCE_ERROR, ex,
getMessageOrToString(ex));
- }
- } catch (URISyntaxException ex) {
- throw new
CompilationException(ErrorCode.EXTERNAL_SOURCE_ERROR, ex,
- String.format("Invalid service endpoint %s",
serviceEndpoint));
- }
- }
-
- return builder.build();
+ return credentialsProvider;
}
/**