You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2023/12/21 10:36:35 UTC

(camel) branch main updated: CAMEL-20271 - Camel-AWS-Cloudtrail: Improve consumers by adding more information as exchange headers (#12528)

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 4e5c4de5668 CAMEL-20271 - Camel-AWS-Cloudtrail: Improve consumers by adding more information as exchange headers (#12528)
4e5c4de5668 is described below

commit 4e5c4de566857c14862f10c39e8ce113f3b65f7f
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Dec 21 11:36:28 2023 +0100

    CAMEL-20271 - Camel-AWS-Cloudtrail: Improve consumers by adding more information as exchange headers (#12528)
    
    * CAMEL-20271 - Camel-AWS-Cloudtrail: Improve consumers by adding more information as exchange headers
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
    
    * CAMEL-20271 - Camel-AWS-Cloudtrail: Improve consumers by adding more information as exchange headers
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
    
    ---------
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../apache/camel/catalog/components/aws-cloudtrail.json   |  6 ++++++
 .../camel/component/aws/cloudtrail/aws-cloudtrail.json    |  6 ++++++
 .../component/aws/cloudtrail/CloudtrailConstants.java     | 15 +++++++++++++++
 .../component/aws/cloudtrail/CloudtrailConsumer.java      | 12 ++++++------
 4 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-cloudtrail.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-cloudtrail.json
index 6b472daa954..365616cb18a 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-cloudtrail.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-cloudtrail.json
@@ -43,6 +43,12 @@
     "useDefaultCredentialsProvider": { "index": 18, "kind": "property", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.cloudtrail.CloudtrailConfiguration", "configurationField": "configuration", "description": "Set whether the Cloudtrail client shoul [...]
     "useProfileCredentialsProvider": { "index": 19, "kind": "property", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.cloudtrail.CloudtrailConfiguration", "configurationField": "configuration", "description": "Set whether the Cloudtrail client shoul [...]
   },
+  "headers": {
+    "CamelAwsCloudTrailEventId": { "index": 0, "kind": "header", "displayName": "", "group": "consumer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The event ID of the cloud trail event consumed.", "constantName": "org.apache.camel.component.aws.cloudtrail.CloudtrailConstants#EVENT_ID" },
+    "CamelAwsCloudTrailEventName": { "index": 1, "kind": "header", "displayName": "", "group": "consumer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The event Name of the cloud trail event consumed.", "constantName": "org.apache.camel.component.aws.cloudtrail.CloudtrailConstants#EVENT_NAME" },
+    "CamelAwsCloudTrailEventSource": { "index": 2, "kind": "header", "displayName": "", "group": "consumer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The event Source of the cloud trail event consumed.", "constantName": "org.apache.camel.component.aws.cloudtrail.CloudtrailConstants#EVENT_SOURCE" },
+    "CamelAwsCloudTrailEventUsername": { "index": 3, "kind": "header", "displayName": "", "group": "consumer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The associated username of the event of the cloud trail event consumed.", "constantName": "org.apache.camel.component.aws.cloudtrail.CloudtrailConstants#USERNAME" }
+  },
   "properties": {
     "label": { "index": 0, "kind": "path", "displayName": "Label", "group": "consumer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.cloudtrail.CloudtrailConfiguration", "configurationField": "configuration", "description": "A label for indexing cloudtrail endpoints" },
     "eventSource": { "index": 1, "kind": "parameter", "displayName": "Event Source", "group": "consumer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.cloudtrail.CloudtrailConfiguration", "configurationField": "configuration", "description": "Specify an event source to select events" },
diff --git a/components/camel-aws/camel-aws-cloudtrail/src/generated/resources/org/apache/camel/component/aws/cloudtrail/aws-cloudtrail.json b/components/camel-aws/camel-aws-cloudtrail/src/generated/resources/org/apache/camel/component/aws/cloudtrail/aws-cloudtrail.json
index 6b472daa954..365616cb18a 100644
--- a/components/camel-aws/camel-aws-cloudtrail/src/generated/resources/org/apache/camel/component/aws/cloudtrail/aws-cloudtrail.json
+++ b/components/camel-aws/camel-aws-cloudtrail/src/generated/resources/org/apache/camel/component/aws/cloudtrail/aws-cloudtrail.json
@@ -43,6 +43,12 @@
     "useDefaultCredentialsProvider": { "index": 18, "kind": "property", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.cloudtrail.CloudtrailConfiguration", "configurationField": "configuration", "description": "Set whether the Cloudtrail client shoul [...]
     "useProfileCredentialsProvider": { "index": 19, "kind": "property", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.cloudtrail.CloudtrailConfiguration", "configurationField": "configuration", "description": "Set whether the Cloudtrail client shoul [...]
   },
+  "headers": {
+    "CamelAwsCloudTrailEventId": { "index": 0, "kind": "header", "displayName": "", "group": "consumer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The event ID of the cloud trail event consumed.", "constantName": "org.apache.camel.component.aws.cloudtrail.CloudtrailConstants#EVENT_ID" },
+    "CamelAwsCloudTrailEventName": { "index": 1, "kind": "header", "displayName": "", "group": "consumer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The event Name of the cloud trail event consumed.", "constantName": "org.apache.camel.component.aws.cloudtrail.CloudtrailConstants#EVENT_NAME" },
+    "CamelAwsCloudTrailEventSource": { "index": 2, "kind": "header", "displayName": "", "group": "consumer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The event Source of the cloud trail event consumed.", "constantName": "org.apache.camel.component.aws.cloudtrail.CloudtrailConstants#EVENT_SOURCE" },
+    "CamelAwsCloudTrailEventUsername": { "index": 3, "kind": "header", "displayName": "", "group": "consumer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The associated username of the event of the cloud trail event consumed.", "constantName": "org.apache.camel.component.aws.cloudtrail.CloudtrailConstants#USERNAME" }
+  },
   "properties": {
     "label": { "index": 0, "kind": "path", "displayName": "Label", "group": "consumer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.cloudtrail.CloudtrailConfiguration", "configurationField": "configuration", "description": "A label for indexing cloudtrail endpoints" },
     "eventSource": { "index": 1, "kind": "parameter", "displayName": "Event Source", "group": "consumer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.cloudtrail.CloudtrailConfiguration", "configurationField": "configuration", "description": "Specify an event source to select events" },
diff --git a/components/camel-aws/camel-aws-cloudtrail/src/main/java/org/apache/camel/component/aws/cloudtrail/CloudtrailConstants.java b/components/camel-aws/camel-aws-cloudtrail/src/main/java/org/apache/camel/component/aws/cloudtrail/CloudtrailConstants.java
index 3578d1ff1e0..b2db9a7099b 100644
--- a/components/camel-aws/camel-aws-cloudtrail/src/main/java/org/apache/camel/component/aws/cloudtrail/CloudtrailConstants.java
+++ b/components/camel-aws/camel-aws-cloudtrail/src/main/java/org/apache/camel/component/aws/cloudtrail/CloudtrailConstants.java
@@ -16,5 +16,20 @@
  */
 package org.apache.camel.component.aws.cloudtrail;
 
+import org.apache.camel.spi.Metadata;
+
 public interface CloudtrailConstants {
+
+    @Metadata(description = "The event ID of the cloud trail event consumed.",
+              javaType = "String")
+    String EVENT_ID = "CamelAwsCloudTrailEventId";
+    @Metadata(description = "The event Name of the cloud trail event consumed.",
+              javaType = "String")
+    String EVENT_NAME = "CamelAwsCloudTrailEventName";
+    @Metadata(description = "The event Source of the cloud trail event consumed.",
+              javaType = "String")
+    String EVENT_SOURCE = "CamelAwsCloudTrailEventSource";
+    @Metadata(description = "The associated username of the event of the cloud trail event consumed.",
+              javaType = "String")
+    String USERNAME = "CamelAwsCloudTrailEventUsername";
 }
diff --git a/components/camel-aws/camel-aws-cloudtrail/src/main/java/org/apache/camel/component/aws/cloudtrail/CloudtrailConsumer.java b/components/camel-aws/camel-aws-cloudtrail/src/main/java/org/apache/camel/component/aws/cloudtrail/CloudtrailConsumer.java
index 1740d05c0bf..f74a831e2f7 100644
--- a/components/camel-aws/camel-aws-cloudtrail/src/main/java/org/apache/camel/component/aws/cloudtrail/CloudtrailConsumer.java
+++ b/components/camel-aws/camel-aws-cloudtrail/src/main/java/org/apache/camel/component/aws/cloudtrail/CloudtrailConsumer.java
@@ -30,11 +30,7 @@ import org.apache.camel.support.ScheduledBatchPollingConsumer;
 import org.apache.camel.util.CastUtils;
 import org.apache.camel.util.ObjectHelper;
 import software.amazon.awssdk.services.cloudtrail.CloudTrailClient;
-import software.amazon.awssdk.services.cloudtrail.model.Event;
-import software.amazon.awssdk.services.cloudtrail.model.LookupAttribute;
-import software.amazon.awssdk.services.cloudtrail.model.LookupAttributeKey;
-import software.amazon.awssdk.services.cloudtrail.model.LookupEventsRequest;
-import software.amazon.awssdk.services.cloudtrail.model.LookupEventsResponse;
+import software.amazon.awssdk.services.cloudtrail.model.*;
 
 public class CloudtrailConsumer extends ScheduledBatchPollingConsumer {
     private static Instant lastTime;
@@ -107,7 +103,11 @@ public class CloudtrailConsumer extends ScheduledBatchPollingConsumer {
 
     protected Exchange createExchange(Event event) {
         Exchange exchange = createExchange(true);
-        exchange.getIn().setBody(event.cloudTrailEvent().getBytes(StandardCharsets.UTF_8));
+        exchange.getMessage().setBody(event.cloudTrailEvent().getBytes(StandardCharsets.UTF_8));
+        exchange.getMessage().setHeader(CloudtrailConstants.EVENT_ID, event.eventId());
+        exchange.getMessage().setHeader(CloudtrailConstants.EVENT_NAME, event.eventName());
+        exchange.getMessage().setHeader(CloudtrailConstants.EVENT_SOURCE, event.eventSource());
+        exchange.getMessage().setHeader(CloudtrailConstants.USERNAME, event.username());
         return exchange;
     }
 }