This is an automated email from the ASF dual-hosted git repository.
oscerd pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new 0178336d4 chore: exec-sink takes the arguments of the program (#3170)
(#3196)
0178336d4 is described below
commit 0178336d468e5a6c0ed5468f8d96210aace8ce02
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Nov 18 15:11:43 2026 +0100
chore: exec-sink takes the arguments of the program (#3170) (#3196)
exec-sink mapped only executable, so a command with arguments had to be
wrapped in a script. It now takes four optional options:
- args: the arguments, split on spaces by camel-exec; quotes keep an
argument with a space together. Wrapped in RAW() so a +, & or % reach
the program as written (an & broke the endpoint without it).
- workingDir: the directory to run the program in, also in RAW().
- commandTimeout: milliseconds after which the program is stopped. It is
not named timeout because the kamelet: endpoint takes a timeout
parameter itself, so it never reached the template.
- exitValues: the exit codes that mean success; another one fails the
message.
None has a default: when unset, the optional placeholders drop the
parameters, so the endpoint URI is the same as before. The description,
the "Good to know" paragraph and the partial page are updated.
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../ROOT/partials/exec-sink-description.adoc | 19 +++++++++++++-
kamelets/exec-sink.kamelet.yaml | 30 ++++++++++++++++++++--
.../main/resources/META-INF/kamelets-index.json | 2 +-
.../main/resources/kamelets/exec-sink.kamelet.yaml | 30 ++++++++++++++++++++--
4 files changed, 75 insertions(+), 6 deletions(-)
diff --git a/docs/modules/ROOT/partials/exec-sink-description.adoc
b/docs/modules/ROOT/partials/exec-sink-description.adoc
index b581ce1fe..69b08e2bf 100644
--- a/docs/modules/ROOT/partials/exec-sink-description.adoc
+++ b/docs/modules/ROOT/partials/exec-sink-description.adoc
@@ -4,10 +4,27 @@
This Kamelet executes system commands on the local machine. It requires an
executable command to be specified.
+=== Arguments
+
+The arguments of the program go in **Arguments**, separated by spaces. An
argument that contains a space goes in double or single quotes. The program is
started directly, not through a shell, so `*`, `$HOME`, `|`, `>` and `;` are
passed to it as they are.
+
+For example, to run a script with two options in `/opt/scripts`, stop it after
one minute, and fail the message when it does not end with exit code 0:
+
+[source,yaml]
+----
+executable: /opt/scripts/import-order.sh
+args: '--input /data/orders.csv --name "John Doe"'
+workingDir: /opt/scripts
+commandTimeout: 60000
+exitValues: "0"
+----
+
+The script gets four arguments: `--input`, `/data/orders.csv`, `--name` and
`John Doe`.
+
=== Output
The Kamelet returns the standard output (stdout) of the executed command as
the response body.
=== Security Considerations
-Use this Kamelet with caution as it executes system commands. Ensure proper
validation and security measures are in place when using dynamic command
execution.
\ No newline at end of file
+Use this Kamelet with caution as it executes system commands. Ensure proper
validation and security measures are in place when using dynamic command
execution.
diff --git a/kamelets/exec-sink.kamelet.yaml b/kamelets/exec-sink.kamelet.yaml
index 8814609d7..01958763c 100644
--- a/kamelets/exec-sink.kamelet.yaml
+++ b/kamelets/exec-sink.kamelet.yaml
@@ -39,16 +39,37 @@ spec:
Output: when it is used inside a route, the body afterwards is what the
program printed on its standard output, as a stream, or no body when it printed
nothing. The `CamelExecExitValue` header is the exit code of the program, and
`CamelExecStderr` what it printed on its standard error.
- Good to know: this Kamelet runs programs by design, with the rights of
the integration, so never place it after a source of untrusted messages.
`executable` is only the name or path of the program: arguments cannot be
given, so to run a command with arguments, put it in a script. A program that
ends with an error exit code does not fail the message; check
`CamelExecExitValue`. A program that is not found fails the message.
+ Good to know: this Kamelet runs programs by design, with the rights of
the integration, so never place it after a source of untrusted messages.
`executable` is only the name or path of the program, and its arguments go in
`args`. Only the options decide what runs: `CamelExecCommand*` headers on the
message are ignored. The program is started directly, not through a shell, so
`*`, `$HOME`, `|`, `>` and `;` in the arguments are passed on as they are. A
program that ends with an error [...]
required:
- executable
type: object
properties:
executable:
title: Executable Command
- description: The name of the program to run, found on the `PATH` of
the machine, or its full path, without arguments. A value with a space, such as
`ls -l`, fails, because no program has that name.
+ description: The name of the program to run, found on the `PATH` of
the machine, or its full path, without arguments. A value with a space, such as
`ls -l`, fails, because no program has that name; put the arguments in `args`.
type: string
example: /opt/scripts/import-order.sh
+ args:
+ title: Arguments
+ description: The arguments to give to the program, separated by
spaces, such as `-l /data`. Put an argument that contains a space in double or
single quotes, such as `--name "John Doe"`; the program gets the text inside
the quotes as one argument, without the quotes. To pass a quote character, put
the argument in the other kind of quotes, such as `"it's"`. When not set, the
program runs without arguments.
+ type: string
+ example: '--input /data/orders.csv --name "John Doe"'
+ workingDir:
+ title: Working Directory
+ description: The directory to run the program in, as a full path. A
directory that does not exist fails the message. When not set, the program runs
in the working directory of the integration.
+ type: string
+ example: /opt/scripts
+ commandTimeout:
+ title: Timeout
+ description: How long the program may run, in milliseconds, such as
60000 for one minute. A program that runs longer is stopped. The message then
carries on, with what the program printed so far as the body and the exit code
of the stopped program, such as 143, in `CamelExecExitValue`; set `exitValues`
to fail the message instead. When not set, the Kamelet waits until the program
ends.
+ type: integer
+ example: 60000
+ exitValues:
+ title: Exit Values
+ description: The exit codes that mean the program succeeded, separated
by commas without spaces, such as `0` or `0,1`. The message fails when the
program ends with another exit code, or is stopped by `commandTimeout`. When
not set, any exit code is accepted and the message carries on.
+ type: string
+ example: "0"
+ pattern: "^-?[0-9]+(,-?[0-9]+)*$"
dataTypes:
out:
headers:
@@ -71,6 +92,11 @@ spec:
uri: exec
parameters:
executable: "{{executable}}"
+ allowControlHeaders: false
+ args: "RAW({{?args}})"
+ workingDir: "RAW({{?workingDir}})"
+ timeout: "{{?commandTimeout}}"
+ exitValues: "{{?exitValues}}"
- setBody:
expression:
simple:
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 24cea83a9..d2a01b4d9 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -725,7 +725,7 @@
"supportLevel" : "Stable",
"title" : "Exec Sink",
"summary" : "Runs a program or command on the machine where the
integration runs, once for each message, with the body as its standard input.",
- "description" : "Runs a program or command on the machine where the
integration runs, once for each message, with the body as its standard
input.\n\nUse it to hand each message to an existing script or command-line
tool, for example a script that imports a file or a tool that converts data,
and to use what the program prints in the next step.\n\nInput: the body is
written to the standard input of the program, when it is text, bytes, a stream
or a file. Another body, or no body, runs [...]
+ "description" : "Runs a program or command on the machine where the
integration runs, once for each message, with the body as its standard
input.\n\nUse it to hand each message to an existing script or command-line
tool, for example a script that imports a file or a tool that converts data,
and to use what the program prints in the next step.\n\nInput: the body is
written to the standard input of the program, when it is text, bytes, a stream
or a file. Another body, or no body, runs [...]
"group" : "Exec",
"namespace" : "System",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/exec-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/exec-sink.kamelet.yaml
index 8814609d7..01958763c 100644
--- a/library/camel-kamelets/src/main/resources/kamelets/exec-sink.kamelet.yaml
+++ b/library/camel-kamelets/src/main/resources/kamelets/exec-sink.kamelet.yaml
@@ -39,16 +39,37 @@ spec:
Output: when it is used inside a route, the body afterwards is what the
program printed on its standard output, as a stream, or no body when it printed
nothing. The `CamelExecExitValue` header is the exit code of the program, and
`CamelExecStderr` what it printed on its standard error.
- Good to know: this Kamelet runs programs by design, with the rights of
the integration, so never place it after a source of untrusted messages.
`executable` is only the name or path of the program: arguments cannot be
given, so to run a command with arguments, put it in a script. A program that
ends with an error exit code does not fail the message; check
`CamelExecExitValue`. A program that is not found fails the message.
+ Good to know: this Kamelet runs programs by design, with the rights of
the integration, so never place it after a source of untrusted messages.
`executable` is only the name or path of the program, and its arguments go in
`args`. Only the options decide what runs: `CamelExecCommand*` headers on the
message are ignored. The program is started directly, not through a shell, so
`*`, `$HOME`, `|`, `>` and `;` in the arguments are passed on as they are. A
program that ends with an error [...]
required:
- executable
type: object
properties:
executable:
title: Executable Command
- description: The name of the program to run, found on the `PATH` of
the machine, or its full path, without arguments. A value with a space, such as
`ls -l`, fails, because no program has that name.
+ description: The name of the program to run, found on the `PATH` of
the machine, or its full path, without arguments. A value with a space, such as
`ls -l`, fails, because no program has that name; put the arguments in `args`.
type: string
example: /opt/scripts/import-order.sh
+ args:
+ title: Arguments
+ description: The arguments to give to the program, separated by
spaces, such as `-l /data`. Put an argument that contains a space in double or
single quotes, such as `--name "John Doe"`; the program gets the text inside
the quotes as one argument, without the quotes. To pass a quote character, put
the argument in the other kind of quotes, such as `"it's"`. When not set, the
program runs without arguments.
+ type: string
+ example: '--input /data/orders.csv --name "John Doe"'
+ workingDir:
+ title: Working Directory
+ description: The directory to run the program in, as a full path. A
directory that does not exist fails the message. When not set, the program runs
in the working directory of the integration.
+ type: string
+ example: /opt/scripts
+ commandTimeout:
+ title: Timeout
+ description: How long the program may run, in milliseconds, such as
60000 for one minute. A program that runs longer is stopped. The message then
carries on, with what the program printed so far as the body and the exit code
of the stopped program, such as 143, in `CamelExecExitValue`; set `exitValues`
to fail the message instead. When not set, the Kamelet waits until the program
ends.
+ type: integer
+ example: 60000
+ exitValues:
+ title: Exit Values
+ description: The exit codes that mean the program succeeded, separated
by commas without spaces, such as `0` or `0,1`. The message fails when the
program ends with another exit code, or is stopped by `commandTimeout`. When
not set, any exit code is accepted and the message carries on.
+ type: string
+ example: "0"
+ pattern: "^-?[0-9]+(,-?[0-9]+)*$"
dataTypes:
out:
headers:
@@ -71,6 +92,11 @@ spec:
uri: exec
parameters:
executable: "{{executable}}"
+ allowControlHeaders: false
+ args: "RAW({{?args}})"
+ workingDir: "RAW({{?workingDir}})"
+ timeout: "{{?commandTimeout}}"
+ exitValues: "{{?exitValues}}"
- setBody:
expression:
simple: