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/01 10:13:58 UTC
(camel) 01/04: Camel-AWS-Config: Add a Put Conformance Pack operation to producer
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch conformace-pack
in repository https://gitbox.apache.org/repos/asf/camel.git
commit fe0018fc2365e93ac7180b5201d767e02559ca8a
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Dec 1 10:58:38 2023 +0100
Camel-AWS-Config: Add a Put Conformance Pack operation to producer
Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
.../camel/component/aws/config/aws-config.json | 9 ++--
.../component/aws/config/AWSConfigConstants.java | 9 ++++
.../component/aws/config/AWSConfigOperations.java | 3 +-
.../component/aws/config/AWSConfigProducer.java | 54 ++++++++++++++++++++++
4 files changed, 71 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 f71b893bb71..6f425a2a828 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", "describeRuleCompliance" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "confi [...]
+ "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", "putConformancePack" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "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 [...]
@@ -47,11 +47,14 @@
"CamelAwsConfigOperation": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The operation we want to perform", "constantName": "org.apache.camel.component.aws.config.AWSConfigConstants#OPERATION" },
"CamelAwsConfigRuleSourceIdentifier": { "index": 1, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Managed rule source identifier", "constantName": "org.apache.camel.component.aws.config.AWSConfigConstants#RULE_SOURCE_IDENTIFIER" },
"CamelAwsConfigRuleSource": { "index": 2, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The source object for the rule. The owner of the rule could be AWS, CUSTOM_LAMBDA or CUSTOM_POLICY", "constantName": "org.apache.camel.component.aws.config.AWSConfigConstants#SOURCE" },
- "CamelAwsConfigRuleName": { "index": 3, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Managed rule name", "constantName": "org.apache.camel.component.aws.config.AWSConfigConstants#RULE_NAME" }
+ "CamelAwsConfigRuleName": { "index": 3, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Managed rule name", "constantName": "org.apache.camel.component.aws.config.AWSConfigConstants#RULE_NAME" },
+ "CamelAwsConformancePackName": { "index": 4, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The Conformance pack name", "constantName": "org.apache.camel.component.aws.config.AWSConfigConstants#CONFORMACE_PACK_NAME" },
+ "CamelAwsConfigConformacePackS3TemplateURI": { "index": 5, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The location of the file containing the template body in S3", "constantName": "org.apache.camel.component.aws.config.AWSConfigConstants#CONFORMACE_PACK_S3_TEMPLATE_URI" },
+ "CamelAwsConfigConformacePackTemplateBody": { "index": 6, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "A string containing the full conformance pack template body", "constantName": "org.apache.camel.component.aws.config.AWSConfigConstants#CONFORMACE_PACK_TEMPLATE_BODY" }
},
"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", "describeRuleCompliance" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "conf [...]
+ "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", "putConformancePack" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "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/AWSConfigConstants.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigConstants.java
index 0a5a902dfb2..f9973b0d5fa 100644
--- a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigConstants.java
+++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigConstants.java
@@ -31,4 +31,13 @@ public interface AWSConfigConstants {
String SOURCE = "CamelAwsConfigRuleSource";
@Metadata(description = "The Managed rule name", javaType = "String")
String RULE_NAME = "CamelAwsConfigRuleName";
+
+ @Metadata(description = "The Conformance pack name", javaType = "String")
+ String CONFORMACE_PACK_NAME = "CamelAwsConformancePackName";
+
+ @Metadata(description = "The location of the file containing the template body in S3", javaType = "String")
+ String CONFORMACE_PACK_S3_TEMPLATE_URI = "CamelAwsConfigConformacePackS3TemplateURI";
+
+ @Metadata(description = "A string containing the full conformance pack template body", javaType = "String")
+ String CONFORMACE_PACK_TEMPLATE_BODY = "CamelAwsConfigConformacePackTemplateBody";
}
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 6c002bc7e71..7c215d10b4e 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
@@ -20,6 +20,7 @@ public enum AWSConfigOperations {
putConfigRule,
removeConfigRule,
+ describeRuleCompliance,
+ putConformancePack
- 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 cc63c42e314..f59031c940f 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
@@ -60,6 +60,9 @@ public class AWSConfigProducer extends DefaultProducer {
case describeRuleCompliance:
describeRuleCompliance(getEndpoint().getConfigClient(), exchange);
break;
+ case putConformancePack:
+ putConformancePack(getEndpoint().getConfigClient(), exchange);
+ break;
default:
throw new IllegalArgumentException("Unsupported operation");
}
@@ -209,6 +212,57 @@ public class AWSConfigProducer extends DefaultProducer {
}
}
+ private void putConformancePack(ConfigClient configClient, Exchange exchange) throws InvalidPayloadException {
+ if (getConfiguration().isPojoRequest()) {
+ Object payload = exchange.getIn().getMandatoryBody();
+ if (payload instanceof PutConformancePackRequest) {
+ PutConformancePackResponse result;
+ try {
+ PutConformancePackRequest request = (PutConformancePackRequest) payload;
+ result = configClient.putConformancePack(request);
+ } catch (AwsServiceException ase) {
+ LOG.trace("Put Conformance Pack command returned the error code {}", ase.awsErrorDetails().errorCode());
+ throw ase;
+ }
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ }
+ } else {
+ PutConformancePackRequest.Builder builder = PutConformancePackRequest.builder();
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWSConfigConstants.CONFORMACE_PACK_NAME))) {
+ String conformancePackName = exchange.getIn().getHeader(AWSConfigConstants.CONFORMACE_PACK_NAME, String.class);
+ builder.conformancePackName(conformancePackName);
+ } else {
+ throw new IllegalArgumentException("Rule Name must be specified");
+ }
+ String conformancePackS3TemplateUri = null;
+ String conformancePackTemplateBody = null;
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWSConfigConstants.CONFORMACE_PACK_S3_TEMPLATE_URI))) {
+ conformancePackS3TemplateUri
+ = exchange.getIn().getHeader(AWSConfigConstants.CONFORMACE_PACK_S3_TEMPLATE_URI, String.class);
+ builder.templateS3Uri(conformancePackS3TemplateUri);
+ }
+ if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWSConfigConstants.CONFORMACE_PACK_TEMPLATE_BODY))) {
+ conformancePackTemplateBody
+ = exchange.getIn().getHeader(AWSConfigConstants.CONFORMACE_PACK_TEMPLATE_BODY, String.class);
+ builder.templateBody(conformancePackTemplateBody);
+ }
+ if (ObjectHelper.isEmpty(conformancePackS3TemplateUri) && ObjectHelper.isEmpty(conformancePackTemplateBody)) {
+ throw new IllegalArgumentException("One of Conformace Pack S3 Template URI or Template Body must be specified");
+ }
+ PutConformancePackResponse result;
+ try {
+ PutConformancePackRequest request = builder.build();
+ result = configClient.putConformancePack(request);
+ } catch (AwsServiceException ase) {
+ LOG.trace("Put Conformance Pack 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();
}