This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new c5b146dc2df CAMEL-20795 - camel-nats - NATS Credential file support
(#14223)
c5b146dc2df is described below
commit c5b146dc2dfd284d677909c698956d98054d68d4
Author: Andrea Cosentino <[email protected]>
AuthorDate: Wed May 22 12:56:39 2024 +0200
CAMEL-20795 - camel-nats - NATS Credential file support (#14223)
Signed-off-by: Andrea Cosentino <[email protected]>
---
.../org/apache/camel/catalog/components/nats.json | 5 ++-
.../component/nats/NatsEndpointConfigurer.java | 6 +++
.../component/nats/NatsEndpointUriFactory.java | 3 +-
.../org/apache/camel/component/nats/nats.json | 5 ++-
.../camel/component/nats/NatsConfiguration.java | 16 +++++++
.../apache/camel/component/nats/NatsEndpoint.java | 7 +++
.../endpoint/dsl/NatsEndpointBuilderFactory.java | 51 ++++++++++++++++++++++
.../apache/camel/kotlin/components/NatsUriDsl.kt | 9 ++++
8 files changed, 97 insertions(+), 5 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/nats.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/nats.json
index 3ae2ae4049c..4c73ee13fe5 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/nats.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/nats.json
@@ -67,7 +67,8 @@
"connection": { "index": 25, "kind": "parameter", "displayName":
"Connection", "group": "advanced", "label": "advanced", "required": false,
"type": "object", "javaType": "io.nats.client.Connection", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "Reference an already instantiated connection
to Nats server" },
"headerFilterStrategy": { "index": 26, "kind": "parameter", "displayName":
"Header Filter Strategy", "group": "advanced", "label": "advanced", "required":
false, "type": "object", "javaType":
"org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "Define the header filtering strategy" },
"traceConnection": { "index": 27, "kind": "parameter", "displayName":
"Trace Connection", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.nats.NatsConfiguration",
"configurationField": "configuration", "description": "Whether or not
connection trace messages should be printed to standard out for fine [...]
- "secure": { "index": 28, "kind": "parameter", "displayName": "Secure",
"group": "security", "label": "security", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "Set secure option indicating TLS is required"
},
- "sslContextParameters": { "index": 29, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "To configure security using
SSLContextParameters" }
+ "credentialsFilePath": { "index": 28, "kind": "parameter", "displayName":
"Credentials File Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "If we use useCredentialsFile to true we'll
need to set the credentialsFilePath option. It [...]
+ "secure": { "index": 29, "kind": "parameter", "displayName": "Secure",
"group": "security", "label": "security", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "Set secure option indicating TLS is required"
},
+ "sslContextParameters": { "index": 30, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "To configure security using
SSLContextParameters" }
}
}
diff --git
a/components/camel-nats/src/generated/java/org/apache/camel/component/nats/NatsEndpointConfigurer.java
b/components/camel-nats/src/generated/java/org/apache/camel/component/nats/NatsEndpointConfigurer.java
index 1e60bd06f4a..223199a3713 100644
---
a/components/camel-nats/src/generated/java/org/apache/camel/component/nats/NatsEndpointConfigurer.java
+++
b/components/camel-nats/src/generated/java/org/apache/camel/component/nats/NatsEndpointConfigurer.java
@@ -28,6 +28,8 @@ public class NatsEndpointConfigurer extends
PropertyConfigurerSupport implements
case "connection":
target.getConfiguration().setConnection(property(camelContext,
io.nats.client.Connection.class, value)); return true;
case "connectiontimeout":
case "connectionTimeout":
target.getConfiguration().setConnectionTimeout(property(camelContext,
int.class, value)); return true;
+ case "credentialsfilepath":
+ case "credentialsFilePath":
target.getConfiguration().setCredentialsFilePath(property(camelContext,
java.lang.String.class, value)); return true;
case "exceptionhandler":
case "exceptionHandler":
target.setExceptionHandler(property(camelContext,
org.apache.camel.spi.ExceptionHandler.class, value)); return true;
case "exchangepattern":
@@ -87,6 +89,8 @@ public class NatsEndpointConfigurer extends
PropertyConfigurerSupport implements
case "connection": return io.nats.client.Connection.class;
case "connectiontimeout":
case "connectionTimeout": return int.class;
+ case "credentialsfilepath":
+ case "credentialsFilePath": return java.lang.String.class;
case "exceptionhandler":
case "exceptionHandler": return
org.apache.camel.spi.ExceptionHandler.class;
case "exchangepattern":
@@ -147,6 +151,8 @@ public class NatsEndpointConfigurer extends
PropertyConfigurerSupport implements
case "connection": return target.getConfiguration().getConnection();
case "connectiontimeout":
case "connectionTimeout": return
target.getConfiguration().getConnectionTimeout();
+ case "credentialsfilepath":
+ case "credentialsFilePath": return
target.getConfiguration().getCredentialsFilePath();
case "exceptionhandler":
case "exceptionHandler": return target.getExceptionHandler();
case "exchangepattern":
diff --git
a/components/camel-nats/src/generated/java/org/apache/camel/component/nats/NatsEndpointUriFactory.java
b/components/camel-nats/src/generated/java/org/apache/camel/component/nats/NatsEndpointUriFactory.java
index 6d61e236881..793f592a818 100644
---
a/components/camel-nats/src/generated/java/org/apache/camel/component/nats/NatsEndpointUriFactory.java
+++
b/components/camel-nats/src/generated/java/org/apache/camel/component/nats/NatsEndpointUriFactory.java
@@ -23,10 +23,11 @@ public class NatsEndpointUriFactory extends
org.apache.camel.support.component.E
private static final Set<String> SECRET_PROPERTY_NAMES;
private static final Set<String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(30);
+ Set<String> props = new HashSet<>(31);
props.add("bridgeErrorHandler");
props.add("connection");
props.add("connectionTimeout");
+ props.add("credentialsFilePath");
props.add("exceptionHandler");
props.add("exchangePattern");
props.add("flushConnection");
diff --git
a/components/camel-nats/src/generated/resources/META-INF/org/apache/camel/component/nats/nats.json
b/components/camel-nats/src/generated/resources/META-INF/org/apache/camel/component/nats/nats.json
index 3ae2ae4049c..4c73ee13fe5 100644
---
a/components/camel-nats/src/generated/resources/META-INF/org/apache/camel/component/nats/nats.json
+++
b/components/camel-nats/src/generated/resources/META-INF/org/apache/camel/component/nats/nats.json
@@ -67,7 +67,8 @@
"connection": { "index": 25, "kind": "parameter", "displayName":
"Connection", "group": "advanced", "label": "advanced", "required": false,
"type": "object", "javaType": "io.nats.client.Connection", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "Reference an already instantiated connection
to Nats server" },
"headerFilterStrategy": { "index": 26, "kind": "parameter", "displayName":
"Header Filter Strategy", "group": "advanced", "label": "advanced", "required":
false, "type": "object", "javaType":
"org.apache.camel.spi.HeaderFilterStrategy", "deprecated": false, "autowired":
false, "secret": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "Define the header filtering strategy" },
"traceConnection": { "index": 27, "kind": "parameter", "displayName":
"Trace Connection", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false,
"configurationClass": "org.apache.camel.component.nats.NatsConfiguration",
"configurationField": "configuration", "description": "Whether or not
connection trace messages should be printed to standard out for fine [...]
- "secure": { "index": 28, "kind": "parameter", "displayName": "Secure",
"group": "security", "label": "security", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "Set secure option indicating TLS is required"
},
- "sslContextParameters": { "index": 29, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "To configure security using
SSLContextParameters" }
+ "credentialsFilePath": { "index": 28, "kind": "parameter", "displayName":
"Credentials File Path", "group": "security", "label": "security", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "If we use useCredentialsFile to true we'll
need to set the credentialsFilePath option. It [...]
+ "secure": { "index": 29, "kind": "parameter", "displayName": "Secure",
"group": "security", "label": "security", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "Set secure option indicating TLS is required"
},
+ "sslContextParameters": { "index": 30, "kind": "parameter", "displayName":
"Ssl Context Parameters", "group": "security", "label": "security", "required":
false, "type": "object", "javaType":
"org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false,
"autowired": false, "secret": false, "configurationClass":
"org.apache.camel.component.nats.NatsConfiguration", "configurationField":
"configuration", "description": "To configure security using
SSLContextParameters" }
}
}
diff --git
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
index 53f185a1fb9..fcaa386a432 100644
---
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
+++
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsConfiguration.java
@@ -20,6 +20,7 @@ import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import io.nats.client.Connection;
+import io.nats.client.Nats;
import io.nats.client.Options;
import io.nats.client.Options.Builder;
import org.apache.camel.spi.HeaderFilterStrategy;
@@ -83,6 +84,8 @@ public class NatsConfiguration {
private boolean secure;
@UriParam(label = "security")
private SSLContextParameters sslContextParameters;
+ @UriParam(label = "security")
+ String credentialsFilePath;
@UriParam(label = "advanced")
private boolean traceConnection;
@UriParam(label = "advanced")
@@ -367,6 +370,19 @@ public class NatsConfiguration {
this.sslContextParameters = sslContextParameters;
}
+ /**
+ * If we use useCredentialsFile to true we'll need to set the
credentialsFilePath option. It can be loaded by
+ * default from classpath, but you can prefix with classpath:, file:, or
http: to load the resource from different
+ * systems.
+ */
+ public String getCredentialsFilePath() {
+ return credentialsFilePath;
+ }
+
+ public void setCredentialsFilePath(String credentialsFilePath) {
+ this.credentialsFilePath = credentialsFilePath;
+ }
+
public Builder createOptions() throws NoSuchAlgorithmException,
IllegalArgumentException {
Builder builder = new Options.Builder();
builder.server(splitServers());
diff --git
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsEndpoint.java
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsEndpoint.java
index 7cc24f51fa1..2edaa653b4d 100644
---
a/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsEndpoint.java
+++
b/components/camel-nats/src/main/java/org/apache/camel/component/nats/NatsEndpoint.java
@@ -36,6 +36,8 @@ import org.apache.camel.spi.HeaderFilterStrategyAware;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.util.ObjectHelper;
/**
* Send and receive messages from <a href="http://nats.io/">NATS</a> messaging
system.
@@ -85,6 +87,11 @@ public class NatsEndpoint extends DefaultEndpoint implements
MultipleConsumersSu
SSLContext sslCtx =
getConfiguration().getSslContextParameters().createSSLContext(getCamelContext());
builder.sslContext(sslCtx);
}
+ if
(ObjectHelper.isNotEmpty(getConfiguration().getCredentialsFilePath())) {
+ builder.authHandler(Nats.staticCredentials(
+ ResourceHelper.resolveResource(getCamelContext(),
getConfiguration().getCredentialsFilePath())
+ .getInputStream().readAllBytes()));
+ }
Options options = builder.build();
return Nats.connect(options);
}
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NatsEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NatsEndpointBuilderFactory.java
index c9a4fb50119..e2e3c57afef 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NatsEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/NatsEndpointBuilderFactory.java
@@ -549,6 +549,23 @@ public interface NatsEndpointBuilderFactory {
doSetProperty("replyToDisabled", replyToDisabled);
return this;
}
+ /**
+ * If we use useCredentialsFile to true we'll need to set the
+ * credentialsFilePath option. It can be loaded by default from
+ * classpath, but you can prefix with classpath:, file:, or http: to
+ * load the resource from different systems.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Group: security
+ *
+ * @param credentialsFilePath the value to set
+ * @return the dsl builder
+ */
+ default NatsEndpointConsumerBuilder credentialsFilePath(String
credentialsFilePath) {
+ doSetProperty("credentialsFilePath", credentialsFilePath);
+ return this;
+ }
/**
* Set secure option indicating TLS is required.
*
@@ -1301,6 +1318,23 @@ public interface NatsEndpointBuilderFactory {
doSetProperty("requestTimeout", requestTimeout);
return this;
}
+ /**
+ * If we use useCredentialsFile to true we'll need to set the
+ * credentialsFilePath option. It can be loaded by default from
+ * classpath, but you can prefix with classpath:, file:, or http: to
+ * load the resource from different systems.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Group: security
+ *
+ * @param credentialsFilePath the value to set
+ * @return the dsl builder
+ */
+ default NatsEndpointProducerBuilder credentialsFilePath(String
credentialsFilePath) {
+ doSetProperty("credentialsFilePath", credentialsFilePath);
+ return this;
+ }
/**
* Set secure option indicating TLS is required.
*
@@ -1938,6 +1972,23 @@ public interface NatsEndpointBuilderFactory {
doSetProperty("verbose", verbose);
return this;
}
+ /**
+ * If we use useCredentialsFile to true we'll need to set the
+ * credentialsFilePath option. It can be loaded by default from
+ * classpath, but you can prefix with classpath:, file:, or http: to
+ * load the resource from different systems.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Group: security
+ *
+ * @param credentialsFilePath the value to set
+ * @return the dsl builder
+ */
+ default NatsEndpointBuilder credentialsFilePath(String
credentialsFilePath) {
+ doSetProperty("credentialsFilePath", credentialsFilePath);
+ return this;
+ }
/**
* Set secure option indicating TLS is required.
*
diff --git
a/dsl/camel-kotlin-api/src/generated/kotlin/org/apache/camel/kotlin/components/NatsUriDsl.kt
b/dsl/camel-kotlin-api/src/generated/kotlin/org/apache/camel/kotlin/components/NatsUriDsl.kt
index e3a42a3e8be..38efa76bc27 100644
---
a/dsl/camel-kotlin-api/src/generated/kotlin/org/apache/camel/kotlin/components/NatsUriDsl.kt
+++
b/dsl/camel-kotlin-api/src/generated/kotlin/org/apache/camel/kotlin/components/NatsUriDsl.kt
@@ -407,6 +407,15 @@ public class NatsUriDsl(
it.property("traceConnection", traceConnection.toString())
}
+ /**
+ * If we use useCredentialsFile to true we'll need to set the
credentialsFilePath option. It can
+ * be loaded by default from classpath, but you can prefix with classpath:,
file:, or http: to load
+ * the resource from different systems.
+ */
+ public fun credentialsFilePath(credentialsFilePath: String) {
+ it.property("credentialsFilePath", credentialsFilePath)
+ }
+
/**
* Set secure option indicating TLS is required
*/