You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/08/07 11:23:52 UTC

[camel-kafka-connector] branch secret-raw created (now f654f09)

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

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


      at f654f09  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 f654f09  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 1 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/01: 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 da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f654f09a116eda8c53ff2a58521021e3be86d58d
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 e536120..4ac2672 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();
+    }
+
 }