diff --git a/catalog/pom.xml b/catalog/pom.xml index 64c1aca3cc6b..e5492e3452b6 100644 --- a/catalog/pom.xml +++ b/catalog/pom.xml @@ -227,6 +227,19 @@ + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail + ${project.version} + pom + test + + + * + * + + + org.apache.camel.quarkus camel-quarkus-aws-secrets-manager diff --git a/docs/modules/ROOT/examples/components/aws-cloudtrail.yml b/docs/modules/ROOT/examples/components/aws-cloudtrail.yml new file mode 100644 index 000000000000..725a7247ae66 --- /dev/null +++ b/docs/modules/ROOT/examples/components/aws-cloudtrail.yml @@ -0,0 +1,13 @@ +# Do not edit directly! +# This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +cqArtifactId: camel-quarkus-aws-cloudtrail +cqArtifactIdBase: aws-cloudtrail +cqNativeSupported: true +cqStatus: Stable +cqDeprecated: false +cqJvmSince: 3.37.0 +cqNativeSince: 3.37.0 +cqCamelPartName: aws-cloudtrail +cqCamelPartTitle: AWS Cloudtrail +cqCamelPartDescription: Consume events from Amazon Cloudtrail using AWS SDK version 2.x. +cqExtensionPageTitle: AWS Cloudtrail diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index 605bf9bf5ed6..ceeb98a2ba87 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -53,6 +53,7 @@ *** xref:reference/extensions/aws2-sqs.adoc[AWS 2 Simple Queue Service (SQS)] *** xref:reference/extensions/aws2-translate.adoc[AWS 2 Translate] *** xref:reference/extensions/aws-bedrock.adoc[AWS Bedrock] +*** xref:reference/extensions/aws-cloudtrail.adoc[AWS Cloudtrail] *** xref:reference/extensions/aws-secrets-manager.adoc[AWS Secrets Manager] *** xref:reference/extensions/aws-xray.adoc[AWS XRay] *** xref:reference/extensions/activemq.adoc[ActiveMQ] diff --git a/docs/modules/ROOT/pages/reference/extensions/aws-cloudtrail.adoc b/docs/modules/ROOT/pages/reference/extensions/aws-cloudtrail.adoc new file mode 100644 index 000000000000..63e4b5da1978 --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/aws-cloudtrail.adoc @@ -0,0 +1,52 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +[id="extensions-aws-cloudtrail"] += AWS Cloudtrail +:linkattrs: +:cq-artifact-id: camel-quarkus-aws-cloudtrail +:cq-native-supported: true +:cq-status: Stable +:cq-status-deprecation: Stable +:cq-description: Consume events from Amazon Cloudtrail using AWS SDK version 2.x. +:cq-deprecated: false +:cq-jvm-since: 3.37.0 +:cq-native-since: 3.37.0 + +ifeval::[{doc-show-badges} == true] +[.badges] +[.badge-key]##JVM since##[.badge-supported]##3.37.0## [.badge-key]##Native since##[.badge-supported]##3.37.0## +endif::[] + +Consume events from Amazon Cloudtrail using AWS SDK version 2.x. + +[id="extensions-aws-cloudtrail-whats-inside"] +== What's inside + +* xref:{cq-camel-components}::aws-cloudtrail-component.adoc[AWS Cloudtrail component], URI syntax: `aws-cloudtrail:label` + +Please refer to the above link for usage and configuration details. + +[id="extensions-aws-cloudtrail-maven-coordinates"] +== Maven coordinates + +https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-aws-cloudtrail[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"] + +Or add the coordinates to your existing project: + +[source,xml] +---- + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail + +---- +ifeval::[{doc-show-user-guide-link} == true] +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. +endif::[] + +[id="extensions-aws-cloudtrail-ssl-in-native-mode"] +== SSL in native mode + +This extension auto-enables SSL support in native mode. Hence you do not need to add +`quarkus.ssl.native=true` to your `application.properties` yourself. See also +https://quarkus.io/guides/native-and-ssl[Quarkus SSL guide]. diff --git a/extensions/aws-cloudtrail/deployment/pom.xml b/extensions/aws-cloudtrail/deployment/pom.xml new file mode 100644 index 000000000000..c565b75abd36 --- /dev/null +++ b/extensions/aws-cloudtrail/deployment/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail-parent + 3.37.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-aws-cloudtrail-deployment + Camel Quarkus :: AWS Cloudtrail :: Deployment + + + + org.apache.camel.quarkus + camel-quarkus-core-deployment + + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail + + + org.apache.camel.quarkus + camel-quarkus-support-aws2-deployment + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + diff --git a/extensions/aws-cloudtrail/deployment/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/deployment/AwsCloudtrailProcessor.java b/extensions/aws-cloudtrail/deployment/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/deployment/AwsCloudtrailProcessor.java new file mode 100644 index 000000000000..ecca2c65d8f3 --- /dev/null +++ b/extensions/aws-cloudtrail/deployment/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/deployment/AwsCloudtrailProcessor.java @@ -0,0 +1,30 @@ +/* + * 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. + */ +package org.apache.camel.quarkus.component.aws.cloudtrail.deployment; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; + +class AwsCloudtrailProcessor { + + private static final String FEATURE = "camel-aws-cloudtrail"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } +} diff --git a/extensions/aws-cloudtrail/pom.xml b/extensions/aws-cloudtrail/pom.xml new file mode 100644 index 000000000000..c8da1f21faad --- /dev/null +++ b/extensions/aws-cloudtrail/pom.xml @@ -0,0 +1,39 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-extensions + 3.37.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-aws-cloudtrail-parent + Camel Quarkus :: AWS Cloudtrail + pom + + + deployment + runtime + + diff --git a/extensions/aws-cloudtrail/runtime/pom.xml b/extensions/aws-cloudtrail/runtime/pom.xml new file mode 100644 index 000000000000..0f62358bbee2 --- /dev/null +++ b/extensions/aws-cloudtrail/runtime/pom.xml @@ -0,0 +1,109 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail-parent + 3.37.0-SNAPSHOT + ../pom.xml + + + camel-quarkus-aws-cloudtrail + Camel Quarkus :: AWS Cloudtrail :: Runtime + Consume events from Amazon Cloudtrail using AWS SDK version 2.x. + + + 3.37.0 + 3.37.0 + + + + + org.apache.camel.quarkus + camel-quarkus-core + + + org.apache.camel + camel-aws-cloudtrail + + + org.jboss.logging + commons-logging-jboss-logging + + + org.apache.camel.quarkus + camel-quarkus-support-aws2 + + + + + + + io.quarkus + quarkus-extension-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${quarkus.version} + + + + + + + + + + + full + + + !quickly + + + + + + org.apache.camel.quarkus + camel-quarkus-maven-plugin + + + update-extension-doc-page + + update-extension-doc-page + + process-classes + + + + + + + + diff --git a/extensions/aws-cloudtrail/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/aws-cloudtrail/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 000000000000..3b268f45cec8 --- /dev/null +++ b/extensions/aws-cloudtrail/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,36 @@ +# +# 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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel AWS Cloudtrail" +description: "Consume events from Amazon Cloudtrail using AWS SDK version 2.x" +metadata: + icon-url: "https://raw.githubusercontent.com/apache/camel-website/main/antora-ui-camel/src/img/logo-d.svg" + sponsor: "Apache Software Foundation" + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/aws-cloudtrail.html" + categories: + - "integration" + status: "stable" + integrates: + - name: "Camel" + artifact: "org.apache.camel:camel-base" + version: "${camel.version}" \ No newline at end of file diff --git a/extensions/pom.xml b/extensions/pom.xml index 7516fe9884b9..6543efc70b63 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -44,6 +44,7 @@ avro aws-bedrock + aws-cloudtrail aws-secrets-manager aws2-athena aws2-cw diff --git a/integration-test-groups/aws2/aws-cloudtrail/README.adoc b/integration-test-groups/aws2/aws-cloudtrail/README.adoc new file mode 100644 index 000000000000..d541d3ecd778 --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/README.adoc @@ -0,0 +1,73 @@ += AWS CloudTrail tests + +By default, the integration tests run against a WireMock container. + +== Running against real AWS + +Refer to the xref:../README.adoc[AWS 2 integration tests README] for general instructions on how to set up AWS credentials. + +The AWS credentials must have the following IAM permissions: + +* `cloudtrail:CreateTrail` +* `cloudtrail:DeleteTrail` +* `cloudtrail:LookupEvents` + +=== Running tests directly against real AWS + +==== Prerequisites + +Before running tests against real AWS, you must create an S3 bucket with proper CloudTrail permissions. + +Apply bucket policy to allow CloudTrail to write logs (replace `ACCOUNT-ID` and bucket name): + +[source,json] +---- +{ + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "AWSCloudTrailAclCheck", + "Effect": "Allow", + "Principal": { + "Service": "cloudtrail.amazonaws.com" + }, + "Action": "s3:GetBucketAcl", + "Resource": "arn:aws:s3:::my-cloudtrail-test-bucket" + }, + { + "Sid": "AWSCloudTrailWrite", + "Effect": "Allow", + "Principal": { + "Service": "cloudtrail.amazonaws.com" + }, + "Action": "s3:PutObject", + "Resource": "arn:aws:s3:::my-cloudtrail-test-bucket/AWSLogs/ACCOUNT-ID/*", + "Condition": { + "StringEquals": { + "s3:x-amz-acl": "bucket-owner-full-control" + } + } + } + ] +} +---- + +==== Set environment variables + +[source,shell] +---- +export AWS_ACCESS_KEY= +export AWS_SECRET_KEY= +export CLOUDTRAIL_REGION=us-east-1 +export AWS_CLOUDTRAIL_S3_BUCKET= +export CAMEL_QUARKUS_START_MOCK_BACKEND=false +---- + +==== Run the tests + +[source,shell] +---- +mvn clean test -pl integration-test-groups/aws2/aws-cloudtrail +---- + +NOTE: The tests create and delete a trail named `cq-test-trail`. The S3 bucket is not created or deleted by the tests, so you must create it beforehand and clean it up manually when finished. diff --git a/integration-test-groups/aws2/aws-cloudtrail/pom.xml b/integration-test-groups/aws2/aws-cloudtrail/pom.xml new file mode 100644 index 000000000000..a7ae82591510 --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/pom.xml @@ -0,0 +1,122 @@ + + + + 4.0.0 + + org.apache.camel.quarkus + camel-quarkus-build-parent-it + 3.37.0-SNAPSHOT + ../../../poms/build-parent-it/pom.xml + + + camel-quarkus-integration-test-aws-cloudtrail + Camel Quarkus :: Integration Tests :: AWS Cloudtrail + Integration tests for Camel Quarkus AWS Cloudtrail extension + + + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail + + + io.quarkus + quarkus-resteasy-jackson + + + + + io.quarkus + quarkus-junit + test + + + io.rest-assured + rest-assured + test + + + org.apache.camel.quarkus + camel-quarkus-integration-wiremock-support + test + + + org.awaitility + awaitility + test + + + + + + native + + + native + + + + true + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + + + + virtualDependencies + + + !noVirtualDependencies + + + + + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail-deployment + ${project.version} + pom + test + + + * + * + + + + + + + + diff --git a/integration-test-groups/aws2/aws-cloudtrail/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailResource.java b/integration-test-groups/aws2/aws-cloudtrail/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailResource.java new file mode 100644 index 000000000000..6aa5b01fb232 --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailResource.java @@ -0,0 +1,85 @@ +/* + * 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. + */ +package org.apache.camel.quarkus.component.aws.cloudtrail.it; + +import java.net.URI; +import java.util.List; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import org.eclipse.microprofile.config.inject.ConfigProperty; +import software.amazon.awssdk.services.cloudtrail.CloudTrailClient; +import software.amazon.awssdk.services.cloudtrail.model.CreateTrailRequest; +import software.amazon.awssdk.services.cloudtrail.model.CreateTrailResponse; +import software.amazon.awssdk.services.cloudtrail.model.DeleteTrailRequest; +import software.amazon.awssdk.services.cloudtrail.model.Event; + +@Path("/aws-cloudtrail") +@ApplicationScoped +public class AwsCloudtrailResource { + + @Inject + CloudTrailClient cloudTrailClient; + + @Inject + @Named("cloudtrailEvents") + List cloudtrailEvents; + + @ConfigProperty(name = "aws.cloudtrail.s3.bucket.name") + String s3BucketName; + + @Path("/trail/{trailName}") + @POST + @Produces(MediaType.TEXT_PLAIN) + public Response createTrail(@PathParam("trailName") String trailName) throws Exception { + CreateTrailRequest request = CreateTrailRequest.builder() + .name(trailName) + .s3BucketName(s3BucketName) + .build(); + + CreateTrailResponse response = cloudTrailClient.createTrail(request); + + return Response.created(new URI("https://camel.apache.org/")).entity(response.trailARN()).build(); + } + + @Path("/trail/{trailName}") + @DELETE + public void deleteTrail(@PathParam("trailName") String trailName) { + DeleteTrailRequest request = DeleteTrailRequest.builder() + .name(trailName) + .build(); + + cloudTrailClient.deleteTrail(request); + } + + @Path("/consumer/events") + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getConsumedEvents() { + // Return the count of events consumed by the Camel CloudTrail route + return Response.ok(cloudtrailEvents.size()).build(); + } +} diff --git a/integration-test-groups/aws2/aws-cloudtrail/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailRoutes.java b/integration-test-groups/aws2/aws-cloudtrail/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailRoutes.java new file mode 100644 index 000000000000..ea68cc2b4cd3 --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailRoutes.java @@ -0,0 +1,73 @@ +/* + * 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. + */ +package org.apache.camel.quarkus.component.aws.cloudtrail.it; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Inject; +import jakarta.inject.Named; +import jakarta.inject.Singleton; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.aws.cloudtrail.CloudtrailConstants; +import software.amazon.awssdk.services.cloudtrail.model.Event; + +@ApplicationScoped +public class AwsCloudtrailRoutes extends RouteBuilder { + + @Inject + @Named("cloudtrailEvents") + List cloudtrailEvents; + + @Override + public void configure() { + from("aws-cloudtrail:cloudtrail-events" + + "?cloudTrailClient=#cloudTrailClient" + + "&maxResults=10" + + "&delay=1000" + + "&initialDelay=0") + .process(e -> { + // CloudTrail consumer sets message body to cloudTrailEvent JSON bytes + // Event details are in headers + String eventId = e.getMessage().getHeader(CloudtrailConstants.EVENT_ID, String.class); + String eventName = e.getMessage().getHeader(CloudtrailConstants.EVENT_NAME, String.class); + String eventSource = e.getMessage().getHeader(CloudtrailConstants.EVENT_SOURCE, String.class); + String username = e.getMessage().getHeader(CloudtrailConstants.USERNAME, String.class); + + // Create Event object from headers for collection + Event event = Event.builder() + .eventId(eventId) + .eventName(eventName) + .eventSource(eventSource) + .username(username) + .build(); + + cloudtrailEvents.add(event); + }); + } + + static class Producers { + @Singleton + @Produces + @Named("cloudtrailEvents") + List cloudtrailEvents() { + return new CopyOnWriteArrayList<>(); + } + } +} diff --git a/integration-test-groups/aws2/aws-cloudtrail/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/CloudTrailClientProducer.java b/integration-test-groups/aws2/aws-cloudtrail/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/CloudTrailClientProducer.java new file mode 100644 index 000000000000..e44e7c828e7b --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/src/main/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/CloudTrailClientProducer.java @@ -0,0 +1,61 @@ +/* + * 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. + */ +package org.apache.camel.quarkus.component.aws.cloudtrail.it; + +import java.net.URI; +import java.util.Optional; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; +import jakarta.inject.Named; +import org.eclipse.microprofile.config.inject.ConfigProperty; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.cloudtrail.CloudTrailClient; +import software.amazon.awssdk.services.cloudtrail.CloudTrailClientBuilder; + +@ApplicationScoped +public class CloudTrailClientProducer { + + @ConfigProperty(name = "quarkus.cloudtrail.endpoint-override") + Optional endpointOverride; + + @ConfigProperty(name = "aws.cloudtrail.region") + String region; + + @ConfigProperty(name = "aws.cloudtrail.access-key") + String accessKeyId; + + @ConfigProperty(name = "aws.cloudtrail.secret-key") + String secretAccessKey; + + @Produces + @ApplicationScoped + @Named("cloudTrailClient") + public CloudTrailClient produceCloudTrailClient() { + CloudTrailClientBuilder builder = CloudTrailClient.builder() + .region(Region.of(region)) + .credentialsProvider( + StaticCredentialsProvider.create( + AwsBasicCredentials.create(accessKeyId, secretAccessKey))); + + endpointOverride.ifPresent(endpoint -> builder.endpointOverride(URI.create(endpoint))); + + return builder.build(); + } +} diff --git a/integration-test-groups/aws2/aws-cloudtrail/src/main/resources/application.properties b/integration-test-groups/aws2/aws-cloudtrail/src/main/resources/application.properties new file mode 100644 index 000000000000..ee5d0f20b11e --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/src/main/resources/application.properties @@ -0,0 +1,22 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +aws.cloudtrail.access-key=${AWS_ACCESS_KEY} +aws.cloudtrail.secret-key=${AWS_SECRET_KEY} +aws.cloudtrail.region=${CLOUDTRAIL_REGION:us-east-1} + +aws.cloudtrail.s3.bucket.name=${AWS_CLOUDTRAIL_S3_BUCKET:cq-test-bucket} diff --git a/integration-test-groups/aws2/aws-cloudtrail/src/test/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailIT.java b/integration-test-groups/aws2/aws-cloudtrail/src/test/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailIT.java new file mode 100644 index 000000000000..0e4cd2b2328d --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/src/test/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailIT.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +package org.apache.camel.quarkus.component.aws.cloudtrail.it; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +class AwsCloudtrailIT extends AwsCloudtrailTest { + +} diff --git a/integration-test-groups/aws2/aws-cloudtrail/src/test/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailTest.java b/integration-test-groups/aws2/aws-cloudtrail/src/test/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailTest.java new file mode 100644 index 000000000000..041322000bf1 --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/src/test/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailTest.java @@ -0,0 +1,65 @@ +/* + * 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. + */ +package org.apache.camel.quarkus.component.aws.cloudtrail.it; + +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; + +@QuarkusTest +@QuarkusTestResource(AwsCloudtrailTestResource.class) +class AwsCloudtrailTest { + + static final String TRAIL_NAME = "cq-test-trail"; + + @Test + public void testCloudtrailOperations() throws Exception { + String trailArn = null; + try { + // Create trail - tests AWS SDK management API and generates CloudTrail event + trailArn = RestAssured.given() + .post("/aws-cloudtrail/trail/" + TRAIL_NAME) + .then() + .statusCode(201) + .extract().body().asString(); + + // Wait for the Camel CloudTrail consumer to poll and consume events + // Consumer runs automatically in background, polling every 1 second + await().atMost(10, TimeUnit.SECONDS).until(() -> { + int count = RestAssured.given() + .get("/aws-cloudtrail/consumer/events") + .then() + .statusCode(200) + .extract().as(Integer.class); + return count > 0; + }); + } finally { + // Delete trail - cleanup + if (trailArn != null) { + RestAssured.given() + .delete("/aws-cloudtrail/trail/" + TRAIL_NAME) + .then() + .statusCode(204); + } + } + } +} diff --git a/integration-test-groups/aws2/aws-cloudtrail/src/test/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailTestResource.java b/integration-test-groups/aws2/aws-cloudtrail/src/test/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailTestResource.java new file mode 100644 index 000000000000..37cdd97a4c9a --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/src/test/java/org/apache/camel/quarkus/component/aws/cloudtrail/it/AwsCloudtrailTestResource.java @@ -0,0 +1,58 @@ +/* + * 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. + */ +package org.apache.camel.quarkus.component.aws.cloudtrail.it; + +import java.util.Map; + +import org.apache.camel.quarkus.test.mock.backend.MockBackendUtils; +import org.apache.camel.quarkus.test.wiremock.WireMockTestResourceLifecycleManager; + +public class AwsCloudtrailTestResource extends WireMockTestResourceLifecycleManager { + + private static final String CLOUDTRAIL_REGION = "CLOUDTRAIL_REGION"; + private static final String AWS_ACCESS_KEY = "AWS_ACCESS_KEY"; + private static final String AWS_SECRET_KEY = "AWS_SECRET_KEY"; + + @Override + public Map start() { + Map properties = super.start(); + + if (isMockingEnabled()) { + String wiremockUrl = properties.get("wiremock.url"); + properties.put("quarkus.cloudtrail.endpoint-override", wiremockUrl); + properties.put("aws.cloudtrail.region", envOrDefault(CLOUDTRAIL_REGION, "us-east-1")); + properties.put("aws.cloudtrail.access-key", "test"); + properties.put("aws.cloudtrail.secret-key", "test"); + } else { + properties.put("aws.cloudtrail.region", envOrDefault(CLOUDTRAIL_REGION, "us-east-1")); + properties.put("aws.cloudtrail.access-key", envOrDefault(AWS_ACCESS_KEY, "")); + properties.put("aws.cloudtrail.secret-key", envOrDefault(AWS_SECRET_KEY, "")); + } + + return properties; + } + + @Override + protected String getRecordTargetBaseUrl() { + return "https://cloudtrail." + envOrDefault(CLOUDTRAIL_REGION, "us-east-1") + ".amazonaws.com"; + } + + @Override + protected boolean isMockingEnabled() { + return MockBackendUtils.startMockBackend(); + } +} diff --git a/integration-test-groups/aws2/aws-cloudtrail/src/test/resources/mappings/cloudtrail-createTrail.json b/integration-test-groups/aws2/aws-cloudtrail/src/test/resources/mappings/cloudtrail-createTrail.json new file mode 100644 index 000000000000..2eaeed96b7b9 --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/src/test/resources/mappings/cloudtrail-createTrail.json @@ -0,0 +1,23 @@ +{ + "request": { + "method": "POST", + "urlPath": "/", + "headers": { + "X-Amz-Target": { + "equalTo": "com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.CreateTrail" + } + }, + "bodyPatterns": [ + { + "contains": "cq-test-trail" + } + ] + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/x-amz-json-1.1" + }, + "body": "{\"Name\":\"cq-test-trail\",\"S3BucketName\":\"cq-test-bucket\",\"TrailARN\":\"arn:aws:cloudtrail:us-east-1:123456789:trail/cq-test-trail\"}" + } +} \ No newline at end of file diff --git a/integration-test-groups/aws2/aws-cloudtrail/src/test/resources/mappings/cloudtrail-deleteTrail.json b/integration-test-groups/aws2/aws-cloudtrail/src/test/resources/mappings/cloudtrail-deleteTrail.json new file mode 100644 index 000000000000..c6ff17dda5ba --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/src/test/resources/mappings/cloudtrail-deleteTrail.json @@ -0,0 +1,23 @@ +{ + "request": { + "method": "POST", + "urlPath": "/", + "headers": { + "X-Amz-Target": { + "equalTo": "com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.DeleteTrail" + } + }, + "bodyPatterns": [ + { + "contains": "cq-test-trail" + } + ] + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/x-amz-json-1.1" + }, + "body": "{}" + } +} \ No newline at end of file diff --git a/integration-test-groups/aws2/aws-cloudtrail/src/test/resources/mappings/cloudtrail-lookupEvents.json b/integration-test-groups/aws2/aws-cloudtrail/src/test/resources/mappings/cloudtrail-lookupEvents.json new file mode 100644 index 000000000000..94b468b33c16 --- /dev/null +++ b/integration-test-groups/aws2/aws-cloudtrail/src/test/resources/mappings/cloudtrail-lookupEvents.json @@ -0,0 +1,18 @@ +{ + "request": { + "method": "POST", + "urlPath": "/", + "headers": { + "X-Amz-Target": { + "equalTo": "com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.LookupEvents" + } + } + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/x-amz-json-1.1" + }, + "body": "{\"Events\":[{\"EventId\":\"event-1\",\"EventName\":\"CreateTrail\",\"EventSource\":\"cloudtrail.amazonaws.com\",\"Username\":\"testuser\",\"EventTime\":1234567890,\"CloudTrailEvent\":\"{\\\"eventVersion\\\":\\\"1.08\\\",\\\"eventID\\\":\\\"event-1\\\",\\\"eventName\\\":\\\"CreateTrail\\\"}\"},{\"EventId\":\"event-2\",\"EventName\":\"DeleteTrail\",\"EventSource\":\"cloudtrail.amazonaws.com\",\"Username\":\"testuser\",\"EventTime\":1234567891,\"CloudTrailEvent\":\"{\\\"eventVersion\\\":\\\"1.08\\\",\\\"eventID\\\":\\\"event-2\\\",\\\"eventName\\\":\\\"DeleteTrail\\\"}\"}]}" + } +} \ No newline at end of file diff --git a/integration-test-groups/aws2/pom.xml b/integration-test-groups/aws2/pom.xml index e7439ef137cd..8df51823a27e 100644 --- a/integration-test-groups/aws2/pom.xml +++ b/integration-test-groups/aws2/pom.xml @@ -37,6 +37,7 @@ + aws-cloudtrail aws-secrets-manager aws2-cw aws2-ddb diff --git a/integration-tests/aws2-grouped/pom.xml b/integration-tests/aws2-grouped/pom.xml index 114f7c0faf31..49c2c421ad0f 100644 --- a/integration-tests/aws2-grouped/pom.xml +++ b/integration-tests/aws2-grouped/pom.xml @@ -56,6 +56,10 @@ io.quarkus quarkus-resteasy-multipart + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail + org.apache.camel.quarkus camel-quarkus-aws-secrets-manager @@ -124,6 +128,16 @@ org.apache.camel.quarkus camel-quarkus-integration-tests-support-aws2 + + software.amazon.awssdk + cloudtrail + + + commons-logging + commons-logging + + + software.amazon.awssdk ec2 @@ -273,6 +287,19 @@ + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail-deployment + ${project.version} + pom + test + + + * + * + + + org.apache.camel.quarkus camel-quarkus-aws-secrets-manager-deployment diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index 024dfa3bee32..0dcf1745afa6 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -231,6 +231,17 @@ + + org.apache.camel + camel-aws-cloudtrail + ${camel.version} + + + commons-logging + commons-logging + + + org.apache.camel camel-aws-common @@ -3535,6 +3546,16 @@ camel-quarkus-aws-bedrock-deployment ${camel-quarkus.version} + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail + ${camel-quarkus.version} + + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail-deployment + ${camel-quarkus.version} + org.apache.camel.quarkus camel-quarkus-aws-secrets-manager diff --git a/poms/bom/src/main/generated/flattened-full-pom.xml b/poms/bom/src/main/generated/flattened-full-pom.xml index 75b221414a44..92f96d05642a 100644 --- a/poms/bom/src/main/generated/flattened-full-pom.xml +++ b/poms/bom/src/main/generated/flattened-full-pom.xml @@ -144,6 +144,17 @@ + + org.apache.camel + camel-aws-cloudtrail + 4.20.0 + + + commons-logging + commons-logging + + + org.apache.camel camel-aws-common @@ -3420,6 +3431,16 @@ camel-quarkus-aws-bedrock-deployment 3.37.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail + 3.37.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail-deployment + 3.37.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-aws-secrets-manager diff --git a/poms/bom/src/main/generated/flattened-reduced-pom.xml b/poms/bom/src/main/generated/flattened-reduced-pom.xml index ebdf08b640a3..d1064513d036 100644 --- a/poms/bom/src/main/generated/flattened-reduced-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-pom.xml @@ -144,6 +144,17 @@ + + org.apache.camel + camel-aws-cloudtrail + 4.20.0 + + + commons-logging + commons-logging + + + org.apache.camel camel-aws-common @@ -3399,6 +3410,16 @@ camel-quarkus-aws-bedrock-deployment 3.37.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail + 3.37.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail-deployment + 3.37.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-aws-secrets-manager diff --git a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml index 71d81ce05ae0..aa41920ca6c6 100644 --- a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml +++ b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml @@ -144,6 +144,17 @@ + + org.apache.camel + camel-aws-cloudtrail + 4.20.0 + + + commons-logging + commons-logging + + + org.apache.camel camel-aws-common @@ -3399,6 +3410,16 @@ camel-quarkus-aws-bedrock-deployment 3.37.0-SNAPSHOT + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail + 3.37.0-SNAPSHOT + + + org.apache.camel.quarkus + camel-quarkus-aws-cloudtrail-deployment + 3.37.0-SNAPSHOT + org.apache.camel.quarkus camel-quarkus-aws-secrets-manager