You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2022/05/10 11:32:24 UTC

[camel] 02/03: Camel-AWS2 S3: Little refactoring for multipart upload

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 09b98c7ecee690caa27d0c4305453b91d92e8469
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue May 10 13:12:09 2022 +0200

    Camel-AWS2 S3: Little refactoring for multipart upload
---
 .../camel/component/aws2/s3/AWS2S3Producer.java    | 21 +-----------------
 .../aws2/s3/stream/AWS2S3StreamUploadProducer.java | 21 +-----------------
 .../camel/component/aws2/s3/utils/AWS2S3Utils.java | 25 ++++++++++++++++++++++
 3 files changed, 27 insertions(+), 40 deletions(-)

diff --git a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
index ab99e7ccbca..c039132edb7 100644
--- a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
+++ b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
@@ -177,26 +177,7 @@ public class AWS2S3Producer extends DefaultProducer {
             createMultipartUploadRequest.contentType(contentType);
         }
 
-        if (getConfiguration().isUseAwsKMS()) {
-            createMultipartUploadRequest.ssekmsKeyId(getConfiguration().getAwsKMSKeyId());
-            createMultipartUploadRequest.serverSideEncryption(ServerSideEncryption.AWS_KMS);
-        }
-
-        if (getConfiguration().isUseSSES3()) {
-            createMultipartUploadRequest.serverSideEncryption(ServerSideEncryption.AES256);
-        }
-
-        if (getConfiguration().isUseCustomerKey()) {
-            if (ObjectHelper.isNotEmpty(getConfiguration().getCustomerKeyId())) {
-                createMultipartUploadRequest.sseCustomerKey(getConfiguration().getCustomerKeyId());
-            }
-            if (ObjectHelper.isNotEmpty(getConfiguration().getCustomerKeyMD5())) {
-                createMultipartUploadRequest.sseCustomerKeyMD5(getConfiguration().getCustomerKeyMD5());
-            }
-            if (ObjectHelper.isNotEmpty(getConfiguration().getCustomerAlgorithm())) {
-                createMultipartUploadRequest.sseCustomerAlgorithm(getConfiguration().getCustomerAlgorithm());
-            }
-        }
+        AWS2S3Utils.setEncryption(createMultipartUploadRequest, getConfiguration());
 
         LOG.trace("Initiating multipart upload [{}] from exchange [{}]...", createMultipartUploadRequest, exchange);
 
diff --git a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/stream/AWS2S3StreamUploadProducer.java b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/stream/AWS2S3StreamUploadProducer.java
index 8c3bdf42a05..2b0d40b0f09 100644
--- a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/stream/AWS2S3StreamUploadProducer.java
+++ b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/stream/AWS2S3StreamUploadProducer.java
@@ -165,26 +165,7 @@ public class AWS2S3StreamUploadProducer extends DefaultProducer {
             createMultipartUploadRequest.acl(acl.toString());
         }
 
-        if (getConfiguration().isUseAwsKMS()) {
-            createMultipartUploadRequest.ssekmsKeyId(getConfiguration().getAwsKMSKeyId());
-            createMultipartUploadRequest.serverSideEncryption(ServerSideEncryption.AWS_KMS);
-        }
-
-        if (getConfiguration().isUseSSES3()) {
-            createMultipartUploadRequest.serverSideEncryption(ServerSideEncryption.AES256);
-        }
-
-        if (getConfiguration().isUseCustomerKey()) {
-            if (ObjectHelper.isNotEmpty(getConfiguration().getCustomerKeyId())) {
-                createMultipartUploadRequest.sseCustomerKey(getConfiguration().getCustomerKeyId());
-            }
-            if (ObjectHelper.isNotEmpty(getConfiguration().getCustomerKeyMD5())) {
-                createMultipartUploadRequest.sseCustomerKeyMD5(getConfiguration().getCustomerKeyMD5());
-            }
-            if (ObjectHelper.isNotEmpty(getConfiguration().getCustomerAlgorithm())) {
-                createMultipartUploadRequest.sseCustomerAlgorithm(getConfiguration().getCustomerAlgorithm());
-            }
-        }
+        AWS2S3Utils.setEncryption(createMultipartUploadRequest, getConfiguration());
 
         LOG.trace("Initiating multipart upload [{}] from exchange [{}]...", createMultipartUploadRequest, exchange);
         if (index.get() == 1) {
diff --git a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/utils/AWS2S3Utils.java b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/utils/AWS2S3Utils.java
index 342bb145d60..2b7ac13121f 100644
--- a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/utils/AWS2S3Utils.java
+++ b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/utils/AWS2S3Utils.java
@@ -25,6 +25,8 @@ import org.apache.camel.StreamCache;
 import org.apache.camel.component.aws2.s3.AWS2S3Configuration;
 import org.apache.camel.component.aws2.s3.AWS2S3Constants;
 import org.apache.camel.util.ObjectHelper;
+import software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest;
+import software.amazon.awssdk.services.s3.model.ServerSideEncryption;
 
 public final class AWS2S3Utils {
 
@@ -120,4 +122,27 @@ public final class AWS2S3Utils {
         }
         return key;
     }
+
+    public static void setEncryption(CreateMultipartUploadRequest.Builder createMultipartUploadRequest, AWS2S3Configuration configuration) {
+        if (configuration.isUseAwsKMS()) {
+            createMultipartUploadRequest.ssekmsKeyId(configuration.getAwsKMSKeyId());
+            createMultipartUploadRequest.serverSideEncryption(ServerSideEncryption.AWS_KMS);
+        }
+
+        if (configuration.isUseSSES3()) {
+            createMultipartUploadRequest.serverSideEncryption(ServerSideEncryption.AES256);
+        }
+
+        if (configuration.isUseCustomerKey()) {
+            if (ObjectHelper.isNotEmpty(configuration.getCustomerKeyId())) {
+                createMultipartUploadRequest.sseCustomerKey(configuration.getCustomerKeyId());
+            }
+            if (ObjectHelper.isNotEmpty(configuration.getCustomerKeyMD5())) {
+                createMultipartUploadRequest.sseCustomerKeyMD5(configuration.getCustomerKeyMD5());
+            }
+            if (ObjectHelper.isNotEmpty(configuration.getCustomerAlgorithm())) {
+                createMultipartUploadRequest.sseCustomerAlgorithm(configuration.getCustomerAlgorithm());
+            }
+        }
+    }
 }