This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 c7887fb3a Fix #3248: azure-functions-sink always sends the function
key in the x-functions-key header (#3249)
c7887fb3a is described below
commit c7887fb3ae59c502ce597108bdd454292527ac30
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Nov 19 08:02:44 2026 +0100
Fix #3248: azure-functions-sink always sends the function key in the
x-functions-key header (#3249)
The keyInHeader option, added on main for 4.24 and not released, is
removed: the key is
always sent in the x-functions-key header instead of the code query
parameter, so it is
not in the address of the request that error messages and access logs show.
The header is
removed from the message after the call, also when the call fails. Without
a key, no
header is sent.
Signed-off-by: Claus Ibsen <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../partials/azure-functions-sink-description.adoc | 3 +--
kamelets/azure-functions-sink.kamelet.yaml | 27 +++++++++----------
.../kamelets/catalog/HttpKameletsTargetTest.java | 31 +++++++++++-----------
.../main/resources/META-INF/kamelets-index.json | 2 +-
.../kamelets/azure-functions-sink.kamelet.yaml | 27 +++++++++----------
5 files changed, 43 insertions(+), 47 deletions(-)
diff --git a/docs/modules/ROOT/partials/azure-functions-sink-description.adoc
b/docs/modules/ROOT/partials/azure-functions-sink-description.adoc
index 7804fa54e..f31e18b17 100644
--- a/docs/modules/ROOT/partials/azure-functions-sink-description.adoc
+++ b/docs/modules/ROOT/partials/azure-functions-sink-description.adoc
@@ -4,7 +4,7 @@
In this Kamelet you should access the function on Azure through a key token in
the key parameter.
-By default the key is sent as the `code` query parameter of the request. With
`keyInHeader` set to true, it is sent in the `x-functions-key` header instead,
so the address of the request, which error messages show, does not hold the key:
+The key is sent in the `x-functions-key` header, so the address of the
request, which error messages and access logs show, does not hold it. The
header is removed from the message after the call, also when the call fails:
[source,yaml,subs='+attributes,macros']
----
@@ -19,5 +19,4 @@ By default the key is sent as the `code` query parameter of
the request. With `k
parameters:
url:
"https://azure-function-demo-12234.azurewebsites.net/api/httpexample"
key: "{{function.key}}"
- keyInHeader: true
----
diff --git a/kamelets/azure-functions-sink.kamelet.yaml
b/kamelets/azure-functions-sink.kamelet.yaml
index 5531444ca..9a4a39610 100644
--- a/kamelets/azure-functions-sink.kamelet.yaml
+++ b/kamelets/azure-functions-sink.kamelet.yaml
@@ -39,7 +39,7 @@ spec:
Output: when it is used inside a route, the body afterwards is the
response of the function, and the `CamelHttpResponseCode` header its status
code.
- Good to know: a response with a status code outside 200 to 299 fails the
message. The `key` is sent as the `code` query parameter of the request, or,
when `keyInHeader` is true, in the `x-functions-key` header, which keeps it out
of the address of the request that error messages show. Headers that start with
`CamelHttp` or `CamelRestHttp` are removed from the message first, so they
cannot change what the Kamelet does.
+ Good to know: a response with a status code outside 200 to 299 fails the
message. The `key` is sent in the `x-functions-key` header, not in the address
of the request, so error messages and access logs do not show it. The header is
removed from the message after the call, also when the call fails. Headers that
start with `CamelHttp` or `CamelRestHttp` are removed from the message first,
so they cannot change what the Kamelet does.
required:
- url
type: object
@@ -58,15 +58,11 @@ spec:
enum: ["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE",
"PATCH"]
key:
title: Key
- description: "A function key, or the master key, from the Azure
portal: the function, then Function Keys. Needed when the authorization level
of the function is `function` or `admin`; leave it empty for `anonymous`. It is
sent as the `code` query parameter, or in the `x-functions-key` header when
`keyInHeader` is true."
+ description: "A function key, or the master key, from the Azure
portal: the function, then Function Keys. Needed when the authorization level
of the function is `function` or `admin`; leave it empty for `anonymous`. It is
sent in the `x-functions-key` header."
type: string
format: password
x-descriptors:
- urn:camel:group:credentials
- keyInHeader:
- title: Key in Header
- description: If true, the `key` is sent in the `x-functions-key` HTTP
header instead of the `code` query parameter. Azure Functions accepts either.
The address of the request, which error messages show, then does not hold the
key, and the header is removed from the message after a successful call.
Requires `key`. When not set, or false, the key is sent as `code`.
- type: boolean
dependencies:
- "camel:vertx-http"
- "camel:kamelet"
@@ -86,23 +82,26 @@ spec:
when:
- expression:
simple:
- expression: "{{keyInHeader:false}} == true"
+ expression: "${propertiesExist:key}"
steps:
- setHeader:
name: x-functions-key
expression:
constant:
expression: "{{key}}"
- - to:
- uri: vertx-http
- parameters:
- httpUri: "{{url}}"
- - removeHeader:
- name: x-functions-key
+ - doTry:
+ steps:
+ - to:
+ uri: vertx-http
+ parameters:
+ httpUri: "{{url}}"
+ doFinally:
+ steps:
+ - removeHeader:
+ name: x-functions-key
otherwise:
steps:
- to:
uri: vertx-http
parameters:
httpUri: "{{url}}"
- code: "RAW({{?key}})"
diff --git
a/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/HttpKameletsTargetTest.java
b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/HttpKameletsTargetTest.java
index 145154bb7..c50e4fb8a 100644
---
a/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/HttpKameletsTargetTest.java
+++
b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/HttpKameletsTargetTest.java
@@ -40,7 +40,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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@@ -98,36 +98,35 @@ public class HttpKameletsTargetTest {
}
@Test
- void azureFunctionsSinkCallsTheConfiguredFunction() throws Exception {
- send("kamelet:azure-functions-sink?url=" + url(configuredServer) +
"/api/hello&key=" + KEY, "hello");
+ void azureFunctionsSinkCallsTheConfiguredFunctionWithTheKeyInAHeader()
throws Exception {
+ Exchange result = send("kamelet:azure-functions-sink?url=" +
url(configuredServer) + "/api/hello&key=" + KEY, "hello");
- assertEquals("POST /api/hello query=code=" + KEY + " key=null",
configured.poll());
+ assertEquals("POST /api/hello query=null key=" + KEY,
configured.poll());
assertTrue(other.isEmpty(), "no request goes to the other server");
+
assertFalse(result.getMessage().getHeaders().containsKey("x-functions-key"),
"the key does not go on");
}
@Test
- void azureFunctionsSinkCallsTheConfiguredFunctionWithTheKeyInAHeader()
throws Exception {
- Exchange result = send("kamelet:azure-functions-sink?url=" +
url(configuredServer) + "/api/hello&key=" + KEY
- + "&keyInHeader=true",
- "hello");
+ void azureFunctionsSinkCallsAnAnonymousFunctionWithoutAKey() throws
Exception {
+ send("kamelet:azure-functions-sink?url=" + url(configuredServer) +
"/api/hello", "hello");
- assertEquals("POST /api/hello query=null key=" + KEY,
configured.poll());
+ assertEquals("POST /api/hello query=null key=null", configured.poll());
assertTrue(other.isEmpty(), "no request goes to the other server");
-
assertFalse(result.getMessage().getHeaders().containsKey("x-functions-key"),
"the key does not go on");
}
@Test
- void azureFunctionsSinkKeepsTheKeyOutOfTheError() {
+ void azureFunctionsSinkKeepsTheKeyOutOfAFailedMessage() {
status = 404;
ProducerTemplate template = context.createProducerTemplate();
- CamelExecutionException e = assertThrows(CamelExecutionException.class,
- () -> template.requestBody("kamelet:azure-functions-sink?url="
+ url(configuredServer)
- + "/api/missing&key=" + KEY +
"&keyInHeader=true",
- "hello"));
+ Exchange result = template.request("kamelet:azure-functions-sink?url="
+ url(configuredServer)
+ + "/api/missing&key=" + KEY,
+ exchange -> exchange.getMessage().setBody("hello"));
assertEquals("POST /api/missing query=null key=" + KEY,
configured.poll());
- assertFalse(e.getCause().getMessage().contains(KEY),
e.getCause().getMessage());
+ assertNotNull(result.getException(), "a 404 fails the message");
+ assertFalse(result.getException().getMessage().contains(KEY),
result.getException().getMessage());
+
assertFalse(result.getMessage().getHeaders().containsKey("x-functions-key"),
"the key does not go on");
}
/**
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 479f91b66..fc876d2dc 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
@@ -375,7 +375,7 @@
"supportLevel" : "Stable",
"title" : "Azure Function Sink",
"summary" : "Calls a function in Azure Functions over HTTP for each
message, with the message as the body of the request.",
- "description" : "Calls a function in Azure Functions over HTTP for each
message, with the message as the body of the request.\n\nUse it to run your own
serverless code on each message, such as an enrichment, a notification or a
calculation. For any other web service, use `http-sink`.\n\nInput: the body is
sent as the request body, as text, bytes or a stream. Turn structured data such
as a Map into JSON text first, for example with `json-serialize-action`. The
`Content-Type` header is [...]
+ "description" : "Calls a function in Azure Functions over HTTP for each
message, with the message as the body of the request.\n\nUse it to run your own
serverless code on each message, such as an enrichment, a notification or a
calculation. For any other web service, use `http-sink`.\n\nInput: the body is
sent as the request body, as text, bytes or a stream. Turn structured data such
as a Map into JSON text first, for example with `json-serialize-action`. The
`Content-Type` header is [...]
"group" : "Azure Functions",
"namespace" : "Azure",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/azure-functions-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/azure-functions-sink.kamelet.yaml
index 5531444ca..9a4a39610 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/azure-functions-sink.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/azure-functions-sink.kamelet.yaml
@@ -39,7 +39,7 @@ spec:
Output: when it is used inside a route, the body afterwards is the
response of the function, and the `CamelHttpResponseCode` header its status
code.
- Good to know: a response with a status code outside 200 to 299 fails the
message. The `key` is sent as the `code` query parameter of the request, or,
when `keyInHeader` is true, in the `x-functions-key` header, which keeps it out
of the address of the request that error messages show. Headers that start with
`CamelHttp` or `CamelRestHttp` are removed from the message first, so they
cannot change what the Kamelet does.
+ Good to know: a response with a status code outside 200 to 299 fails the
message. The `key` is sent in the `x-functions-key` header, not in the address
of the request, so error messages and access logs do not show it. The header is
removed from the message after the call, also when the call fails. Headers that
start with `CamelHttp` or `CamelRestHttp` are removed from the message first,
so they cannot change what the Kamelet does.
required:
- url
type: object
@@ -58,15 +58,11 @@ spec:
enum: ["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE",
"PATCH"]
key:
title: Key
- description: "A function key, or the master key, from the Azure
portal: the function, then Function Keys. Needed when the authorization level
of the function is `function` or `admin`; leave it empty for `anonymous`. It is
sent as the `code` query parameter, or in the `x-functions-key` header when
`keyInHeader` is true."
+ description: "A function key, or the master key, from the Azure
portal: the function, then Function Keys. Needed when the authorization level
of the function is `function` or `admin`; leave it empty for `anonymous`. It is
sent in the `x-functions-key` header."
type: string
format: password
x-descriptors:
- urn:camel:group:credentials
- keyInHeader:
- title: Key in Header
- description: If true, the `key` is sent in the `x-functions-key` HTTP
header instead of the `code` query parameter. Azure Functions accepts either.
The address of the request, which error messages show, then does not hold the
key, and the header is removed from the message after a successful call.
Requires `key`. When not set, or false, the key is sent as `code`.
- type: boolean
dependencies:
- "camel:vertx-http"
- "camel:kamelet"
@@ -86,23 +82,26 @@ spec:
when:
- expression:
simple:
- expression: "{{keyInHeader:false}} == true"
+ expression: "${propertiesExist:key}"
steps:
- setHeader:
name: x-functions-key
expression:
constant:
expression: "{{key}}"
- - to:
- uri: vertx-http
- parameters:
- httpUri: "{{url}}"
- - removeHeader:
- name: x-functions-key
+ - doTry:
+ steps:
+ - to:
+ uri: vertx-http
+ parameters:
+ httpUri: "{{url}}"
+ doFinally:
+ steps:
+ - removeHeader:
+ name: x-functions-key
otherwise:
steps:
- to:
uri: vertx-http
parameters:
httpUri: "{{url}}"
- code: "RAW({{?key}})"