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 2020/08/12 15:22:36 UTC

[camel-kafka-connector] branch backport-raw-fixes created (now 1d4fdbe)

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

acosentino pushed a change to branch backport-raw-fixes
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector.git.


      at 1d4fdbe  Building endpoint uris should for secret options automatic use RAW() syntax for the value so we wont have encoding issue for passwords or access tokens etc.

This branch includes the following new commits:

     new b7650bb  Building endpoint uris should for secret options automatic use RAW() syntax for the value so we wont have encoding issue for passwords or access tokens etc.
     new 1d4fdbe  Building endpoint uris should for secret options automatic use RAW() syntax for the value so we wont have encoding issue for passwords or access tokens etc.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel-kafka-connector] 01/02: Building endpoint uris should for secret options automatic use RAW() syntax for the value so we wont have encoding issue for passwords or access tokens etc.

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch backport-raw-fixes
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector.git

commit b7650bbaf3b7b2d55e196b1686b9ca4653d73b75
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Aug 7 13:12:01 2020 +0200

    Building endpoint uris should for secret options automatic use RAW() syntax for the value so we wont have encoding issue for passwords or access tokens etc.
---
 core/pom.xml                                       |  5 ++++
 .../camel/kafkaconnector/utils/TaskHelper.java     | 32 ++++++++++++++++++++++
 .../camel/kafkaconnector/CamelSinkTaskTest.java    | 14 ++++++++++
 3 files changed, 51 insertions(+)

diff --git a/core/pom.xml b/core/pom.xml
index 6d3fdd5..a5084dc 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -136,6 +136,11 @@
             <artifactId>camel-cassandraql</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-aws2-sqs</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/core/src/main/java/org/apache/camel/kafkaconnector/utils/TaskHelper.java b/core/src/main/java/org/apache/camel/kafkaconnector/utils/TaskHelper.java
index 672f13b..321fd8d 100644
--- a/core/src/main/java/org/apache/camel/kafkaconnector/utils/TaskHelper.java
+++ b/core/src/main/java/org/apache/camel/kafkaconnector/utils/TaskHelper.java
@@ -26,6 +26,9 @@ import org.apache.camel.LoggingLevel;
 import org.apache.camel.catalog.RuntimeCamelCatalog;
 import org.apache.camel.kafkaconnector.CamelSinkConnectorConfig;
 import org.apache.camel.kafkaconnector.CamelSourceConnectorConfig;
+import org.apache.camel.tooling.model.BaseOptionModel;
+import org.apache.camel.tooling.model.ComponentModel;
+import org.apache.camel.tooling.model.JsonMapper;
 import org.apache.kafka.common.config.AbstractConfig;
 import org.apache.kafka.connect.connector.ConnectRecord;
 import org.apache.kafka.connect.source.SourceRecord;
@@ -37,10 +40,32 @@ public final class TaskHelper {
     }
 
     public static String buildUrl(RuntimeCamelCatalog rcc, Map<String, String> props, String componentSchema, String endpointPropertiesPrefix, String pathPropertiesPrefix) throws URISyntaxException {
+        ComponentModel cm = null;
+        if (componentSchema != null) {
+            String json = rcc.componentJSonSchema(componentSchema);
+            if (json != null) {
+                cm = JsonMapper.generateComponentModel(json);
+            }
+        }
+
         Map<String, String> filteredProps = new HashMap<>();
         props.keySet().stream()
                 .filter(k -> k.startsWith(endpointPropertiesPrefix) || k.startsWith(pathPropertiesPrefix))
                 .forEach(k -> filteredProps.put(k.replace(endpointPropertiesPrefix, "").replace(pathPropertiesPrefix, ""), props.get(k)));
+
+        if (cm != null) {
+            // secret options should have their values in RAW mode so we can preseve credentials/passwords etc in uri encodings
+            for (String k : filteredProps.keySet()) {
+                if (isSecretOption(rcc, cm, k)) {
+                    String value = filteredProps.get(k);
+                    if (value != null && !value.startsWith("RAW(")) {
+                        value = "RAW(" + value + ")";
+                        filteredProps.put(k, value);
+                    }
+                }
+            }
+        }
+
         return rcc.asEndpointUri(componentSchema, filteredProps, false);
     }
 
