This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.8.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.8.x by this push:
new 8a93f26d376 CAMEL-21316: camel-jbang - Export with k8s secret does not
include camel-kubernetes (#15840)
8a93f26d376 is described below
commit 8a93f26d37694d04ddead004c14263222ba2ccff
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Oct 4 13:37:22 2024 +0200
CAMEL-21316: camel-jbang - Export with k8s secret does not include
camel-kubernetes (#15840)
---
.../camel/dsl/jbang/core/commands/ExportTest.java | 26 ++++++++++++++++++++++
.../src/test/resources/k8s-secret.yaml | 23 +++++++++++++++++++
.../java/org/apache/camel/main/KameletMain.java | 16 +++++--------
...ndencyDownloaderPropertiesFunctionResolver.java | 5 ++---
.../main/download/ExportPropertiesParser.java | 15 +++++++++++++
5 files changed, 71 insertions(+), 14 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
index df6c33adde2..694187f243d 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/ExportTest.java
@@ -207,6 +207,32 @@ class ExportTest {
Assertions.assertTrue(f.exists());
}
+ @ParameterizedTest
+ @MethodSource("runtimeProvider")
+ public void shouldExportSecret(RuntimeType rt) throws Exception {
+ Export command = createCommand(rt,
+ new String[] { "src/test/resources/k8s-secret.yaml" },
+ "--gav=examples:route:1.0.0", "--dir=" + workingDir,
"--quiet");
+ int exit = command.doCall();
+
+ Assertions.assertEquals(0, exit);
+ Model model = readMavenModel();
+ Assertions.assertEquals("examples", model.getGroupId());
+ Assertions.assertEquals("route", model.getArtifactId());
+ Assertions.assertEquals("1.0.0", model.getVersion());
+
+ if (rt == RuntimeType.main) {
+ Assertions.assertTrue(containsDependency(model.getDependencies(),
"org.apache.camel", "camel-kubernetes", null));
+ } else if (rt == RuntimeType.springBoot) {
+ Assertions.assertTrue(
+ containsDependency(model.getDependencies(),
"org.apache.camel.springboot", "camel-kubernetes-starter",
+ null));
+ } else if (rt == RuntimeType.quarkus) {
+ Assertions.assertTrue(
+ containsDependency(model.getDependencies(),
"org.apache.camel.quarkus", "camel-quarkus-kubernetes", null));
+ }
+ }
+
private Model readMavenModel() throws Exception {
File f = workingDir.toPath().resolve("pom.xml").toFile();
Assertions.assertTrue(f.isFile(), "Not a pom.xml file: " + f);
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/resources/k8s-secret.yaml
b/dsl/camel-jbang/camel-jbang-core/src/test/resources/k8s-secret.yaml
new file mode 100644
index 00000000000..d7d48a60068
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/resources/k8s-secret.yaml
@@ -0,0 +1,23 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+- from:
+ uri: timer:tick
+ steps:
+ - setBody:
+ constant: "{{secret:custom-secrets/kafka.username}}"
+ - to: log:info
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index f7ed06aa653..264b2b5316e 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -411,7 +411,8 @@ public class KameletMain extends MainCommandLineSupport {
addInitialProperty("camel.component.properties.ignore-missing-property",
"true");
addInitialProperty("camel.component.properties.ignore-missing-location",
"true");
PropertiesComponent pc = (PropertiesComponent)
answer.getPropertiesComponent();
- pc.setPropertiesParser(new ExportPropertiesParser());
+ pc.setPropertiesParser(new ExportPropertiesParser(answer));
+ pc.setPropertiesFunctionResolver(new
DependencyDownloaderPropertiesFunctionResolver(answer, export));
// override default type converters with our export converter that
is more flexible during exporting
ExportTypeConverter ec = new ExportTypeConverter();
@@ -423,6 +424,9 @@ public class KameletMain extends MainCommandLineSupport {
answer.getTypeConverterRegistry().addTypeConverter(Byte.class,
String.class, ec);
answer.getTypeConverterRegistry().addTypeConverter(Boolean.class,
String.class, ec);
answer.getTypeConverterRegistry().addFallbackTypeConverter(ec,
false);
+ } else {
+ PropertiesComponent pc = (PropertiesComponent)
answer.getPropertiesComponent();
+ pc.setPropertiesFunctionResolver(new
DependencyDownloaderPropertiesFunctionResolver(answer, false));
}
boolean prompt =
"true".equals(getInitialProperties().get("camel.jbang.prompt"));
@@ -703,16 +707,6 @@ public class KameletMain extends MainCommandLineSupport {
return answer;
}
- @Override
- protected void configurePropertiesService(CamelContext camelContext)
throws Exception {
- super.configurePropertiesService(camelContext);
-
- org.apache.camel.component.properties.PropertiesComponent pc
- = (org.apache.camel.component.properties.PropertiesComponent)
camelContext.getPropertiesComponent();
- boolean export =
"true".equals(getInitialProperties().get("camel.jbang.export"));
- pc.setPropertiesFunctionResolver(new
DependencyDownloaderPropertiesFunctionResolver(camelContext, export));
- }
-
@Override
protected void autoconfigure(CamelContext camelContext) throws Exception {
ClassLoader cl = createApplicationContextClassLoader(camelContext);
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesFunctionResolver.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesFunctionResolver.java
index 6d52b9b001d..2766e8ef189 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesFunctionResolver.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderPropertiesFunctionResolver.java
@@ -25,18 +25,17 @@ import org.apache.camel.spi.PropertiesFunction;
*/
public class DependencyDownloaderPropertiesFunctionResolver extends
DefaultPropertiesFunctionResolver {
- private final DependencyDownloader downloader;
private final boolean export;
public DependencyDownloaderPropertiesFunctionResolver(CamelContext
camelContext, boolean export) {
super();
setCamelContext(camelContext);
this.export = export;
- this.downloader =
getCamelContext().hasService(DependencyDownloader.class);
}
@Override
public PropertiesFunction resolvePropertiesFunction(String name) {
+ DependencyDownloader downloader =
getCamelContext().hasService(DependencyDownloader.class);
if ("base64".equals(name)) {
if (downloader != null &&
!downloader.alreadyOnClasspath("org.apache.camel", "camel-base64",
getCamelContext().getVersion())) {
@@ -123,6 +122,6 @@ public class DependencyDownloaderPropertiesFunctionResolver
extends DefaultPrope
public boolean optional(String remainder) {
return true;
}
-
}
+
}
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/ExportPropertiesParser.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/ExportPropertiesParser.java
index 941e013744b..b63eafe070b 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/ExportPropertiesParser.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/ExportPropertiesParser.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.main.download;
+import org.apache.camel.CamelContext;
import org.apache.camel.component.properties.DefaultPropertiesParser;
import org.apache.camel.component.properties.PropertiesLookup;
import org.apache.camel.support.component.PropertyConfigurerSupport;
@@ -26,9 +27,23 @@ import
org.apache.camel.support.component.PropertyConfigurerSupport;
*/
public class ExportPropertiesParser extends DefaultPropertiesParser {
+ private final CamelContext camelContext;
+
+ public ExportPropertiesParser(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
@Override
public String parseProperty(String key, String value, PropertiesLookup
properties) {
if (value == null) {
+ // the key may refer to a properties function so make sure we
include this during export
+ if (key != null) {
+ try {
+
camelContext.getPropertiesComponent().getPropertiesFunction(key);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
return PropertyConfigurerSupport.MAGIC_VALUE;
}
return value;