This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit b429a8f15b5f9a160bf177fe6a41c8f20fcaeec1 Author: Andrea Cosentino <[email protected]> AuthorDate: Fri Dec 1 11:08:01 2023 +0100 Camel-AWS-Config: Add a Delete Conformance Pack Operation to Producer Signed-off-by: Andrea Cosentino <[email protected]> --- .../component/aws/config/AWSConfigOperations.java | 3 +- .../component/aws/config/AWSConfigProducer.java | 39 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) 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 7c215d10b4e..3abe50adffe 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 @@ -21,6 +21,7 @@ public enum AWSConfigOperations { putConfigRule, removeConfigRule, describeRuleCompliance, - putConformancePack + putConformancePack, + removeConformancePack } 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 f59031c940f..317be5b3bf6 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 @@ -63,6 +63,9 @@ public class AWSConfigProducer extends DefaultProducer { case putConformancePack: putConformancePack(getEndpoint().getConfigClient(), exchange); break; + case removeConformancePack: + removeConformancePack(getEndpoint().getConfigClient(), exchange); + break; default: throw new IllegalArgumentException("Unsupported operation"); } @@ -263,6 +266,42 @@ public class AWSConfigProducer extends DefaultProducer { } } + private void removeConformancePack(ConfigClient configClient, Exchange exchange) throws InvalidPayloadException { + if (getConfiguration().isPojoRequest()) { + Object payload = exchange.getIn().getMandatoryBody(); + if (payload instanceof DeleteConformancePackRequest) { + DeleteConformancePackResponse result; + try { + DeleteConformancePackRequest request = (DeleteConformancePackRequest) payload; + result = configClient.deleteConformancePack(request); + } catch (AwsServiceException ase) { + LOG.trace("Remove Conformance Pack rule command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } else { + DeleteConformancePackRequest.Builder builder = DeleteConformancePackRequest.builder(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWSConfigConstants.CONFORMACE_PACK_NAME))) { + String conformancePackName = exchange.getIn().getHeader(AWSConfigConstants.RULE_NAME, String.class); + builder.conformancePackName(conformancePackName); + } else { + throw new IllegalArgumentException("Conformance Pack Name must be specified"); + } + DeleteConformancePackResponse result; + try { + DeleteConformancePackRequest request = builder.build(); + result = configClient.deleteConformancePack(request); + } catch (AwsServiceException ase) { + LOG.trace("Remove 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(); }
