This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch 4.22.x
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git


The following commit(s) were added to refs/heads/4.22.x by this push:
     new ce261d0b0 [4.22.x] Fix #3189: the object storage event sources read a 
file whatever characters its name has (#3266)
ce261d0b0 is described below

commit ce261d0b0a2d20bf384774d759281e9fa9bcf2c9
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Nov 19 14:52:46 2026 +0100

    [4.22.x] Fix #3189: the object storage event sources read a file whatever 
characters its name has (#3266)
    
    Backport of #3259 (e6fce6acb7a3) to 4.22.x.
    
    aws-s3-event-based-source and google-storage-event-based-source, with 
getObject,
    put the name of the object of the event into the endpoint address of the 
call
    that reads it. A name with &, + or = was cut or changed, so the file was not
    found or the endpoint could not be created.
    
    They now pass the object name in the header of the component (CamelAwsS3Key,
    CamelGoogleCloudStorageObjectName), which the component uses as it is, and
    remove the other headers of the component from the message before the call.
    The S3 source calls a bucket only when its name is a valid bucket name, and 
the
    Google Cloud Storage source uses a fixed endpoint, as it reads only the 
bucket
    of bucketNameOrArn.
    
    Ported by hand in the YAML style of 4.22.x, with the endpoint options of 
4.22.x.
    ceph-event-based-source is not on 4.22.x.
    
    Signed-off-by: Claus Ibsen <[email protected]>
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 kamelets/aws-s3-event-based-source.kamelet.yaml    |  16 +++-
 .../google-storage-event-based-source.kamelet.yaml |  12 ++-
 .../aws-s3-event-based-source.kamelet.yaml         |  16 +++-
 .../google-storage-event-based-source.kamelet.yaml |  12 ++-
 ...s3-event-based-source-get-object.citrus.it.yaml | 105 +++++++++++++++++++++
 .../s3/aws-s3-event-based-source-get-object.yaml   |  33 +++++++
 6 files changed, 186 insertions(+), 8 deletions(-)

diff --git a/kamelets/aws-s3-event-based-source.kamelet.yaml 
b/kamelets/aws-s3-event-based-source.kamelet.yaml
index 165123805..4d90e82f7 100644
--- a/kamelets/aws-s3-event-based-source.kamelet.yaml
+++ b/kamelets/aws-s3-event-based-source.kamelet.yaml
@@ -200,7 +200,19 @@ spec:
                             - setProperty:
                                 name: aws-s3-bucket
                                 jsonpath: $.detail.bucket.name
-                            - toD: >-
-                                
aws2-s3:${exchangeProperty.aws-s3-bucket}?accessKey={{accessKey}}&secretKey={{secretKey}}&region={{region}}&operation=getObject&keyName=${exchangeProperty.aws-s3-name}
+                            - choice:
+                                when:
+                                  - simple: "${exchangeProperty.aws-s3-bucket} 
regex '[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]'"
+                                    steps:
+                                      # the S3 call takes the bucket and the 
key of the event, and no other header
+                                      - removeHeaders:
+                                          pattern: 'CamelAwsS3*'
+                                      - setHeader:
+                                          name: CamelAwsS3Key
+                                          simple: 
'${exchangeProperty.aws-s3-name}'
+                                      - toD: >-
+                                          
aws2-s3:${exchangeProperty.aws-s3-bucket}?accessKey={{accessKey}}&secretKey={{secretKey}}&region={{region}}&operation=getObject
+                                      - removeHeader:
+                                          name: CamelAwsS3Key
         - to: 'kamelet:sink'
 
diff --git a/kamelets/google-storage-event-based-source.kamelet.yaml 
b/kamelets/google-storage-event-based-source.kamelet.yaml
index cd730c381..c1a383ba1 100644
--- a/kamelets/google-storage-event-based-source.kamelet.yaml
+++ b/kamelets/google-storage-event-based-source.kamelet.yaml
@@ -111,6 +111,14 @@ spec:
                       when:
                         - simple: 
'${exchangeProperty.google-storage-event-type} == "OBJECT_FINALIZE" && 
${exchangeProperty.google-storage-bucket-id} == "{{bucketNameOrArn}}"'
                           steps:
-                            - toD: >-
-                                
google-storage:{{bucketNameOrArn}}?serviceAccountKey=base64:{{serviceAccountKey}}&operation=getObject&objectName=${exchangeProperty.google-storage-object-id}
+                            # the Cloud Storage call takes the name of the 
object of the event, and no other header
+                            - removeHeaders:
+                                pattern: 'CamelGoogleCloudStorage*'
+                            - setHeader:
+                                name: CamelGoogleCloudStorageObjectName
+                                simple: 
'${exchangeProperty.google-storage-object-id}'
+                            - to: >-
+                                
google-storage:{{bucketNameOrArn}}?serviceAccountKey=base64:{{serviceAccountKey}}&operation=getObject
+                            - removeHeader:
+                                name: CamelGoogleCloudStorageObjectName
         - to: 'kamelet:sink'
diff --git 
a/library/camel-kamelets/src/main/resources/kamelets/aws-s3-event-based-source.kamelet.yaml
 
b/library/camel-kamelets/src/main/resources/kamelets/aws-s3-event-based-source.kamelet.yaml
index 165123805..4d90e82f7 100644
--- 
a/library/camel-kamelets/src/main/resources/kamelets/aws-s3-event-based-source.kamelet.yaml
+++ 
b/library/camel-kamelets/src/main/resources/kamelets/aws-s3-event-based-source.kamelet.yaml
@@ -200,7 +200,19 @@ spec:
                             - setProperty:
                                 name: aws-s3-bucket
                                 jsonpath: $.detail.bucket.name
-                            - toD: >-
-                                
aws2-s3:${exchangeProperty.aws-s3-bucket}?accessKey={{accessKey}}&secretKey={{secretKey}}&region={{region}}&operation=getObject&keyName=${exchangeProperty.aws-s3-name}
+                            - choice:
+                                when:
+                                  - simple: "${exchangeProperty.aws-s3-bucket} 
regex '[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]'"
+                                    steps:
+                                      # the S3 call takes the bucket and the 
key of the event, and no other header
+                                      - removeHeaders:
+                                          pattern: 'CamelAwsS3*'
+                                      - setHeader:
+                                          name: CamelAwsS3Key
+                                          simple: 
'${exchangeProperty.aws-s3-name}'
+                                      - toD: >-
+                                          
aws2-s3:${exchangeProperty.aws-s3-bucket}?accessKey={{accessKey}}&secretKey={{secretKey}}&region={{region}}&operation=getObject
+                                      - removeHeader:
+                                          name: CamelAwsS3Key
         - to: 'kamelet:sink'
 
diff --git 
a/library/camel-kamelets/src/main/resources/kamelets/google-storage-event-based-source.kamelet.yaml
 
b/library/camel-kamelets/src/main/resources/kamelets/google-storage-event-based-source.kamelet.yaml
index cd730c381..c1a383ba1 100644
--- 
a/library/camel-kamelets/src/main/resources/kamelets/google-storage-event-based-source.kamelet.yaml
+++ 
b/library/camel-kamelets/src/main/resources/kamelets/google-storage-event-based-source.kamelet.yaml
@@ -111,6 +111,14 @@ spec:
                       when:
                         - simple: 
'${exchangeProperty.google-storage-event-type} == "OBJECT_FINALIZE" && 
${exchangeProperty.google-storage-bucket-id} == "{{bucketNameOrArn}}"'
                           steps:
-                            - toD: >-
-                                
google-storage:{{bucketNameOrArn}}?serviceAccountKey=base64:{{serviceAccountKey}}&operation=getObject&objectName=${exchangeProperty.google-storage-object-id}
+                            # the Cloud Storage call takes the name of the 
object of the event, and no other header
+                            - removeHeaders:
+                                pattern: 'CamelGoogleCloudStorage*'
+                            - setHeader:
+                                name: CamelGoogleCloudStorageObjectName
+                                simple: 
'${exchangeProperty.google-storage-object-id}'
+                            - to: >-
+                                
google-storage:{{bucketNameOrArn}}?serviceAccountKey=base64:{{serviceAccountKey}}&operation=getObject
+                            - removeHeader:
+                                name: CamelGoogleCloudStorageObjectName
         - to: 'kamelet:sink'
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/aws/s3/aws-s3-event-based-source-get-object.citrus.it.yaml
 
b/tests/camel-kamelets-itest/src/test/resources/aws/s3/aws-s3-event-based-source-get-object.citrus.it.yaml
new file mode 100644
index 000000000..34663188b
--- /dev/null
+++ 
b/tests/camel-kamelets-itest/src/test/resources/aws/s3/aws-s3-event-based-source-get-object.citrus.it.yaml
@@ -0,0 +1,105 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+name: aws-s3-event-based-source-get-object-test
+variables:
+  - name: "aws.s3.bucketNameOrArn"
+    value: "bucket-events"
+  - name: "aws.sqs.queueName"
+    value: "queue-s3-events"
+actions:
+  # Create AWS infrastructure (Floci container)
+  - testcontainers:
+      start:
+        localstack:
+          services:
+            - "S3"
+            - "SQS"
+          options:
+            buckets: '${aws.s3.bucketNameOrArn}'
+            queues: '${aws.sqs.queueName}'
+            s3ClientName: "s3EventsClient"
+            sqsClientName: "sqsEventsClient"
+  - waitFor:
+      http:
+        url: "${CITRUS_TESTCONTAINERS_LOCALSTACK_SERVICE_URL}"
+
+  # Files whose names have characters that an endpoint address gives a meaning 
to
+  - send:
+      endpoint: 
camel:aws2-s3://${aws.s3.bucketNameOrArn}?amazonS3Client=#s3EventsClient
+      message:
+        headers:
+          - name: CamelAwsS3Key
+            value: "dir/my file+x=1.txt"
+        body:
+          data: "Content of the first file"
+  - send:
+      endpoint: 
camel:aws2-s3://${aws.s3.bucketNameOrArn}?amazonS3Client=#s3EventsClient
+      message:
+        headers:
+          - name: CamelAwsS3Key
+            value: "reports/a&b=c.txt"
+        body:
+          data: "Content of the second file"
+
+  # Create Camel JBang integration. The file is read without 
uriEndpointOverride, so the S3 client finds the
+  # container through the environment.
+  - camel:
+      cli:
+        run:
+          integration:
+            file: "aws/s3/aws-s3-event-based-source-get-object.yaml"
+            environment:
+              variables:
+                - name: "AWS_ENDPOINT_URL_S3"
+                  value: "${CITRUS_TESTCONTAINERS_LOCALSTACK_SERVICE_URL}"
+            systemProperties:
+              properties:
+                - name: "aws.sqs.queueName"
+                  value: "${aws.sqs.queueName}"
+                - name: "aws.uriEndpointOverride"
+                  value: "${CITRUS_TESTCONTAINERS_LOCALSTACK_SERVICE_URL}"
+                - name: "aws.secretKey"
+                  value: "${CITRUS_TESTCONTAINERS_LOCALSTACK_SECRET_KEY}"
+                - name: "aws.accessKey"
+                  value: "${CITRUS_TESTCONTAINERS_LOCALSTACK_ACCESS_KEY}"
+                - name: "aws.region"
+                  value: "${CITRUS_TESTCONTAINERS_LOCALSTACK_REGION}"
+
+  # The events that EventBridge sends to the queue for the two uploads
+  - send:
+      endpoint: 
camel:aws2-sqs://${aws.sqs.queueName}?amazonSQSClient=#sqsEventsClient
+      message:
+        body:
+          data: '{"version":"0","source":"aws.s3","detail-type":"Object 
Created","detail":{"bucket":{"name":"${aws.s3.bucketNameOrArn}"},"object":{"key":"dir/my
 file+x=1.txt"},"reason":"PutObject"}}'
+  - send:
+      endpoint: 
camel:aws2-sqs://${aws.sqs.queueName}?amazonSQSClient=#sqsEventsClient
+      message:
+        body:
+          data: '{"version":"0","source":"aws.s3","detail-type":"Object 
Created","detail":{"bucket":{"name":"${aws.s3.bucketNameOrArn}"},"object":{"key":"reports/a&b=c.txt"},"reason":"PutObject"}}'
+
+  # Each file is read with its whole name
+  - camel:
+      cli:
+        verify:
+          integration: "aws-s3-event-based-source-get-object"
+          logMessage: "Read dir/my file+x=1.txt: Content of the first file"
+  - camel:
+      cli:
+        verify:
+          integration: "aws-s3-event-based-source-get-object"
+          logMessage: "Read reports/a&b=c.txt: Content of the second file"
diff --git 
a/tests/camel-kamelets-itest/src/test/resources/aws/s3/aws-s3-event-based-source-get-object.yaml
 
b/tests/camel-kamelets-itest/src/test/resources/aws/s3/aws-s3-event-based-source-get-object.yaml
new file mode 100644
index 000000000..ec2fffa8a
--- /dev/null
+++ 
b/tests/camel-kamelets-itest/src/test/resources/aws/s3/aws-s3-event-based-source-get-object.yaml
@@ -0,0 +1,33 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+- route:
+    from:
+      uri: "kamelet:aws-s3-event-based-source"
+      parameters:
+        queueNameOrArn: "{{aws.sqs.queueName}}"
+        uriEndpointOverride: "{{aws.uriEndpointOverride}}"
+        overrideEndpoint: "true"
+        accessKey: "{{aws.accessKey}}"
+        secretKey: "{{aws.secretKey}}"
+        region: "{{aws.region}}"
+        getObject: "true"
+      steps:
+        - convertBodyTo:
+            type: String
+        - log:
+            message: "Read ${header.CamelAwsS3ProducedKey}: ${body}"

Reply via email to