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/11/28 10:52:11 UTC

(camel) branch CAMEL-20162 created (now d8c2acae815)

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

acosentino pushed a change to branch CAMEL-20162
in repository https://gitbox.apache.org/repos/asf/camel.git


      at d8c2acae815 CAMEL-20162 - Camel-AWS-Config: Add Describe Compliance By Config Rule operation

This branch includes the following new commits:

     new 8a9f7155bbd CAMEL-20162 - Camel-AWS-Config: Add Describe Compliance By Config Rule operation
     new d8c2acae815 CAMEL-20162 - Camel-AWS-Config: Add Describe Compliance By Config Rule operation

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/02: CAMEL-20162 - Camel-AWS-Config: Add Describe Compliance By Config Rule operation

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch CAMEL-20162
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 8a9f7155bbde2e0025092bb2cb002eb4945fe629
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Nov 28 11:47:16 2023 +0100

    CAMEL-20162 - Camel-AWS-Config: Add Describe Compliance By Config Rule operation
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../camel/component/aws/config/aws-config.json     |  4 +-
 .../component/aws/config/AWSConfigOperations.java  |  4 +-
 .../component/aws/config/AWSConfigProducer.java    | 39 ++++++++++++++++++
 .../integration/AWSConfigProducerManualIT.java     | 47 +++++++++++++++++++++-
 4 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/components/camel-aws/camel-aws-config/src/generated/resources/org/apache/camel/component/aws/config/aws-config.json b/components/camel-aws/camel-aws-config/src/generated/resources/org/apache/camel/component/aws/config/aws-config.json
