diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-security-hub.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-security-hub.json index cffa5381f325b..3c1f64e1d5d11 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-security-hub.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-security-hub.json @@ -68,7 +68,8 @@ "CamelAwsSecurityHubUnprocessedFindings": { "index": 17, "kind": "header", "displayName": "", "group": "batchUpdateFindings", "label": "batchUpdateFindings", "required": false, "javaType": "List", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The list of findings that were not updated", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#UNPROCESSED_FINDINGS" }, "CamelAwsSecurityHubProcessedFindings": { "index": 18, "kind": "header", "displayName": "", "group": "batchUpdateFindings", "label": "batchUpdateFindings", "required": false, "javaType": "List", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The list of findings that were updated successfully", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PROCESSED_FINDINGS" }, "CamelAwsSecurityHubFindingId": { "index": 19, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The finding ID to get history for", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#FINDING_ID" }, - "CamelAwsSecurityHubProductArn": { "index": 20, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The product ARN for the finding", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PRODUCT_ARN" } + "CamelAwsSecurityHubProductArn": { "index": 20, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The product ARN for the finding", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PRODUCT_ARN" }, + "CamelAwsSecurityHubFindingAggregatorArn": { "index": 21, "kind": "header", "displayName": "", "group": "getFindingAggregator", "label": "getFindingAggregator", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The ARN of the finding aggregator to retrieve", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#FINDING_AGGREGATOR_ARN" } }, "properties": { "label": { "index": 0, "kind": "path", "displayName": "Label", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Logical name" }, diff --git a/components/camel-aws/camel-aws-security-hub/pom.xml b/components/camel-aws/camel-aws-security-hub/pom.xml index 8aa4d09036744..b53ac449c0800 100644 --- a/components/camel-aws/camel-aws-security-hub/pom.xml +++ b/components/camel-aws/camel-aws-security-hub/pom.xml @@ -70,6 +70,12 @@ camel-test-spring-junit6 test + + org.mockito + mockito-junit-jupiter + ${mockito-version} + test + org.apache.camel diff --git a/components/camel-aws/camel-aws-security-hub/src/generated/resources/META-INF/org/apache/camel/component/aws/securityhub/aws-security-hub.json b/components/camel-aws/camel-aws-security-hub/src/generated/resources/META-INF/org/apache/camel/component/aws/securityhub/aws-security-hub.json index cffa5381f325b..3c1f64e1d5d11 100644 --- a/components/camel-aws/camel-aws-security-hub/src/generated/resources/META-INF/org/apache/camel/component/aws/securityhub/aws-security-hub.json +++ b/components/camel-aws/camel-aws-security-hub/src/generated/resources/META-INF/org/apache/camel/component/aws/securityhub/aws-security-hub.json @@ -68,7 +68,8 @@ "CamelAwsSecurityHubUnprocessedFindings": { "index": 17, "kind": "header", "displayName": "", "group": "batchUpdateFindings", "label": "batchUpdateFindings", "required": false, "javaType": "List", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The list of findings that were not updated", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#UNPROCESSED_FINDINGS" }, "CamelAwsSecurityHubProcessedFindings": { "index": 18, "kind": "header", "displayName": "", "group": "batchUpdateFindings", "label": "batchUpdateFindings", "required": false, "javaType": "List", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The list of findings that were updated successfully", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PROCESSED_FINDINGS" }, "CamelAwsSecurityHubFindingId": { "index": 19, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The finding ID to get history for", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#FINDING_ID" }, - "CamelAwsSecurityHubProductArn": { "index": 20, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The product ARN for the finding", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PRODUCT_ARN" } + "CamelAwsSecurityHubProductArn": { "index": 20, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The product ARN for the finding", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PRODUCT_ARN" }, + "CamelAwsSecurityHubFindingAggregatorArn": { "index": 21, "kind": "header", "displayName": "", "group": "getFindingAggregator", "label": "getFindingAggregator", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The ARN of the finding aggregator to retrieve", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#FINDING_AGGREGATOR_ARN" } }, "properties": { "label": { "index": 0, "kind": "path", "displayName": "Label", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Logical name" }, diff --git a/components/camel-aws/camel-aws-security-hub/src/main/java/org/apache/camel/component/aws/securityhub/SecurityHubConstants.java b/components/camel-aws/camel-aws-security-hub/src/main/java/org/apache/camel/component/aws/securityhub/SecurityHubConstants.java index e4c52e045c244..1cefa249b9e76 100644 --- a/components/camel-aws/camel-aws-security-hub/src/main/java/org/apache/camel/component/aws/securityhub/SecurityHubConstants.java +++ b/components/camel-aws/camel-aws-security-hub/src/main/java/org/apache/camel/component/aws/securityhub/SecurityHubConstants.java @@ -97,4 +97,8 @@ public interface SecurityHubConstants { @Metadata(label = "getFindingHistory", description = "The product ARN for the finding", javaType = "String") String PRODUCT_ARN = "CamelAwsSecurityHubProductArn"; + + @Metadata(label = "getFindingAggregator", + description = "The ARN of the finding aggregator to retrieve", javaType = "String") + String FINDING_AGGREGATOR_ARN = "CamelAwsSecurityHubFindingAggregatorArn"; } diff --git a/components/camel-aws/camel-aws-security-hub/src/main/java/org/apache/camel/component/aws/securityhub/SecurityHubProducer.java b/components/camel-aws/camel-aws-security-hub/src/main/java/org/apache/camel/component/aws/securityhub/SecurityHubProducer.java index 94021b52cca0b..b53168d3fc969 100644 --- a/components/camel-aws/camel-aws-security-hub/src/main/java/org/apache/camel/component/aws/securityhub/SecurityHubProducer.java +++ b/components/camel-aws/camel-aws-security-hub/src/main/java/org/apache/camel/component/aws/securityhub/SecurityHubProducer.java @@ -45,6 +45,7 @@ import software.amazon.awssdk.services.securityhub.model.BatchUpdateFindingsResponse; import software.amazon.awssdk.services.securityhub.model.DescribeHubRequest; import software.amazon.awssdk.services.securityhub.model.DescribeHubResponse; +import software.amazon.awssdk.services.securityhub.model.GetFindingAggregatorRequest; import software.amazon.awssdk.services.securityhub.model.GetFindingHistoryRequest; import software.amazon.awssdk.services.securityhub.model.GetFindingHistoryResponse; import software.amazon.awssdk.services.securityhub.model.GetFindingsRequest; @@ -94,6 +95,9 @@ public void process(Exchange exchange) throws Exception { case listEnabledProductsForImport: listEnabledProductsForImport(getEndpoint().getSecurityHubClient(), exchange); break; + case getFindingAggregator: + getFindingAggregator(getEndpoint().getSecurityHubClient(), exchange); + break; default: throw new IllegalArgumentException("Unsupported operation"); } @@ -292,6 +296,25 @@ private void getFindingHistory(SecurityHubClient securityHubClient, Exchange exc }); } + private void getFindingAggregator(SecurityHubClient securityHubClient, Exchange exchange) + throws InvalidPayloadException { + executeOperation( + exchange, + GetFindingAggregatorRequest.class, + securityHubClient::getFindingAggregator, + () -> { + String findingAggregatorArn + = exchange.getIn().getHeader(SecurityHubConstants.FINDING_AGGREGATOR_ARN, String.class); + if (ObjectHelper.isEmpty(findingAggregatorArn)) { + throw new IllegalArgumentException("Finding Aggregator ARN must be specified"); + } + GetFindingAggregatorRequest.Builder builder = GetFindingAggregatorRequest.builder(); + builder.findingAggregatorArn(findingAggregatorArn); + return securityHubClient.getFindingAggregator(builder.build()); + }, + "Get Finding Aggregator"); + } + private void describeHub(SecurityHubClient securityHubClient, Exchange exchange) throws InvalidPayloadException { executeOperation( exchange, diff --git a/components/camel-aws/camel-aws-security-hub/src/test/java/org/apache/camel/component/aws/securityhub/SecurityHubGetFindingAggregatorTest.java b/components/camel-aws/camel-aws-security-hub/src/test/java/org/apache/camel/component/aws/securityhub/SecurityHubGetFindingAggregatorTest.java new file mode 100644 index 0000000000000..83699964d4d8c --- /dev/null +++ b/components/camel-aws/camel-aws-security-hub/src/test/java/org/apache/camel/component/aws/securityhub/SecurityHubGetFindingAggregatorTest.java @@ -0,0 +1,67 @@ +/* + * 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.component.aws.securityhub; + +import org.apache.camel.BindToRegistry; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import software.amazon.awssdk.services.securityhub.SecurityHubClient; +import software.amazon.awssdk.services.securityhub.model.GetFindingAggregatorRequest; +import software.amazon.awssdk.services.securityhub.model.GetFindingAggregatorResponse; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class SecurityHubGetFindingAggregatorTest extends CamelTestSupport { + + private static final String AGGREGATOR_ARN + = "arn:aws:securityhub:eu-west-1:123456789012:finding-aggregator/abcd"; + + @BindToRegistry("securityHubClient") + private final SecurityHubClient securityHubClient = mock(SecurityHubClient.class); + + @Test + public void getFindingAggregatorIsSupportedAndUsesTheArnHeader() throws Exception { + when(securityHubClient.getFindingAggregator(any(GetFindingAggregatorRequest.class))) + .thenReturn(GetFindingAggregatorResponse.builder().findingAggregatorArn(AGGREGATOR_ARN).build()); + + // Before the fix this operation fell through to "Unsupported operation". + template.send("direct:start", + exchange -> exchange.getIn().setHeader(SecurityHubConstants.FINDING_AGGREGATOR_ARN, AGGREGATOR_ARN)); + + ArgumentCaptor captor + = ArgumentCaptor.forClass(GetFindingAggregatorRequest.class); + verify(securityHubClient).getFindingAggregator(captor.capture()); + assertEquals(AGGREGATOR_ARN, captor.getValue().findingAggregatorArn()); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:start") + .to("aws-security-hub://test?securityHubClient=#securityHubClient&operation=getFindingAggregator"); + } + }; + } +} diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SecurityHubEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SecurityHubEndpointBuilderFactory.java index 7f33eefebee7d..a8251ef413498 100644 --- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SecurityHubEndpointBuilderFactory.java +++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SecurityHubEndpointBuilderFactory.java @@ -853,6 +853,19 @@ public String awsSecurityHubFindingId() { public String awsSecurityHubProductArn() { return "CamelAwsSecurityHubProductArn"; } + /** + * The ARN of the finding aggregator to retrieve. + * + * The option is a: {@code String} type. + * + * Group: getFindingAggregator + * + * @return the name of the header {@code + * AwsSecurityHubFindingAggregatorArn}. + */ + public String awsSecurityHubFindingAggregatorArn() { + return "CamelAwsSecurityHubFindingAggregatorArn"; + } } static SecurityHubEndpointBuilder endpointBuilder(String componentName, String path) { class SecurityHubEndpointBuilderImpl extends AbstractEndpointBuilder implements SecurityHubEndpointBuilder, AdvancedSecurityHubEndpointBuilder {