@@ -135,4 +160,11 @@ public final class TaskHelper {
         }
     }
 
+    private static boolean isSecretOption(RuntimeCamelCatalog rcc, ComponentModel cm, String endpointName) {
+        return cm.getEndpointOptions().stream()
+                .filter(o -> o.getName().equals(endpointName))
+                .findFirst()
+                .map(BaseOptionModel::isSecret).orElse(false);
+    }
+
 }
diff --git a/core/src/test/java/org/apache/camel/kafkaconnector/CamelSinkTaskTest.java b/core/src/test/java/org/apache/camel/kafkaconnector/CamelSinkTaskTest.java
index dd82ff6..b9af651 100644
--- a/core/src/test/java/org/apache/camel/kafkaconnector/CamelSinkTaskTest.java
+++ b/core/src/test/java/org/apache/camel/kafkaconnector/CamelSinkTaskTest.java
@@ -632,4 +632,18 @@ public class CamelSinkTaskTest {
         sinkTask.stop();
     }
 
+    @Test
+    public void testSecretRaw() {
+        Map<String, String> props = new HashMap<>();
+        props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME);
+        props.put("camel.sink.endpoint.secretKey", "se+ret");
+        props.put("camel.sink.endpoint.accessKey", "MoreSe+ret$");
+        props.put(CamelSinkConnectorConfig.CAMEL_SINK_COMPONENT_CONF, "aws2-sqs");
+
+        CamelSinkTask sinkTask = new CamelSinkTask();
+        sinkTask.start(props);
+
+        sinkTask.stop();
+    }
+
 }


[camel-kafka-connector] 02/02: Building endpoint uris should for secret options automatic use RAW() syntax for the value so we wont have encoding issue for passwords or access tokens etc.

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch backport-raw-fixes
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector.git

commit 1d4fdbee5b1c96fe9e824d36e12960523be30fff
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Aug 10 14:20:17 2020 +0200

    Building endpoint uris should for secret options automatic use RAW() syntax for the value so we wont have encoding issue for passwords or access tokens etc.
---
 .../org/apache/camel/kafkaconnector/utils/TaskHelper.java |  2 +-
 .../apache/camel/kafkaconnector/CamelSinkTaskTest.java    | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/camel/kafkaconnector/utils/TaskHelper.java b/core/src/main/java/org/apache/camel/kafkaconnector/utils/TaskHelper.java
index 321fd8d..6fbeb20 100644
--- a/core/src/main/java/org/apache/camel/kafkaconnector/utils/TaskHelper.java
+++ b/core/src/main/java/org/apache/camel/kafkaconnector/utils/TaskHelper.java
@@ -58,7 +58,7 @@ public final class TaskHelper {
             for (String k : filteredProps.keySet()) {
                 if (isSecretOption(rcc, cm, k)) {
                     String value = filteredProps.get(k);
-                    if (value != null && !value.startsWith("RAW(")) {
+                    if (value != null && !value.startsWith("#") && !value.startsWith("RAW(")) {
                         value = "RAW(" + value + ")";
                         filteredProps.put(k, value);
                     }
diff --git a/core/src/test/java/org/apache/camel/kafkaconnector/CamelSinkTaskTest.java b/core/src/test/java/org/apache/camel/kafkaconnector/CamelSinkTaskTest.java
index b9af651..f4bb812 100644
--- a/core/src/test/java/org/apache/camel/kafkaconnector/CamelSinkTaskTest.java
+++ b/core/src/test/java/org/apache/camel/kafkaconnector/CamelSinkTaskTest.java
@@ -646,4 +646,19 @@ public class CamelSinkTaskTest {
         sinkTask.stop();
     }
 
+    @Test
+    public void testSecretRawReference() {
+        Map<String, String> props = new HashMap<>();
+        props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME);
+        props.put("camel.sink.endpoint.secretKey", "#bean:mySecretKey");
+        props.put("camel.sink.endpoint.accessKey", "#property:myAccessKey");
+        props.put(CamelSinkConnectorConfig.CAMEL_SINK_COMPONENT_CONF, "aws2-sqs");
+        props.put("myAccessKey", "MoreSe+ret$");
+
+        CamelSinkTask sinkTask = new CamelSinkTask();
+        sinkTask.start(props);
+
+        sinkTask.stop();
+    }
+
 }