This is an automated email from the ASF dual-hosted git repository.
orpiske 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 63b3971aea1 Enhancement to camel splunk component
63b3971aea1 is described below
commit 63b3971aea118d418fd6ce822950db86b1aaf555
Author: Claudio Miranda <[email protected]>
AuthorDate: Wed Jul 6 21:51:15 2022 -0300
Enhancement to camel splunk component
* Explicit documentation about the token in camel-splunk-hec is not the
user's token, but the token generated for the HEC.
* Add support for token authentication, a safe alternative to the user's
password.
* Escape the error cause when creating the authenticating to splunk
(original stacktrace is lost)
* Document about using the realtime consumer.
---
.../camel/component/splunkhec/splunk-hec.json | 6 +++---
.../splunkhec/SplunkHECConfiguration.java | 2 +-
.../component/splunkhec/SplunkHECEndpoint.java | 4 ++--
.../component/splunk/SplunkEndpointConfigurer.java | 3 +++
.../component/splunk/SplunkEndpointUriFactory.java | 6 ++++--
.../org/apache/camel/component/splunk/splunk.json | 1 +
.../src/main/docs/splunk-component.adoc | 2 ++
.../splunk/DefaultSplunkConfigurationFactory.java | 9 +++++++--
.../component/splunk/SplunkConfiguration.java | 14 ++++++++++++++
.../component/splunk/SplunkConnectionFactory.java | 22 +++++++++++++++++-----
.../splunk/SplunkComponentConfigurationTest.java | 10 ++++++++++
11 files changed, 64 insertions(+), 15 deletions(-)
diff --git
a/components/camel-splunk-hec/src/generated/resources/org/apache/camel/component/splunkhec/splunk-hec.json
b/components/camel-splunk-hec/src/generated/resources/org/apache/camel/component/splunkhec/splunk-hec.json
index 60ce9a0d57f..00aed4b03a7 100644
---
a/components/camel-splunk-hec/src/generated/resources/org/apache/camel/component/splunkhec/splunk-hec.json
+++
b/components/camel-splunk-hec/src/generated/resources/org/apache/camel/component/splunkhec/splunk-hec.json
@@ -29,11 +29,11 @@
"CamelSplunkHECIndexTime": { "kind": "header", "displayName": "", "group":
"producer", "label": "", "required": false, "javaType": "Long", "deprecated":
false, "deprecationNote": "", "autowired": false, "secret": false,
"description": "Epoch-formatted time. Specify with the time query string
parameter. Sets a default for all events in the request. The default time can
be overridden.", "constantName":
"org.apache.camel.component.splunkhec.SplunkHECConstants#INDEX_TIME" }
},
"properties": {
- "splunkURL": { "kind": "path", "displayName": "Splunk URL", "group":
"producer", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "deprecationNote": "", "autowired":
false, "secret": false, "description": "Splunk Host URL" },
- "token": { "kind": "path", "displayName": "Token", "group": "security",
"label": "security", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "deprecationNote": "", "autowired":
false, "secret": false, "description": "Splunk authorization token" },
+ "splunkURL": { "kind": "path", "displayName": "Splunk URL", "group":
"producer", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "deprecationNote": "", "autowired":
false, "secret": false, "description": "Splunk Host and Port (example:
my_splunk_server:8089)" },
+ "token": { "kind": "path", "displayName": "Token", "group": "security",
"label": "security", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "deprecationNote": "", "autowired":
false, "secret": false, "description": "Splunk HEC token (this is the token
created for HEC and not the user's token)" },
"bodyOnly": { "kind": "parameter", "displayName": "Body Only", "group":
"producer", "label": "", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "configurationClass":
"org.apache.camel.component.splunkhec.SplunkHECConfiguration",
"configurationField": "configuration", "description": "Send only the message
body" },
"headersOnly": { "kind": "parameter", "displayName": "Headers Only",
"group": "producer", "label": "", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.splunkhec.SplunkHECConfiguration",
"configurationField": "configuration", "description": "Send only message
headers" },
- "host": { "kind": "parameter", "displayName": "Host", "group": "producer",
"label": "", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.splunkhec.SplunkHECConfiguration",
"configurationField": "configuration", "description": "Splunk host." },
+ "host": { "kind": "parameter", "displayName": "Host", "group": "producer",
"label": "", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"configurationClass":
"org.apache.camel.component.splunkhec.SplunkHECConfiguration",
"configurationField": "configuration", "description": "Splunk host field of the
event message. This is not the Splunk host to connect to." },
"index": { "kind": "parameter", "displayName": "Index", "group":
"producer", "label": "", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "camel", "configurationClass":
"org.apache.camel.component.splunkhec.SplunkHECConfiguration",
"configurationField": "configuration", "description": "Splunk index to write
to" },
"source": { "kind": "parameter", "displayName": "Source", "group":
"producer", "label": "", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "camel", "configurationClass":
"org.apache.camel.component.splunkhec.SplunkHECConfiguration",
"configurationField": "configuration", "description": "Splunk source argument"
},
"sourceType": { "kind": "parameter", "displayName": "Source Type",
"group": "producer", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "camel", "configurationClass":
"org.apache.camel.component.splunkhec.SplunkHECConfiguration",
"configurationField": "configuration", "description": "Splunk sourcetype
argument" },
diff --git
a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECConfiguration.java
b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECConfiguration.java
index 5a06bf7e6cb..078d003f0d0 100644
---
a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECConfiguration.java
+++
b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECConfiguration.java
@@ -93,7 +93,7 @@ public class SplunkHECConfiguration {
}
/**
- * Splunk host.
+ * Splunk host field of the event message. This is not the Splunk host to
connect to.
*/
public void setHost(String host) {
this.host = host;
diff --git
a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECEndpoint.java
b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECEndpoint.java
index 81f70e4ad23..e32e7182aca 100644
---
a/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECEndpoint.java
+++
b/components/camel-splunk-hec/src/main/java/org/apache/camel/component/splunkhec/SplunkHECEndpoint.java
@@ -94,7 +94,7 @@ public class SplunkHECEndpoint extends DefaultEndpoint {
}
/**
- * Splunk Host URL
+ * Splunk Host and Port (example: my_splunk_server:8089)
*/
public void setSplunkURL(String splunkURL) {
this.splunkURL = splunkURL;
@@ -105,7 +105,7 @@ public class SplunkHECEndpoint extends DefaultEndpoint {
}
/**
- * Splunk authorization token
+ * Splunk HEC token (this is the token created for HEC and not the user's
token)
*/
public void setToken(String token) {
this.token = token;
diff --git
a/components/camel-splunk/src/generated/java/org/apache/camel/component/splunk/SplunkEndpointConfigurer.java
b/components/camel-splunk/src/generated/java/org/apache/camel/component/splunk/SplunkEndpointConfigurer.java
index 6e5118eeb16..9adbebce6c0 100644
---
a/components/camel-splunk/src/generated/java/org/apache/camel/component/splunk/SplunkEndpointConfigurer.java
+++
b/components/camel-splunk/src/generated/java/org/apache/camel/component/splunk/SplunkEndpointConfigurer.java
@@ -88,6 +88,7 @@ public class SplunkEndpointConfigurer extends
PropertyConfigurerSupport implemen
case "tcpReceiverPort":
target.getConfiguration().setTcpReceiverPort(property(camelContext, int.class,
value)); return true;
case "timeunit":
case "timeUnit": target.setTimeUnit(property(camelContext,
java.util.concurrent.TimeUnit.class, value)); return true;
+ case "token":
target.getConfiguration().setToken(property(camelContext,
java.lang.String.class, value)); return true;
case "usefixeddelay":
case "useFixedDelay": target.setUseFixedDelay(property(camelContext,
boolean.class, value)); return true;
case "usesunhttpshandler":
@@ -167,6 +168,7 @@ public class SplunkEndpointConfigurer extends
PropertyConfigurerSupport implemen
case "tcpReceiverPort": return int.class;
case "timeunit":
case "timeUnit": return java.util.concurrent.TimeUnit.class;
+ case "token": return java.lang.String.class;
case "usefixeddelay":
case "useFixedDelay": return boolean.class;
case "usesunhttpshandler":
@@ -247,6 +249,7 @@ public class SplunkEndpointConfigurer extends
PropertyConfigurerSupport implemen
case "tcpReceiverPort": return
target.getConfiguration().getTcpReceiverPort();
case "timeunit":
case "timeUnit": return target.getTimeUnit();
+ case "token": return target.getConfiguration().getToken();
case "usefixeddelay":
case "useFixedDelay": return target.isUseFixedDelay();
case "usesunhttpshandler":
diff --git
a/components/camel-splunk/src/generated/java/org/apache/camel/component/splunk/SplunkEndpointUriFactory.java
b/components/camel-splunk/src/generated/java/org/apache/camel/component/splunk/SplunkEndpointUriFactory.java
index 90aaae05015..7b2147dbbd1 100644
---
a/components/camel-splunk/src/generated/java/org/apache/camel/component/splunk/SplunkEndpointUriFactory.java
+++
b/components/camel-splunk/src/generated/java/org/apache/camel/component/splunk/SplunkEndpointUriFactory.java
@@ -21,7 +21,7 @@ public class SplunkEndpointUriFactory extends
org.apache.camel.support.component
private static final Set<String> SECRET_PROPERTY_NAMES;
private static final Set<String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(45);
+ Set<String> props = new HashSet<>(46);
props.add("app");
props.add("backoffErrorThreshold");
props.add("backoffIdleThreshold");
@@ -64,12 +64,14 @@ public class SplunkEndpointUriFactory extends
org.apache.camel.support.component
props.add("tcpReceiverLocalPort");
props.add("tcpReceiverPort");
props.add("timeUnit");
+ props.add("token");
props.add("useFixedDelay");
props.add("useSunHttpsHandler");
props.add("username");
PROPERTY_NAMES = Collections.unmodifiableSet(props);
- Set<String> secretProps = new HashSet<>(2);
+ Set<String> secretProps = new HashSet<>(3);
secretProps.add("password");
+ secretProps.add("token");
secretProps.add("username");
SECRET_PROPERTY_NAMES = Collections.unmodifiableSet(secretProps);
Set<String> prefixes = new HashSet<>(1);
diff --git
a/components/camel-splunk/src/generated/resources/org/apache/camel/component/splunk/splunk.json
b/components/camel-splunk/src/generated/resources/org/apache/camel/component/splunk/splunk.json
index e868299d91b..4294082ce19 100644
---
a/components/camel-splunk/src/generated/resources/org/apache/camel/component/splunk/splunk.json
+++
b/components/camel-splunk/src/generated/resources/org/apache/camel/component/splunk/splunk.json
@@ -71,6 +71,7 @@
"useFixedDelay": { "kind": "parameter", "displayName": "Use Fixed Delay",
"group": "scheduler", "label": "consumer,scheduler", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": true, "description": "Controls if fixed delay
or fixed rate is used. See ScheduledExecutorService in JDK for details." },
"password": { "kind": "parameter", "displayName": "Password", "group":
"security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "configurationClass":
"org.apache.camel.component.splunk.SplunkConfiguration", "configurationField":
"configuration", "description": "Password for Splunk" },
"sslProtocol": { "kind": "parameter", "displayName": "Ssl Protocol",
"group": "security", "label": "security", "required": false, "type": "object",
"javaType": "com.splunk.SSLSecurityProtocol", "enum": [ "TLSv1.2", "TLSv1.1",
"TLSv1", "SSLv3" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "TLSv1.2", "configurationClass":
"org.apache.camel.component.splunk.SplunkConfiguration", "configurationField":
"configuration", "description": "Set the ssl protocol to [...]
+ "token": { "kind": "parameter", "displayName": "Token", "group":
"security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "configurationClass":
"org.apache.camel.component.splunk.SplunkConfiguration", "configurationField":
"configuration", "description": "User's token for Splunk. This takes precedence
over password when both are set" },
"username": { "kind": "parameter", "displayName": "Username", "group":
"security", "label": "security", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "configurationClass":
"org.apache.camel.component.splunk.SplunkConfiguration", "configurationField":
"configuration", "description": "Username for Splunk" },
"useSunHttpsHandler": { "kind": "parameter", "displayName": "Use Sun Https
Handler", "group": "security", "label": "security", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "configurationClass":
"org.apache.camel.component.splunk.SplunkConfiguration", "configurationField":
"configuration", "description": "Use sun.net.www.protocol.https.Handler Https
handler to establish the Splunk Connecti [...]
}
diff --git a/components/camel-splunk/src/main/docs/splunk-component.adoc
b/components/camel-splunk/src/main/docs/splunk-component.adoc
index 03c6360cccf..8e796090a9e 100644
--- a/components/camel-splunk/src/main/docs/splunk-component.adoc
+++ b/components/camel-splunk/src/main/docs/splunk-component.adoc
@@ -93,6 +93,8 @@ class.
|normal |Performs normal search and requires a search query in the search
option.
+|realtime |Performs realtime search on live data and requires a search query
in the search option.
+
|savedsearch |Performs search based on a search query saved in splunk and
requires the
name of the query in the savedSearch option.
|=======================================================================
diff --git
a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/DefaultSplunkConfigurationFactory.java
b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/DefaultSplunkConfigurationFactory.java
index b289718ab39..f0b10575a64 100644
---
a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/DefaultSplunkConfigurationFactory.java
+++
b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/DefaultSplunkConfigurationFactory.java
@@ -26,8 +26,13 @@ public class DefaultSplunkConfigurationFactory implements
SplunkConfigurationFac
public SplunkConfiguration parseMap(Map<String, Object> parameters) {
String username = (String) parameters.get("username");
String password = (String) parameters.get("password");
- if (ObjectHelper.isEmpty(username) || ObjectHelper.isEmpty(password)) {
- throw new IllegalArgumentException("Username and password has to
be specified");
+ String token = (String) parameters.get("token");
+ if (ObjectHelper.isEmpty(token) && (ObjectHelper.isEmpty(username) ||
ObjectHelper.isEmpty(password))) {
+ throw new IllegalArgumentException("Username and password OR token
has to be specified");
+ }
+ if (ObjectHelper.isNotEmpty(token)) {
+ parameters.remove("username");
+ parameters.remove("password");
}
return new SplunkConfiguration();
}
diff --git
a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConfiguration.java
b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConfiguration.java
index 0ae8646ef88..b2b47bb5d6f 100644
---
a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConfiguration.java
+++
b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConfiguration.java
@@ -48,6 +48,8 @@ public class SplunkConfiguration {
private String username;
@UriParam(label = "security", secret = true)
private String password;
+ @UriParam(label = "security", secret = true)
+ private String token;
@UriParam(defaultValue = "5000")
private int connectionTimeout = 5000;
@UriParam(label = "security")
@@ -314,6 +316,17 @@ public class SplunkConfiguration {
this.password = password;
}
+ public String getToken() {
+ return token;
+ }
+
+ /**
+ * User's token for Splunk. This takes precedence over password when both
are set
+ */
+ public void setToken(String token) {
+ this.token = token;
+ }
+
public boolean isStreaming() {
return streaming;
}
@@ -384,6 +397,7 @@ public class SplunkConfiguration {
splunkConnectionFactory.setScheme(getScheme());
splunkConnectionFactory.setUseSunHttpsHandler(isUseSunHttpsHandler());
splunkConnectionFactory.setSslProtocol(getSslProtocol());
+ splunkConnectionFactory.setToken(getToken());
return splunkConnectionFactory;
}
diff --git
a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConnectionFactory.java
b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConnectionFactory.java
index b5da29ff3ad..faeccc89eac 100644
---
a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConnectionFactory.java
+++
b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConnectionFactory.java
@@ -40,6 +40,7 @@ public class SplunkConnectionFactory {
private String owner;
private String username;
private String password;
+ private String token;
private int connectionTimeout;
private boolean useSunHttpsHandler;
private SSLSecurityProtocol sslProtocol;
@@ -95,6 +96,14 @@ public class SplunkConnectionFactory {
this.sslProtocol = sslProtocol;
}
+ public String getToken() {
+ return token;
+ }
+
+ public void setToken(String token) {
+ this.token = token;
+ }
+
public synchronized Service createService(CamelContext camelContext) {
final ServiceArgs args = new ServiceArgs();
if (host != null) {
@@ -115,9 +124,14 @@ public class SplunkConnectionFactory {
if (username != null) {
args.setUsername(username);
}
- if (password != null) {
+ if (password != null && token == null) {
args.setPassword(password);
}
+ if (token != null) {
+ args.setToken(String.format("Bearer %s", token));
+ args.remove("username");
+ args.remove("password");
+ }
// useful in cases where you want to bypass app. servers https handling
// (wls i'm looking at you)
if (isUseSunHttpsHandler()) {
@@ -156,11 +170,9 @@ public class SplunkConnectionFactory {
return service;
} catch (Exception e) {
throw new RuntimeException(
- String.format("could not connect to Splunk Server @ %s:%d
- %s", host, port, e.getMessage()));
+ String.format("could not connect to Splunk Server @ %s:%d
- %s", host, port, e.getMessage()), e);
} finally {
- if (executor != null) {
- camelContext.getExecutorServiceManager().shutdownNow(executor);
- }
+ camelContext.getExecutorServiceManager().shutdownNow(executor);
}
}
}
diff --git
a/components/camel-splunk/src/test/java/org/apache/camel/component/splunk/SplunkComponentConfigurationTest.java
b/components/camel-splunk/src/test/java/org/apache/camel/component/splunk/SplunkComponentConfigurationTest.java
index d699b16a671..c456486f210 100644
---
a/components/camel-splunk/src/test/java/org/apache/camel/component/splunk/SplunkComponentConfigurationTest.java
+++
b/components/camel-splunk/src/test/java/org/apache/camel/component/splunk/SplunkComponentConfigurationTest.java
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -51,6 +52,15 @@ public class SplunkComponentConfigurationTest extends
CamelTestSupport {
() -> component.createEndpoint("splunk://test"));
}
+ @Test
+ public void createProducerWithPasswordAndToken() throws Exception {
+ SplunkComponent component = context.getComponent("splunk",
SplunkComponent.class);
+ SplunkEndpoint endpoint
+ = (SplunkEndpoint)
component.createEndpoint("splunk://test?username=test&password=pw&token=myToken");
+ assertNull(endpoint.getConfiguration().getPassword());
+ assertEquals("myToken", endpoint.getConfiguration().getToken());
+ }
+
@Test
public void createProducerWithAnonymousAccess() throws Exception {
SplunkComponent component = context.getComponent("splunk",
SplunkComponent.class);