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:37 UTC
[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.
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();
+ }
+
}