index f3d14599473..f71b893bb71 100644
--- a/components/camel-aws/camel-aws-config/src/generated/resources/org/apache/camel/component/aws/config/aws-config.json
+++ b/components/camel-aws/camel-aws-config/src/generated/resources/org/apache/camel/component/aws/config/aws-config.json
@@ -24,7 +24,7 @@
   "componentProperties": {
     "configuration": { "index": 0, "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "Component configuration" },
     "lazyStartProducer": { "index": 1, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...]
-    "operation": { "index": 2, "kind": "property", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.config.AWSConfigOperations", "enum": [ "putConfigRule", "removeConfigRule" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description":  [...]
+    "operation": { "index": 2, "kind": "property", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.config.AWSConfigOperations", "enum": [ "putConfigRule", "removeConfigRule", "describeRuleCompliance" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "confi [...]
     "overrideEndpoint": { "index": 3, "kind": "property", "displayName": "Override Endpoint", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Set the need for overidding the endpoint. This option needs to be used in combina [...]
     "pojoRequest": { "index": 4, "kind": "property", "displayName": "Pojo Request", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" },
     "region": { "index": 5, "kind": "property", "displayName": "Region", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "ap-south-2", "ap-south-1", "eu-south-1", "eu-south-2", "us-gov-east-1", "me-central-1", "il-central-1", "ca-central-1", "eu-central-1", "us-iso-west-1", "eu-central-2", "us-west-1", "us-west-2", "af-south-1", "eu-north-1", "eu-west-3", "eu-west-2", "eu-west-1", "ap-northeast-3", "ap-northeast-2", "ap-nor [...]
@@ -51,7 +51,7 @@
   },
   "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, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Logical name" },
-    "operation": { "index": 1, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.config.AWSConfigOperations", "enum": [ "putConfigRule", "removeConfigRule" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": [...]
+    "operation": { "index": 1, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.config.AWSConfigOperations", "enum": [ "putConfigRule", "removeConfigRule", "describeRuleCompliance" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "conf [...]
     "overrideEndpoint": { "index": 2, "kind": "parameter", "displayName": "Override Endpoint", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Set the need for overidding the endpoint. This option needs to be used in combin [...]
     "pojoRequest": { "index": 3, "kind": "parameter", "displayName": "Pojo Request", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" },
     "region": { "index": 4, "kind": "parameter", "displayName": "Region", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "ap-south-2", "ap-south-1", "eu-south-1", "eu-south-2", "us-gov-east-1", "me-central-1", "il-central-1", "ca-central-1", "eu-central-1", "us-iso-west-1", "eu-central-2", "us-west-1", "us-west-2", "af-south-1", "eu-north-1", "eu-west-3", "eu-west-2", "eu-west-1", "ap-northeast-3", "ap-northeast-2", "ap-no [...]
diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigOperations.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigOperations.java
index e8aa2424401..6c002bc7e71 100644
--- a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigOperations.java
+++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigOperations.java
@@ -19,5 +19,7 @@ package org.apache.camel.component.aws.config;
 public enum AWSConfigOperations {
 
     putConfigRule,
-    removeConfigRule
+    removeConfigRule,
+
+    describeRuleCompliance
 }
diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducer.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducer.java
index c8883b12863..cc63c42e314 100644
--- a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducer.java
+++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducer.java
@@ -57,6 +57,9 @@ public class AWSConfigProducer extends DefaultProducer {
             case removeConfigRule:
                 removeConfigRule(getEndpoint().getConfigClient(), exchange);
                 break;
+            case describeRuleCompliance:
+                describeRuleCompliance(getEndpoint().getConfigClient(), exchange);
+                break;
             default:
                 throw new IllegalArgumentException("Unsupported operation");
         }
@@ -170,6 +173,42 @@ public class AWSConfigProducer extends DefaultProducer {
         }
     }
 
+    private void describeRuleCompliance(ConfigClient configClient, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {
+            Object payload = exchange.getIn().getMandatoryBody();
+            if (payload instanceof DescribeComplianceByConfigRuleRequest) {
+                DescribeComplianceByConfigRuleResponse result;
+                try {
+                    DescribeComplianceByConfigRuleRequest request = (DescribeComplianceByConfigRuleRequest) payload;
+                    result = configClient.describeComplianceByConfigRule(request);
+                } catch (AwsServiceException ase) {
+                    LOG.trace("Describe Compliance by Config rule command returned the error code {}",
+                            ase.awsErrorDetails().errorCode());
+                    throw ase;
+                }
+                Message message = getMessageForResponse(exchange);
+                message.setBody(result);
+            }
+        } else {
+            DescribeComplianceByConfigRuleRequest.Builder builder = DescribeComplianceByConfigRuleRequest.builder();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWSConfigConstants.RULE_NAME))) {
+                String ruleName = exchange.getIn().getHeader(AWSConfigConstants.RULE_NAME, String.class);
+                builder.configRuleNames(ruleName);
+            }
+            DescribeComplianceByConfigRuleResponse result;
+            try {
+                DescribeComplianceByConfigRuleRequest request = builder.build();
+                result = configClient.describeComplianceByConfigRule(request);
+            } catch (AwsServiceException ase) {
+                LOG.trace("Describe Compliance by Config Rule command returned the error code {}",
+                        ase.awsErrorDetails().errorCode());
+                throw ase;
+            }
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
+        }
+    }
+
     public static Message getMessageForResponse(final Exchange exchange) {
         return exchange.getMessage();
     }
diff --git a/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/integration/AWSConfigProducerManualIT.java b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/integration/AWSConfigProducerManualIT.java
index 97f5f755e32..a7e8237a65f 100644
--- a/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/integration/AWSConfigProducerManualIT.java
+++ b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/integration/AWSConfigProducerManualIT.java
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.EnabledIfSystemProperties;
 import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
 import software.amazon.awssdk.services.config.model.DeleteConfigRuleResponse;
+import software.amazon.awssdk.services.config.model.DescribeComplianceByConfigRuleResponse;
 import software.amazon.awssdk.services.config.model.PutConfigRuleResponse;
 
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -42,7 +43,7 @@ public class AWSConfigProducerManualIT extends CamelTestSupport {
     private MockEndpoint mock;
 
     @Test
-    public void translateTextTest() {
+    public void PutAndRemoveRule() {
 
         mock.expectedMessageCount(1);
         Exchange exchange = template.request("direct:putConfigRule", new Processor() {
@@ -70,6 +71,46 @@ public class AWSConfigProducerManualIT extends CamelTestSupport {
         assertTrue(deleteResponse.sdkHttpResponse().isSuccessful());
     }
 
+    @Test
+    public void PutRuleCheckCompliance() {
+
+        mock.expectedMessageCount(1);
+        Exchange exchange = template.request("direct:putConfigRule", new Processor() {
+            @Override
+            public void process(Exchange exchange) {
+
+                exchange.getMessage().setHeader(AWSConfigConstants.SOURCE, "AWS");
+                exchange.getMessage().setHeader(AWSConfigConstants.RULE_SOURCE_IDENTIFIER, "S3_VERSION_LIFECYCLE_POLICY_CHECK");
+                exchange.getMessage().setHeader(AWSConfigConstants.RULE_NAME, "Lifecycle-policy-check");
+            }
+        });
+
+        PutConfigRuleResponse resultGet = (PutConfigRuleResponse) exchange.getIn().getBody();
+        assertTrue(resultGet.sdkHttpResponse().isSuccessful());
+
+        exchange = template.request("direct:checkCompliance", new Processor() {
+            @Override
+            public void process(Exchange exchange) {
+
+                exchange.getMessage().setHeader(AWSConfigConstants.RULE_NAME, "Lifecycle-policy-check");
+            }
+        });
+
+        DescribeComplianceByConfigRuleResponse compliancy = (DescribeComplianceByConfigRuleResponse) exchange.getIn().getBody();
+        assertTrue(compliancy.sdkHttpResponse().isSuccessful());
+
+        exchange = template.request("direct:removeConfigRule", new Processor() {
+            @Override
+            public void process(Exchange exchange) {
+
+                exchange.getMessage().setHeader(AWSConfigConstants.RULE_NAME, "Lifecycle-policy-check");
+            }
+        });
+
+        DeleteConfigRuleResponse deleteResponse = (DeleteConfigRuleResponse) exchange.getIn().getBody();
+        assertTrue(deleteResponse.sdkHttpResponse().isSuccessful());
+    }
+
     @Override
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
@@ -82,6 +123,10 @@ public class AWSConfigProducerManualIT extends CamelTestSupport {
                 from("direct:removeConfigRule")
                         .to("aws-config://test?accessKey=RAW({{aws.manual.access.key}})&secretKey=RAW({{aws.manual.secret.key}})&region=eu-west-1&operation=removeConfigRule")
                         .to("mock:result");
+
+                from("direct:checkCompliance")
+                        .to("aws-config://test?accessKey=RAW({{aws.manual.access.key}})&secretKey=RAW({{aws.manual.secret.key}})&region=eu-west-1&operation=describeRuleCompliance")
+                        .to("mock:result");
             }
         };
     }


(camel) 02/02: CAMEL-20162 - Camel-AWS-Config: Add Describe Compliance By Config Rule operation

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch CAMEL-20162
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d8c2acae815a31d2ad5faf8aed84f0688c3255df
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Nov 28 11:51:52 2023 +0100

    CAMEL-20162 - Camel-AWS-Config: Add Describe Compliance By Config Rule operation
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../resources/org/apache/camel/catalog/components/aws-config.json     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-config.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-config.json
index f3d14599473..f71b893bb71 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-config.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws-config.json
@@ -24,7 +24,7 @@
   "componentProperties": {
     "configuration": { "index": 0, "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "Component configuration" },
     "lazyStartProducer": { "index": 1, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...]
-    "operation": { "index": 2, "kind": "property", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.config.AWSConfigOperations", "enum": [ "putConfigRule", "removeConfigRule" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description":  [...]
+    "operation": { "index": 2, "kind": "property", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.config.AWSConfigOperations", "enum": [ "putConfigRule", "removeConfigRule", "describeRuleCompliance" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "confi [...]
     "overrideEndpoint": { "index": 3, "kind": "property", "displayName": "Override Endpoint", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Set the need for overidding the endpoint. This option needs to be used in combina [...]
     "pojoRequest": { "index": 4, "kind": "property", "displayName": "Pojo Request", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" },
     "region": { "index": 5, "kind": "property", "displayName": "Region", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "ap-south-2", "ap-south-1", "eu-south-1", "eu-south-2", "us-gov-east-1", "me-central-1", "il-central-1", "ca-central-1", "eu-central-1", "us-iso-west-1", "eu-central-2", "us-west-1", "us-west-2", "af-south-1", "eu-north-1", "eu-west-3", "eu-west-2", "eu-west-1", "ap-northeast-3", "ap-northeast-2", "ap-nor [...]
@@ -51,7 +51,7 @@
   },
   "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, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Logical name" },
-    "operation": { "index": 1, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.config.AWSConfigOperations", "enum": [ "putConfigRule", "removeConfigRule" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": [...]
+    "operation": { "index": 1, "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.config.AWSConfigOperations", "enum": [ "putConfigRule", "removeConfigRule", "describeRuleCompliance" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "conf [...]
     "overrideEndpoint": { "index": 2, "kind": "parameter", "displayName": "Override Endpoint", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Set the need for overidding the endpoint. This option needs to be used in combin [...]
     "pojoRequest": { "index": 3, "kind": "parameter", "displayName": "Pojo Request", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" },
     "region": { "index": 4, "kind": "parameter", "displayName": "Region", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "ap-south-2", "ap-south-1", "eu-south-1", "eu-south-2", "us-gov-east-1", "me-central-1", "il-central-1", "ca-central-1", "eu-central-1", "us-iso-west-1", "eu-central-2", "us-west-1", "us-west-2", "af-south-1", "eu-north-1", "eu-west-3", "eu-west-2", "eu-west-1", "ap-northeast-3", "ap-northeast-2", "ap-no [...]