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 2019/05/15 14:41:32 UTC

[camel] 01/04: CAMEL-13519 - Camel-AWS SNS: Support encryption parameter when the creation of the topic is needed

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

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

commit 43df1566a2fd4a7917d41ba235af0a911de5ac6b
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed May 15 16:05:55 2019 +0200

    CAMEL-13519 - Camel-AWS SNS: Support encryption parameter when the creation of the topic is needed
---
 .../src/main/docs/aws-sns-component.adoc           |  4 +++-
 .../camel/component/aws/sns/SnsConfiguration.java  | 26 ++++++++++++++++++++++
 .../camel/component/aws/sns/SnsEndpoint.java       | 11 +++++++++
 .../sns/springboot/SnsComponentConfiguration.java  | 26 ++++++++++++++++++++++
 4 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/components/camel-aws-sns/src/main/docs/aws-sns-component.adoc b/components/camel-aws-sns/src/main/docs/aws-sns-component.adoc
index ecfafe3..656512e 100644
--- a/components/camel-aws-sns/src/main/docs/aws-sns-component.adoc
+++ b/components/camel-aws-sns/src/main/docs/aws-sns-component.adoc
@@ -67,7 +67,7 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (14 parameters):
+==== Query Parameters (16 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -76,12 +76,14 @@ with the following path and query parameters:
 | *amazonSNSClient* (producer) | To use the AmazonSNS as the client |  | AmazonSNS
 | *amazonSQSClient* (producer) | An SQS Client to use as bridge between SNS and SQS |  | AmazonSQS
 | *headerFilterStrategy* (producer) | To use a custom HeaderFilterStrategy to map headers to/from Camel. |  | HeaderFilterStrategy
+| *kmsMasterKeyId* (producer) | The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK. |  | String
 | *messageStructure* (producer) | The message structure to use such as json |  | String
 | *policy* (producer) | The policy for this queue |  | String
 | *proxyHost* (producer) | To define a proxy host when instantiating the SNS client |  | String
 | *proxyPort* (producer) | To define a proxy port when instantiating the SNS client |  | Integer
 | *queueUrl* (producer) | The queueUrl to subscribe to |  | String
 | *region* (producer) | The region in which SNS client needs to work |  | String
+| *serverSideEncryptionEnabled* (producer) | Define if Server Side Encryption is enabled or not on the topic | false | boolean
 | *subject* (producer) | The subject which is used if the message header 'CamelAwsSnsSubject' is not present. |  | String
 | *subscribeSNStoSQS* (producer) | Define if the subscription between SNS Topic and SQS must be done or not | false | boolean
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
diff --git a/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java b/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
index 1e10790..0b2ac60 100644
--- a/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
+++ b/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsConfiguration.java
@@ -46,6 +46,10 @@ public class SnsConfiguration implements Cloneable {
     private String queueUrl;
     @UriParam
     private boolean subscribeSNStoSQS;
+    @UriParam
+    private String kmsMasterKeyId;
+    @UriParam
+    private boolean serverSideEncryptionEnabled;
 
     // Producer only properties
     @UriParam
@@ -211,6 +215,28 @@ public class SnsConfiguration implements Cloneable {
         this.subscribeSNStoSQS = subscribeSNStoSQS;
     }
     
+    public String getKmsMasterKeyId() {
+        return kmsMasterKeyId;
+    }
+
+    /**
+     * The ID of an AWS-managed customer master key (CMK) for Amazon SNS or a custom CMK.
+     */
+    public void setKmsMasterKeyId(String kmsMasterKeyId) {
+        this.kmsMasterKeyId = kmsMasterKeyId;
+    }
+
+    public boolean isServerSideEncryptionEnabled() {
+        return serverSideEncryptionEnabled;
+    }
+
+    /**
+     * Define if Server Side Encryption is enabled or not on the topic
+     */
+    public void setServerSideEncryptionEnabled(boolean serverSideEncryptionEnabled) {
+        this.serverSideEncryptionEnabled = serverSideEncryptionEnabled;
+    }
+    
     // *************************************************
     //
     // *************************************************
diff --git a/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java b/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java
index cc6f757..1d960d6 100644
--- a/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java
+++ b/components/camel-aws-sns/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java
@@ -32,6 +32,9 @@ import com.amazonaws.services.sns.model.SetTopicAttributesRequest;
 import com.amazonaws.services.sns.model.Topic;
 import com.amazonaws.services.sns.util.Topics;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
@@ -121,6 +124,14 @@ public class SnsEndpoint extends DefaultEndpoint implements HeaderFilterStrategy
         if (configuration.getTopicArn() == null) {
             // creates a new topic, or returns the URL of an existing one
             CreateTopicRequest request = new CreateTopicRequest(configuration.getTopicName());
+            
+            if (configuration.isServerSideEncryptionEnabled()) {
+            	if (ObjectHelper.isNotEmpty(configuration.getKmsMasterKeyId())) {
+            	    Map<String, String> attributes = new HashMap<>();
+            	    attributes.put("KmsMasterKeyId", configuration.getKmsMasterKeyId());
+            	    request.setAttributes(attributes);
+            	}
+            }
 
             log.trace("Creating topic [{}] with request [{}]...", configuration.getTopicName(), request);
 
diff --git a/platforms/spring-boot/components-starter/camel-aws-sns-starter/src/main/java/org/apache/camel/component/aws/sns/springboot/SnsComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-sns-starter/src/main/java/org/apache/camel/component/aws/sns/springboot/SnsComponentConfiguration.java
index 8a06aac..80b9229 100644
--- a/platforms/spring-boot/components-starter/camel-aws-sns-starter/src/main/java/org/apache/camel/component/aws/sns/springboot/SnsComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-aws-sns-starter/src/main/java/org/apache/camel/component/aws/sns/springboot/SnsComponentConfiguration.java
@@ -164,6 +164,15 @@ public class SnsComponentConfiguration
          * not
          */
         private Boolean subscribeSNStoSQS = false;
+        /**
+         * The ID of an AWS-managed customer master key (CMK) for Amazon SNS or
+         * a custom CMK.
+         */
+        private String kmsMasterKeyId;
+        /**
+         * Define if Server Side Encryption is enabled or not on the topic
+         */
+        private Boolean serverSideEncryptionEnabled = false;
 
         public String getSubject() {
             return subject;
@@ -276,5 +285,22 @@ public class SnsComponentConfiguration
         public void setSubscribeSNStoSQS(Boolean subscribeSNStoSQS) {
             this.subscribeSNStoSQS = subscribeSNStoSQS;
         }
+
+        public String getKmsMasterKeyId() {
+            return kmsMasterKeyId;
+        }
+
+        public void setKmsMasterKeyId(String kmsMasterKeyId) {
+            this.kmsMasterKeyId = kmsMasterKeyId;
+        }
+
+        public Boolean getServerSideEncryptionEnabled() {
+            return serverSideEncryptionEnabled;
+        }
+
+        public void setServerSideEncryptionEnabled(
+                Boolean serverSideEncryptionEnabled) {
+            this.serverSideEncryptionEnabled = serverSideEncryptionEnabled;
+        }
     }
 }
\ No newline at end of file