This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch aws-config-component in repository https://gitbox.apache.org/repos/asf/camel.git
commit bf7d9d86e8c9d0575d29ba566c435bd3e29df4d8 Author: Andrea Cosentino <[email protected]> AuthorDate: Mon Nov 27 11:52:44 2023 +0100 CAMEL-20157 - Add a Camel-AWS-Config component Signed-off-by: Andrea Cosentino <[email protected]> --- catalog/camel-allcomponents/pom.xml | 5 + components/camel-aws/camel-aws-config/pom.xml | 71 ++++++ .../aws/config/AWSConfigComponentConfigurer.java | 166 ++++++++++++++ .../aws/config/AWSConfigEndpointConfigurer.java | 138 ++++++++++++ .../aws/config/AWSConfigEndpointUriFactory.java | 87 ++++++++ .../services/org/apache/camel/component.properties | 7 + .../services/org/apache/camel/component/aws-config | 2 + .../apache/camel/configurer/aws-config-component | 2 + .../apache/camel/configurer/aws-config-endpoint | 2 + .../apache/camel/urifactory/aws-config-endpoint | 2 + .../camel/component/aws/config/aws-config.json | 71 ++++++ .../src/main/docs/aws2-ecs-component.adoc | 79 +++++++ .../component/aws/config/AWSConfigComponent.java | 71 ++++++ .../aws/config/AWSConfigConfiguration.java | 244 +++++++++++++++++++++ .../component/aws/config/AWSConfigConstants.java | 34 +++ .../component/aws/config/AWSConfigEndpoint.java | 89 ++++++++ .../component/aws/config/AWSConfigOperations.java | 23 ++ .../component/aws/config/AWSConfigProducer.java | 201 +++++++++++++++++ .../aws/config/AWSConfigProducerHealthCheck.java | 71 ++++++ .../aws/config/client/AWSConfigClientFactory.java | 47 ++++ .../aws/config/client/AWSConfigInternalClient.java | 32 +++ .../impl/AWSConfigClientIAMOptimizedImpl.java | 93 ++++++++ .../AWSConfigClientIAMProfileOptimizedImpl.java | 98 +++++++++ .../client/impl/AWSConfigClientStandardImpl.java | 109 +++++++++ .../aws/config/AWSConfigClientFactoryTest.java | 51 +++++ ...SConfigProducerHealthCheckProfileCredsTest.java | 99 +++++++++ ...WSConfigProducerHealthCheckStaticCredsTest.java | 99 +++++++++ .../integration/AWSConfigProducerManualIT.java | 88 ++++++++ .../src/test/resources/log4j2.properties | 28 +++ parent/pom.xml | 5 + 30 files changed, 2114 insertions(+) diff --git a/catalog/camel-allcomponents/pom.xml b/catalog/camel-allcomponents/pom.xml index 4f900d74593..8a9d2cb1a8a 100644 --- a/catalog/camel-allcomponents/pom.xml +++ b/catalog/camel-allcomponents/pom.xml @@ -122,6 +122,11 @@ <artifactId>camel-aws-cloudtrail</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws-config</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws-secrets-manager</artifactId> diff --git a/components/camel-aws/camel-aws-config/pom.xml b/components/camel-aws/camel-aws-config/pom.xml new file mode 100644 index 00000000000..c9146924215 --- /dev/null +++ b/components/camel-aws/camel-aws-config/pom.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws-parent</artifactId> + <version>4.3.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-aws-config</artifactId> + <packaging>jar</packaging> + + <name>Camel :: AWS Config</name> + <description>Execute different operations on AWS Config Service</description> + + <properties> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-support</artifactId> + </dependency> + <dependency> + <groupId>software.amazon.awssdk</groupId> + <artifactId>config</artifactId> + <version>${aws-java-sdk2-version}</version> + </dependency> + <dependency> + <groupId>software.amazon.awssdk</groupId> + <artifactId>apache-client</artifactId> + <version>${aws-java-sdk2-version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-health</artifactId> + </dependency> + + <!-- for testing --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <version>${awaitility-version}</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/components/camel-aws/camel-aws-config/src/generated/java/org/apache/camel/component/aws/config/AWSConfigComponentConfigurer.java b/components/camel-aws/camel-aws-config/src/generated/java/org/apache/camel/component/aws/config/AWSConfigComponentConfigurer.java new file mode 100644 index 00000000000..a2679d80efd --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/generated/java/org/apache/camel/component/aws/config/AWSConfigComponentConfigurer.java @@ -0,0 +1,166 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.component.aws.config; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.ExtendedPropertyConfigurerGetter; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.spi.ConfigurerStrategy; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.support.component.PropertyConfigurerSupport; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class AWSConfigComponentConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + private org.apache.camel.component.aws.config.AWSConfigConfiguration getOrCreateConfiguration(AWSConfigComponent target) { + if (target.getConfiguration() == null) { + target.setConfiguration(new org.apache.camel.component.aws.config.AWSConfigConfiguration()); + } + return target.getConfiguration(); + } + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + AWSConfigComponent target = (AWSConfigComponent) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true; + case "autowiredenabled": + case "autowiredEnabled": target.setAutowiredEnabled(property(camelContext, boolean.class, value)); return true; + case "configclient": + case "configClient": getOrCreateConfiguration(target).setConfigClient(property(camelContext, software.amazon.awssdk.services.config.ConfigClient.class, value)); return true; + case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.aws.config.AWSConfigConfiguration.class, value)); return true; + case "healthcheckconsumerenabled": + case "healthCheckConsumerEnabled": target.setHealthCheckConsumerEnabled(property(camelContext, boolean.class, value)); return true; + case "healthcheckproducerenabled": + case "healthCheckProducerEnabled": target.setHealthCheckProducerEnabled(property(camelContext, boolean.class, value)); return true; + case "lazystartproducer": + case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; + case "operation": getOrCreateConfiguration(target).setOperation(property(camelContext, org.apache.camel.component.aws.config.AWSConfigOperations.class, value)); return true; + case "overrideendpoint": + case "overrideEndpoint": getOrCreateConfiguration(target).setOverrideEndpoint(property(camelContext, boolean.class, value)); return true; + case "pojorequest": + case "pojoRequest": getOrCreateConfiguration(target).setPojoRequest(property(camelContext, boolean.class, value)); return true; + case "profilecredentialsname": + case "profileCredentialsName": getOrCreateConfiguration(target).setProfileCredentialsName(property(camelContext, java.lang.String.class, value)); return true; + case "proxyhost": + case "proxyHost": getOrCreateConfiguration(target).setProxyHost(property(camelContext, java.lang.String.class, value)); return true; + case "proxyport": + case "proxyPort": getOrCreateConfiguration(target).setProxyPort(property(camelContext, java.lang.Integer.class, value)); return true; + case "proxyprotocol": + case "proxyProtocol": getOrCreateConfiguration(target).setProxyProtocol(property(camelContext, software.amazon.awssdk.core.Protocol.class, value)); return true; + case "region": getOrCreateConfiguration(target).setRegion(property(camelContext, java.lang.String.class, value)); return true; + case "secretkey": + case "secretKey": getOrCreateConfiguration(target).setSecretKey(property(camelContext, java.lang.String.class, value)); return true; + case "trustallcertificates": + case "trustAllCertificates": getOrCreateConfiguration(target).setTrustAllCertificates(property(camelContext, boolean.class, value)); return true; + case "uriendpointoverride": + case "uriEndpointOverride": getOrCreateConfiguration(target).setUriEndpointOverride(property(camelContext, java.lang.String.class, value)); return true; + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": getOrCreateConfiguration(target).setUseDefaultCredentialsProvider(property(camelContext, boolean.class, value)); return true; + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": getOrCreateConfiguration(target).setUseProfileCredentialsProvider(property(camelContext, boolean.class, value)); return true; + default: return false; + } + } + + @Override + public String[] getAutowiredNames() { + return new String[]{"configClient"}; + } + + @Override + public Class<?> getOptionType(String name, boolean ignoreCase) { + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": return java.lang.String.class; + case "autowiredenabled": + case "autowiredEnabled": return boolean.class; + case "configclient": + case "configClient": return software.amazon.awssdk.services.config.ConfigClient.class; + case "configuration": return org.apache.camel.component.aws.config.AWSConfigConfiguration.class; + case "healthcheckconsumerenabled": + case "healthCheckConsumerEnabled": return boolean.class; + case "healthcheckproducerenabled": + case "healthCheckProducerEnabled": return boolean.class; + case "lazystartproducer": + case "lazyStartProducer": return boolean.class; + case "operation": return org.apache.camel.component.aws.config.AWSConfigOperations.class; + case "overrideendpoint": + case "overrideEndpoint": return boolean.class; + case "pojorequest": + case "pojoRequest": return boolean.class; + case "profilecredentialsname": + case "profileCredentialsName": return java.lang.String.class; + case "proxyhost": + case "proxyHost": return java.lang.String.class; + case "proxyport": + case "proxyPort": return java.lang.Integer.class; + case "proxyprotocol": + case "proxyProtocol": return software.amazon.awssdk.core.Protocol.class; + case "region": return java.lang.String.class; + case "secretkey": + case "secretKey": return java.lang.String.class; + case "trustallcertificates": + case "trustAllCertificates": return boolean.class; + case "uriendpointoverride": + case "uriEndpointOverride": return java.lang.String.class; + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": return boolean.class; + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": return boolean.class; + default: return null; + } + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + AWSConfigComponent target = (AWSConfigComponent) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); + case "autowiredenabled": + case "autowiredEnabled": return target.isAutowiredEnabled(); + case "configclient": + case "configClient": return getOrCreateConfiguration(target).getConfigClient(); + case "configuration": return target.getConfiguration(); + case "healthcheckconsumerenabled": + case "healthCheckConsumerEnabled": return target.isHealthCheckConsumerEnabled(); + case "healthcheckproducerenabled": + case "healthCheckProducerEnabled": return target.isHealthCheckProducerEnabled(); + case "lazystartproducer": + case "lazyStartProducer": return target.isLazyStartProducer(); + case "operation": return getOrCreateConfiguration(target).getOperation(); + case "overrideendpoint": + case "overrideEndpoint": return getOrCreateConfiguration(target).isOverrideEndpoint(); + case "pojorequest": + case "pojoRequest": return getOrCreateConfiguration(target).isPojoRequest(); + case "profilecredentialsname": + case "profileCredentialsName": return getOrCreateConfiguration(target).getProfileCredentialsName(); + case "proxyhost": + case "proxyHost": return getOrCreateConfiguration(target).getProxyHost(); + case "proxyport": + case "proxyPort": return getOrCreateConfiguration(target).getProxyPort(); + case "proxyprotocol": + case "proxyProtocol": return getOrCreateConfiguration(target).getProxyProtocol(); + case "region": return getOrCreateConfiguration(target).getRegion(); + case "secretkey": + case "secretKey": return getOrCreateConfiguration(target).getSecretKey(); + case "trustallcertificates": + case "trustAllCertificates": return getOrCreateConfiguration(target).isTrustAllCertificates(); + case "uriendpointoverride": + case "uriEndpointOverride": return getOrCreateConfiguration(target).getUriEndpointOverride(); + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": return getOrCreateConfiguration(target).isUseDefaultCredentialsProvider(); + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": return getOrCreateConfiguration(target).isUseProfileCredentialsProvider(); + default: return null; + } + } +} + diff --git a/components/camel-aws/camel-aws-config/src/generated/java/org/apache/camel/component/aws/config/AWSConfigEndpointConfigurer.java b/components/camel-aws/camel-aws-config/src/generated/java/org/apache/camel/component/aws/config/AWSConfigEndpointConfigurer.java new file mode 100644 index 00000000000..6d2df0d76f8 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/generated/java/org/apache/camel/component/aws/config/AWSConfigEndpointConfigurer.java @@ -0,0 +1,138 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.component.aws.config; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.ExtendedPropertyConfigurerGetter; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.spi.ConfigurerStrategy; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.support.component.PropertyConfigurerSupport; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class AWSConfigEndpointConfigurer extends PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + AWSConfigEndpoint target = (AWSConfigEndpoint) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.class, value)); return true; + case "configclient": + case "configClient": target.getConfiguration().setConfigClient(property(camelContext, software.amazon.awssdk.services.config.ConfigClient.class, value)); return true; + case "lazystartproducer": + case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; + case "operation": target.getConfiguration().setOperation(property(camelContext, org.apache.camel.component.aws.config.AWSConfigOperations.class, value)); return true; + case "overrideendpoint": + case "overrideEndpoint": target.getConfiguration().setOverrideEndpoint(property(camelContext, boolean.class, value)); return true; + case "pojorequest": + case "pojoRequest": target.getConfiguration().setPojoRequest(property(camelContext, boolean.class, value)); return true; + case "profilecredentialsname": + case "profileCredentialsName": target.getConfiguration().setProfileCredentialsName(property(camelContext, java.lang.String.class, value)); return true; + case "proxyhost": + case "proxyHost": target.getConfiguration().setProxyHost(property(camelContext, java.lang.String.class, value)); return true; + case "proxyport": + case "proxyPort": target.getConfiguration().setProxyPort(property(camelContext, java.lang.Integer.class, value)); return true; + case "proxyprotocol": + case "proxyProtocol": target.getConfiguration().setProxyProtocol(property(camelContext, software.amazon.awssdk.core.Protocol.class, value)); return true; + case "region": target.getConfiguration().setRegion(property(camelContext, java.lang.String.class, value)); return true; + case "secretkey": + case "secretKey": target.getConfiguration().setSecretKey(property(camelContext, java.lang.String.class, value)); return true; + case "trustallcertificates": + case "trustAllCertificates": target.getConfiguration().setTrustAllCertificates(property(camelContext, boolean.class, value)); return true; + case "uriendpointoverride": + case "uriEndpointOverride": target.getConfiguration().setUriEndpointOverride(property(camelContext, java.lang.String.class, value)); return true; + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": target.getConfiguration().setUseDefaultCredentialsProvider(property(camelContext, boolean.class, value)); return true; + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": target.getConfiguration().setUseProfileCredentialsProvider(property(camelContext, boolean.class, value)); return true; + default: return false; + } + } + + @Override + public String[] getAutowiredNames() { + return new String[]{"configClient"}; + } + + @Override + public Class<?> getOptionType(String name, boolean ignoreCase) { + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": return java.lang.String.class; + case "configclient": + case "configClient": return software.amazon.awssdk.services.config.ConfigClient.class; + case "lazystartproducer": + case "lazyStartProducer": return boolean.class; + case "operation": return org.apache.camel.component.aws.config.AWSConfigOperations.class; + case "overrideendpoint": + case "overrideEndpoint": return boolean.class; + case "pojorequest": + case "pojoRequest": return boolean.class; + case "profilecredentialsname": + case "profileCredentialsName": return java.lang.String.class; + case "proxyhost": + case "proxyHost": return java.lang.String.class; + case "proxyport": + case "proxyPort": return java.lang.Integer.class; + case "proxyprotocol": + case "proxyProtocol": return software.amazon.awssdk.core.Protocol.class; + case "region": return java.lang.String.class; + case "secretkey": + case "secretKey": return java.lang.String.class; + case "trustallcertificates": + case "trustAllCertificates": return boolean.class; + case "uriendpointoverride": + case "uriEndpointOverride": return java.lang.String.class; + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": return boolean.class; + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": return boolean.class; + default: return null; + } + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + AWSConfigEndpoint target = (AWSConfigEndpoint) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "accesskey": + case "accessKey": return target.getConfiguration().getAccessKey(); + case "configclient": + case "configClient": return target.getConfiguration().getConfigClient(); + case "lazystartproducer": + case "lazyStartProducer": return target.isLazyStartProducer(); + case "operation": return target.getConfiguration().getOperation(); + case "overrideendpoint": + case "overrideEndpoint": return target.getConfiguration().isOverrideEndpoint(); + case "pojorequest": + case "pojoRequest": return target.getConfiguration().isPojoRequest(); + case "profilecredentialsname": + case "profileCredentialsName": return target.getConfiguration().getProfileCredentialsName(); + case "proxyhost": + case "proxyHost": return target.getConfiguration().getProxyHost(); + case "proxyport": + case "proxyPort": return target.getConfiguration().getProxyPort(); + case "proxyprotocol": + case "proxyProtocol": return target.getConfiguration().getProxyProtocol(); + case "region": return target.getConfiguration().getRegion(); + case "secretkey": + case "secretKey": return target.getConfiguration().getSecretKey(); + case "trustallcertificates": + case "trustAllCertificates": return target.getConfiguration().isTrustAllCertificates(); + case "uriendpointoverride": + case "uriEndpointOverride": return target.getConfiguration().getUriEndpointOverride(); + case "usedefaultcredentialsprovider": + case "useDefaultCredentialsProvider": return target.getConfiguration().isUseDefaultCredentialsProvider(); + case "useprofilecredentialsprovider": + case "useProfileCredentialsProvider": return target.getConfiguration().isUseProfileCredentialsProvider(); + default: return null; + } + } +} + diff --git a/components/camel-aws/camel-aws-config/src/generated/java/org/apache/camel/component/aws/config/AWSConfigEndpointUriFactory.java b/components/camel-aws/camel-aws-config/src/generated/java/org/apache/camel/component/aws/config/AWSConfigEndpointUriFactory.java new file mode 100644 index 00000000000..ca52f7b0d6d --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/generated/java/org/apache/camel/component/aws/config/AWSConfigEndpointUriFactory.java @@ -0,0 +1,87 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.component.aws.config; + +import java.net.URISyntaxException; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.camel.spi.EndpointUriFactory; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +public class AWSConfigEndpointUriFactory extends org.apache.camel.support.component.EndpointUriFactorySupport implements EndpointUriFactory { + + private static final String BASE = ":label"; + + private static final Set<String> PROPERTY_NAMES; + private static final Set<String> SECRET_PROPERTY_NAMES; + private static final Set<String> MULTI_VALUE_PREFIXES; + static { + Set<String> props = new HashSet<>(17); + props.add("accessKey"); + props.add("configClient"); + props.add("label"); + props.add("lazyStartProducer"); + props.add("operation"); + props.add("overrideEndpoint"); + props.add("pojoRequest"); + props.add("profileCredentialsName"); + props.add("proxyHost"); + props.add("proxyPort"); + props.add("proxyProtocol"); + props.add("region"); + props.add("secretKey"); + props.add("trustAllCertificates"); + props.add("uriEndpointOverride"); + props.add("useDefaultCredentialsProvider"); + props.add("useProfileCredentialsProvider"); + PROPERTY_NAMES = Collections.unmodifiableSet(props); + Set<String> secretProps = new HashSet<>(2); + secretProps.add("accessKey"); + secretProps.add("secretKey"); + SECRET_PROPERTY_NAMES = Collections.unmodifiableSet(secretProps); + MULTI_VALUE_PREFIXES = Collections.emptySet(); + } + + @Override + public boolean isEnabled(String scheme) { + return "aws-config".equals(scheme); + } + + @Override + public String buildUri(String scheme, Map<String, Object> properties, boolean encode) throws URISyntaxException { + String syntax = scheme + BASE; + String uri = syntax; + + Map<String, Object> copy = new HashMap<>(properties); + + uri = buildPathParameter(syntax, uri, "label", null, true, copy); + uri = buildQueryParameters(uri, copy, encode); + return uri; + } + + @Override + public Set<String> propertyNames() { + return PROPERTY_NAMES; + } + + @Override + public Set<String> secretPropertyNames() { + return SECRET_PROPERTY_NAMES; + } + + @Override + public Set<String> multiValuePrefixes() { + return MULTI_VALUE_PREFIXES; + } + + @Override + public boolean isLenientProperties() { + return false; + } +} + diff --git a/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/component.properties b/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/component.properties new file mode 100644 index 00000000000..ae6254f808f --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/component.properties @@ -0,0 +1,7 @@ +# Generated by camel build tools - do NOT edit this file! +components=aws-config +groupId=org.apache.camel +artifactId=camel-aws-config +version=4.3.0-SNAPSHOT +projectName=Camel :: AWS Config +projectDescription=Execute different operations on AWS Config Service diff --git a/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/component/aws-config b/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/component/aws-config new file mode 100644 index 00000000000..fcd55400d3e --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/component/aws-config @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.aws.config.AWSConfigComponent diff --git a/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-config-component b/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-config-component new file mode 100644 index 00000000000..60de351b64f --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-config-component @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.aws.config.AWSConfigComponentConfigurer diff --git a/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-config-endpoint b/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-config-endpoint new file mode 100644 index 00000000000..1bac768035e --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/configurer/aws-config-endpoint @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.aws.config.AWSConfigEndpointConfigurer diff --git a/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/urifactory/aws-config-endpoint b/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/urifactory/aws-config-endpoint new file mode 100644 index 00000000000..b794bce1af2 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/generated/resources/META-INF/services/org/apache/camel/urifactory/aws-config-endpoint @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.component.aws.config.AWSConfigEndpointUriFactory 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 new file mode 100644 index 00000000000..07b96787c2b --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/generated/resources/org/apache/camel/component/aws/config/aws-config.json @@ -0,0 +1,71 @@ +{ + "component": { + "kind": "component", + "name": "aws-config", + "title": "AWS Config Service", + "description": "Manage AWS ECS cluster instances.", + "deprecated": false, + "firstVersion": "4.3.0", + "label": "cloud,management", + "javaType": "org.apache.camel.component.aws.config.AWSConfigComponent", + "supportLevel": "Preview", + "groupId": "org.apache.camel", + "artifactId": "camel-aws-config", + "version": "4.3.0-SNAPSHOT", + "scheme": "aws-config", + "extendsScheme": "", + "syntax": "aws-config:label", + "async": false, + "api": false, + "consumerOnly": false, + "producerOnly": true, + "lenientProperties": false + }, + "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": [...] + "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 [...] + "uriEndpointOverride": { "index": 6, "kind": "property", "displayName": "Uri Endpoint Override", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Set the overriding uri endpoint. This option needs to be used in combination with overrid [...] + "autowiredEnabled": { "index": 7, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...] + "configClient": { "index": 8, "kind": "property", "displayName": "Config Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.config.ConfigClient", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Amazon AWS Config Client instance" }, + "healthCheckConsumerEnabled": { "index": 9, "kind": "property", "displayName": "Health Check Consumer Enabled", "group": "health", "label": "health", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Used for enabling or disabling all consumer based health checks from this component" }, + "healthCheckProducerEnabled": { "index": 10, "kind": "property", "displayName": "Health Check Producer Enabled", "group": "health", "label": "health", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on produce [...] + "proxyHost": { "index": 11, "kind": "property", "displayName": "Proxy Host", "group": "proxy", "label": "proxy", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the ECS client" }, + "proxyPort": { "index": 12, "kind": "property", "displayName": "Proxy Port", "group": "proxy", "label": "proxy", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "To define a proxy port when instantiating the ECS client" }, + "proxyProtocol": { "index": 13, "kind": "property", "displayName": "Proxy Protocol", "group": "proxy", "label": "proxy", "required": false, "type": "object", "javaType": "software.amazon.awssdk.core.Protocol", "enum": [ "HTTP", "HTTPS" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "HTTPS", "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "To define a proxy protoco [...] + "accessKey": { "index": 14, "kind": "property", "displayName": "Access Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, + "profileCredentialsName": { "index": 15, "kind": "property", "displayName": "Profile Credentials Name", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "If using a profile credentials provider this parameter will set the profil [...] + "secretKey": { "index": 16, "kind": "property", "displayName": "Secret Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" }, + "trustAllCertificates": { "index": 17, "kind": "property", "displayName": "Trust All Certificates", "group": "security", "label": "security", "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 trust all certificates in case of overriding the [...] + "useDefaultCredentialsProvider": { "index": 18, "kind": "property", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "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 whether the ECS client should expect to [...] + "useProfileCredentialsProvider": { "index": 19, "kind": "property", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "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 whether the ECS client should expect to [...] + }, + "headers": { + "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" } + }, + "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": [...] + "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 [...] + "uriEndpointOverride": { "index": 5, "kind": "parameter", "displayName": "Uri Endpoint Override", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Set the overriding uri endpoint. This option needs to be used in combination with overri [...] + "lazyStartProducer": { "index": 6, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "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 produc [...] + "configClient": { "index": 7, "kind": "parameter", "displayName": "Config Client", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.config.ConfigClient", "deprecated": false, "deprecationNote": "", "autowired": true, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Amazon AWS Config Client instance" }, + "proxyHost": { "index": 8, "kind": "parameter", "displayName": "Proxy Host", "group": "proxy", "label": "proxy", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the ECS client" }, + "proxyPort": { "index": 9, "kind": "parameter", "displayName": "Proxy Port", "group": "proxy", "label": "proxy", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "To define a proxy port when instantiating the ECS client" }, + "proxyProtocol": { "index": 10, "kind": "parameter", "displayName": "Proxy Protocol", "group": "proxy", "label": "proxy", "required": false, "type": "object", "javaType": "software.amazon.awssdk.core.Protocol", "enum": [ "HTTP", "HTTPS" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "HTTPS", "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "To define a proxy protoc [...] + "accessKey": { "index": 11, "kind": "parameter", "displayName": "Access Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, + "profileCredentialsName": { "index": 12, "kind": "parameter", "displayName": "Profile Credentials Name", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "If using a profile credentials provider this parameter will set the profi [...] + "secretKey": { "index": 13, "kind": "parameter", "displayName": "Secret Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws.config.AWSConfigConfiguration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" }, + "trustAllCertificates": { "index": 14, "kind": "parameter", "displayName": "Trust All Certificates", "group": "security", "label": "security", "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 trust all certificates in case of overriding the [...] + "useDefaultCredentialsProvider": { "index": 15, "kind": "parameter", "displayName": "Use Default Credentials Provider", "group": "security", "label": "security", "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 whether the ECS client should expect to [...] + "useProfileCredentialsProvider": { "index": 16, "kind": "parameter", "displayName": "Use Profile Credentials Provider", "group": "security", "label": "security", "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 whether the ECS client should expect to [...] + } +} diff --git a/components/camel-aws/camel-aws-config/src/main/docs/aws2-ecs-component.adoc b/components/camel-aws/camel-aws-config/src/main/docs/aws2-ecs-component.adoc new file mode 100644 index 00000000000..9be931e9680 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/docs/aws2-ecs-component.adoc @@ -0,0 +1,79 @@ += AWS Elastic Container Service (ECS) Component +:doctitle: AWS Elastic Container Service (ECS) +:shortname: aws2-ecs +:artifactid: camel-aws2-ecs +:description: Manage AWS ECS cluster instances. +:since: 3.1 +:supportlevel: Stable +:tabs-sync-option: +:component-header: Only producer is supported +//Manually maintained attributes +:group: AWS +:camel-spring-boot-name: aws2-ecs + +*Since Camel {since}* + +*{component-header}* + +The AWS Config component supports create and delete config rules +https://aws.amazon.com/config/[AWS ECS] clusters instances. + +Prerequisites + +You must have a valid Amazon Web Services developer account, and be +signed up to use Amazon Config. More information is available at +https://aws.amazon.com/config/[Amazon Config]. + +== URI Format + +------------------------- +aws-config://label[?options] +------------------------- + +You can append query options to the URI in the following format, +?options=value&option2=value&... + + +// component-configure options: START + +// component-configure options: END + +// component options: START +include::partial$component-configure-options.adoc[] +include::partial$component-endpoint-options.adoc[] +// component options: END + +// endpoint options: START + +// endpoint options: END + +Required ECS component options + +You have to provide the ConfigClient in the +Registry or your accessKey and secretKey to access +the https://aws.amazon.com/config/[Amazon Config] service. + +== Usage + +=== Static credentials, Default Credential Provider and Profile Credentials Provider + +You have the possibility of avoiding the usage of explicit static credentials, by specifying the useDefaultCredentialsProvider option and set it to true. + +The order of evaluation for Default Credentials Provider is the following: + + - Java system properties - aws.accessKeyId and aws.secretKey + - Environment variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. + - Web Identity Token from AWS STS. + - The shared credentials and config files. + - Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set. + - Amazon EC2 Instance profile credentials. + +You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name. + +Only one of static, default and profile credentials could be used at the same time. + +For more information about this you can look at https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials.html[AWS credentials documentation] + +// component headers: START +include::partial$component-endpoint-headers.adoc[] +// component headers: END diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigComponent.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigComponent.java new file mode 100644 index 00000000000..1c0af0e8134 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigComponent.java @@ -0,0 +1,71 @@ +/* + * 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.config; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.HealthCheckComponent; + +/** + * For working with Amazon Config SDK v2. + */ +@Component("aws-config") +public class AWSConfigComponent extends HealthCheckComponent { + + @Metadata + private AWSConfigConfiguration configuration = new AWSConfigConfiguration(); + + public AWSConfigComponent() { + this(null); + } + + public AWSConfigComponent(CamelContext context) { + super(context); + } + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + AWSConfigConfiguration configuration + = this.configuration != null ? this.configuration.copy() : new AWSConfigConfiguration(); + AWSConfigEndpoint endpoint = new AWSConfigEndpoint(uri, this, configuration); + setProperties(endpoint, parameters); + if (Boolean.FALSE.equals(configuration.isUseDefaultCredentialsProvider()) + && Boolean.FALSE.equals(configuration.isUseProfileCredentialsProvider()) + && configuration.getConfigClient() == null + && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { + throw new IllegalArgumentException( + "useDefaultCredentialsProvider is set to false, useProfileCredentialsProvider is set to false, Amazon ecs client or accessKey and secretKey must be specified"); + } + + return endpoint; + } + + public AWSConfigConfiguration getConfiguration() { + return configuration; + } + + /** + * Component configuration + */ + public void setConfiguration(AWSConfigConfiguration configuration) { + this.configuration = configuration; + } +} diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigConfiguration.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigConfiguration.java new file mode 100644 index 00000000000..eb36e393bb1 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigConfiguration.java @@ -0,0 +1,244 @@ +/* + * 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.config; + +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.apache.camel.spi.UriPath; +import software.amazon.awssdk.core.Protocol; +import software.amazon.awssdk.services.config.ConfigClient; + +@UriParams +public class AWSConfigConfiguration implements Cloneable { + + @UriPath(description = "Logical name") + @Metadata(required = true) + private String label; + @UriParam + @Metadata(label = "advanced", autowired = true) + private ConfigClient configClient; + @UriParam(label = "security", secret = true) + private String accessKey; + @UriParam(label = "security", secret = true) + private String secretKey; + @UriParam + @Metadata(required = true) + private AWSConfigOperations operation; + @UriParam(label = "proxy", enums = "HTTP,HTTPS", defaultValue = "HTTPS") + private Protocol proxyProtocol = Protocol.HTTPS; + @UriParam(label = "proxy") + private String proxyHost; + @UriParam(label = "proxy") + private Integer proxyPort; + @UriParam(enums = "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-northeast-1,me-south-1,sa-east-1,ap-east-1,cn-north-1,us-gov-west-1,ap-southeast-1,ap-southeast-2,us-iso-east-1,ap-southeast-3,ap-southeast-4,us-east-1,us-east-2,cn-northwest-1,us-isob-east-1,aws-global,aws-cn-global,aws-us-gov [...] + private String region; + @UriParam + private boolean pojoRequest; + @UriParam(label = "security") + private boolean trustAllCertificates; + @UriParam + private boolean overrideEndpoint; + @UriParam + private String uriEndpointOverride; + @UriParam(label = "security") + private boolean useDefaultCredentialsProvider; + @UriParam(label = "security") + private boolean useProfileCredentialsProvider; + @UriParam(label = "security") + private String profileCredentialsName; + + public ConfigClient getConfigClient() { + return configClient; + } + + /** + * Amazon AWS Config Client instance + */ + public void setConfigClient(ConfigClient configClient) { + this.configClient = configClient; + } + + public String getAccessKey() { + return accessKey; + } + + /** + * Amazon AWS Access Key + */ + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + /** + * Amazon AWS Secret Key + */ + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public AWSConfigOperations getOperation() { + return operation; + } + + /** + * The operation to perform + */ + public void setOperation(AWSConfigOperations operation) { + this.operation = operation; + } + + public Protocol getProxyProtocol() { + return proxyProtocol; + } + + /** + * To define a proxy protocol when instantiating the ECS client + */ + public void setProxyProtocol(Protocol proxyProtocol) { + this.proxyProtocol = proxyProtocol; + } + + public String getProxyHost() { + return proxyHost; + } + + /** + * To define a proxy host when instantiating the ECS client + */ + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + public Integer getProxyPort() { + return proxyPort; + } + + /** + * To define a proxy port when instantiating the ECS client + */ + public void setProxyPort(Integer proxyPort) { + this.proxyPort = proxyPort; + } + + public String getRegion() { + return region; + } + + /** + * The region in which ECS client needs to work. When using this parameter, the configuration will expect the + * lowercase name of the region (for example ap-east-1) You'll need to use the name Region.EU_WEST_1.id() + */ + public void setRegion(String region) { + this.region = region; + } + + public boolean isPojoRequest() { + return pojoRequest; + } + + /** + * If we want to use a POJO request as body or not + */ + public void setPojoRequest(boolean pojoRequest) { + this.pojoRequest = pojoRequest; + } + + public boolean isTrustAllCertificates() { + return trustAllCertificates; + } + + /** + * If we want to trust all certificates in case of overriding the endpoint + */ + public void setTrustAllCertificates(boolean trustAllCertificates) { + this.trustAllCertificates = trustAllCertificates; + } + + public boolean isOverrideEndpoint() { + return overrideEndpoint; + } + + /** + * Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride + * option + */ + public void setOverrideEndpoint(boolean overrideEndpoint) { + this.overrideEndpoint = overrideEndpoint; + } + + public String getUriEndpointOverride() { + return uriEndpointOverride; + } + + /** + * Set the overriding uri endpoint. This option needs to be used in combination with overrideEndpoint option + */ + public void setUriEndpointOverride(String uriEndpointOverride) { + this.uriEndpointOverride = uriEndpointOverride; + } + + /** + * Set whether the ECS client should expect to load credentials through a default credentials provider or to expect + * static credentials to be passed in. + */ + public void setUseDefaultCredentialsProvider(Boolean useDefaultCredentialsProvider) { + this.useDefaultCredentialsProvider = useDefaultCredentialsProvider; + } + + public Boolean isUseDefaultCredentialsProvider() { + return useDefaultCredentialsProvider; + } + + public boolean isUseProfileCredentialsProvider() { + return useProfileCredentialsProvider; + } + + /** + * Set whether the ECS client should expect to load credentials through a profile credentials provider. + */ + public void setUseProfileCredentialsProvider(boolean useProfileCredentialsProvider) { + this.useProfileCredentialsProvider = useProfileCredentialsProvider; + } + + public String getProfileCredentialsName() { + return profileCredentialsName; + } + + /** + * If using a profile credentials provider this parameter will set the profile name + */ + public void setProfileCredentialsName(String profileCredentialsName) { + this.profileCredentialsName = profileCredentialsName; + } + // ************************************************* + // + // ************************************************* + + public AWSConfigConfiguration copy() { + try { + return (AWSConfigConfiguration) super.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeCamelException(e); + } + } +} 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 new file mode 100644 index 00000000000..0a5a902dfb2 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigConstants.java @@ -0,0 +1,34 @@ +/* + * 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.config; + +import org.apache.camel.spi.Metadata; + +/** + * Constants used in Camel AWS Config module + */ +public interface AWSConfigConstants { + @Metadata(description = "The operation we want to perform", javaType = "String") + String OPERATION = "CamelAwsConfigOperation"; + @Metadata(description = "The Managed rule source identifier", javaType = "String") + String RULE_SOURCE_IDENTIFIER = "CamelAwsConfigRuleSourceIdentifier"; + @Metadata(description = "The source object for the rule. The owner of the rule could be AWS, CUSTOM_LAMBDA or CUSTOM_POLICY", + javaType = "String") + String SOURCE = "CamelAwsConfigRuleSource"; + @Metadata(description = "The Managed rule name", javaType = "String") + String RULE_NAME = "CamelAwsConfigRuleName"; +} diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigEndpoint.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigEndpoint.java new file mode 100644 index 00000000000..2b153d53f47 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigEndpoint.java @@ -0,0 +1,89 @@ +/* + * 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.config; + +import org.apache.camel.Category; +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.component.aws.config.client.AWSConfigClientFactory; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.support.DefaultEndpoint; +import org.apache.camel.util.ObjectHelper; +import software.amazon.awssdk.services.config.ConfigClient; + +/** + * Manage AWS ECS cluster instances. + */ +@UriEndpoint(firstVersion = "4.3.0", scheme = "aws-config", title = "AWS Config Service", + syntax = "aws-config:label", producerOnly = true, category = { Category.CLOUD, Category.MANAGEMENT }, + headersClass = AWSConfigConstants.class) +public class AWSConfigEndpoint extends DefaultEndpoint { + + private ConfigClient configClient; + + @UriParam + private AWSConfigConfiguration configuration; + + public AWSConfigEndpoint(String uri, Component component, AWSConfigConfiguration configuration) { + super(uri, component); + this.configuration = configuration; + } + + @Override + public AWSConfigComponent getComponent() { + return (AWSConfigComponent) super.getComponent(); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + throw new UnsupportedOperationException("You cannot receive messages from this endpoint"); + } + + @Override + public Producer createProducer() throws Exception { + return new AWSConfigProducer(this); + } + + @Override + public void doStart() throws Exception { + super.doStart(); + + configClient = configuration.getConfigClient() != null + ? configuration.getConfigClient() : AWSConfigClientFactory.getConfigClient(configuration).getConfigClient(); + } + + @Override + public void doStop() throws Exception { + if (ObjectHelper.isEmpty(configuration.getConfigClient())) { + if (configClient != null) { + configClient.close(); + } + } + super.doStop(); + } + + public AWSConfigConfiguration getConfiguration() { + return configuration; + } + + public ConfigClient getConfigClient() { + return configClient; + } +} 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 new file mode 100644 index 00000000000..e8aa2424401 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigOperations.java @@ -0,0 +1,23 @@ +/* + * 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.config; + +public enum AWSConfigOperations { + + putConfigRule, + removeConfigRule +} 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 new file mode 100644 index 00000000000..c8883b12863 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducer.java @@ -0,0 +1,201 @@ +/* + * 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.config; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.InvalidPayloadException; +import org.apache.camel.Message; +import org.apache.camel.health.HealthCheck; +import org.apache.camel.health.HealthCheckHelper; +import org.apache.camel.health.WritableHealthCheckRepository; +import org.apache.camel.support.DefaultProducer; +import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.URISupport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.awscore.exception.AwsServiceException; +import software.amazon.awssdk.services.config.ConfigClient; +import software.amazon.awssdk.services.config.model.*; + +/** + * A Producer which sends messages to the Amazon Config Service SDK v2 <a href="http://aws.amazon.com/config/">AWS + * Config</a> + */ +public class AWSConfigProducer extends DefaultProducer { + + private static final Logger LOG = LoggerFactory.getLogger(AWSConfigProducer.class); + + private transient String configProducerToString; + private HealthCheck producerHealthCheck; + private WritableHealthCheckRepository healthCheckRepository; + + public AWSConfigProducer(Endpoint endpoint) { + super(endpoint); + } + + @Override + public void process(Exchange exchange) throws Exception { + switch (determineOperation(exchange)) { + case putConfigRule: + putConfigRule(getEndpoint().getConfigClient(), exchange); + break; + case removeConfigRule: + removeConfigRule(getEndpoint().getConfigClient(), exchange); + break; + default: + throw new IllegalArgumentException("Unsupported operation"); + } + } + + private AWSConfigOperations determineOperation(Exchange exchange) { + AWSConfigOperations operation = exchange.getIn().getHeader(AWSConfigConstants.OPERATION, AWSConfigOperations.class); + if (operation == null) { + operation = getConfiguration().getOperation(); + } + return operation; + } + + protected AWSConfigConfiguration getConfiguration() { + return getEndpoint().getConfiguration(); + } + + @Override + public String toString() { + if (configProducerToString == null) { + configProducerToString = "AWSConfigProducer[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]"; + } + return configProducerToString; + } + + @Override + public AWSConfigEndpoint getEndpoint() { + return (AWSConfigEndpoint) super.getEndpoint(); + } + + private void putConfigRule(ConfigClient configClient, Exchange exchange) throws InvalidPayloadException { + if (getConfiguration().isPojoRequest()) { + Object payload = exchange.getIn().getMandatoryBody(); + if (payload instanceof PutConfigRuleRequest) { + PutConfigRuleResponse result; + try { + PutConfigRuleRequest request = (PutConfigRuleRequest) payload; + result = configClient.putConfigRule(request); + } catch (AwsServiceException ase) { + LOG.trace("Put Config rule command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } else { + PutConfigRuleRequest.Builder builder = PutConfigRuleRequest.builder(); + ConfigRule.Builder configRule = ConfigRule.builder(); + Source.Builder source = Source.builder(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWSConfigConstants.SOURCE))) { + String sourceString = exchange.getIn().getHeader(AWSConfigConstants.SOURCE, String.class); + source.owner(sourceString); + } else { + throw new IllegalArgumentException("Source Owner must be specified"); + } + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWSConfigConstants.RULE_SOURCE_IDENTIFIER))) { + String ruleId = exchange.getIn().getHeader(AWSConfigConstants.RULE_SOURCE_IDENTIFIER, String.class); + source.sourceIdentifier(ruleId); + } + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWSConfigConstants.RULE_NAME))) { + String ruleName = exchange.getIn().getHeader(AWSConfigConstants.RULE_NAME, String.class); + configRule.configRuleName(ruleName); + } + configRule.source(source.build()); + PutConfigRuleResponse result; + try { + PutConfigRuleRequest request = builder.configRule(configRule.build()).build(); + result = configClient.putConfigRule(request); + } catch (AwsServiceException ase) { + LOG.trace("Put Config Rule command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } + + private void removeConfigRule(ConfigClient configClient, Exchange exchange) throws InvalidPayloadException { + if (getConfiguration().isPojoRequest()) { + Object payload = exchange.getIn().getMandatoryBody(); + if (payload instanceof DeleteConfigRuleRequest) { + DeleteConfigRuleResponse result; + try { + DeleteConfigRuleRequest request = (DeleteConfigRuleRequest) payload; + result = configClient.deleteConfigRule(request); + } catch (AwsServiceException ase) { + LOG.trace("Delete Config rule command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } else { + DeleteConfigRuleRequest.Builder builder = DeleteConfigRuleRequest.builder(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(AWSConfigConstants.RULE_NAME))) { + String ruleName = exchange.getIn().getHeader(AWSConfigConstants.RULE_NAME, String.class); + builder.configRuleName(ruleName); + } else { + throw new IllegalArgumentException("Rule Name must be specified"); + } + DeleteConfigRuleResponse result; + try { + DeleteConfigRuleRequest request = builder.build(); + result = configClient.deleteConfigRule(request); + } catch (AwsServiceException ase) { + LOG.trace("Delete 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(); + } + + @Override + protected void doStart() throws Exception { + // health-check is optional so discover and resolve + healthCheckRepository = HealthCheckHelper.getHealthCheckRepository( + getEndpoint().getCamelContext(), + "producers", + WritableHealthCheckRepository.class); + + if (healthCheckRepository != null) { + String id = getEndpoint().getId(); + producerHealthCheck = new AWSConfigProducerHealthCheck(getEndpoint(), id); + producerHealthCheck.setEnabled(getEndpoint().getComponent().isHealthCheckProducerEnabled()); + healthCheckRepository.addHealthCheck(producerHealthCheck); + } + } + + @Override + protected void doStop() throws Exception { + if (healthCheckRepository != null && producerHealthCheck != null) { + healthCheckRepository.removeHealthCheck(producerHealthCheck); + producerHealthCheck = null; + } + } + +} diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducerHealthCheck.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducerHealthCheck.java new file mode 100644 index 00000000000..8b33b067d21 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/AWSConfigProducerHealthCheck.java @@ -0,0 +1,71 @@ +/* + * 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.config; + +import java.util.Map; + +import org.apache.camel.health.HealthCheckResultBuilder; +import org.apache.camel.impl.health.AbstractHealthCheck; +import org.apache.camel.util.ObjectHelper; +import software.amazon.awssdk.awscore.exception.AwsServiceException; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.config.ConfigClient; +import software.amazon.awssdk.services.config.model.ListDiscoveredResourcesRequest; + +public class AWSConfigProducerHealthCheck extends AbstractHealthCheck { + + private final AWSConfigEndpoint configEndpoint; + + public AWSConfigProducerHealthCheck(AWSConfigEndpoint configEndpoint, String clientId) { + super("camel", "producer:aws-config-" + clientId); + this.configEndpoint = configEndpoint; + } + + @Override + protected void doCall(HealthCheckResultBuilder builder, Map<String, Object> options) { + AWSConfigConfiguration configuration = configEndpoint.getConfiguration(); + if (ObjectHelper.isNotEmpty(configuration.getRegion())) { + if (!ConfigClient.serviceMetadata().regions().contains(Region.of(configuration.getRegion()))) { + builder.message("The service is not supported in this region"); + builder.down(); + return; + } + } + try { + ConfigClient configClient = configEndpoint.getConfigClient(); + configClient.listDiscoveredResources(ListDiscoveredResourcesRequest.builder().build()); + } catch (AwsServiceException e) { + builder.message(e.getMessage()); + builder.error(e); + if (ObjectHelper.isNotEmpty(e.statusCode())) { + builder.detail(SERVICE_STATUS_CODE, e.statusCode()); + } + if (ObjectHelper.isNotEmpty(e.awsErrorDetails().errorCode())) { + builder.detail(SERVICE_ERROR_CODE, e.awsErrorDetails().errorCode()); + } + builder.down(); + return; + } catch (Exception e) { + builder.error(e); + builder.down(); + return; + } + builder.up(); + } + +} diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/AWSConfigClientFactory.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/AWSConfigClientFactory.java new file mode 100644 index 00000000000..4f3119ab7ca --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/AWSConfigClientFactory.java @@ -0,0 +1,47 @@ +/* + * 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.config.client; + +import org.apache.camel.component.aws.config.AWSConfigConfiguration; +import org.apache.camel.component.aws.config.client.impl.AWSConfigClientIAMOptimizedImpl; +import org.apache.camel.component.aws.config.client.impl.AWSConfigClientIAMProfileOptimizedImpl; +import org.apache.camel.component.aws.config.client.impl.AWSConfigClientStandardImpl; + +/** + * Factory class to return the correct type of AWS Config client. + */ +public final class AWSConfigClientFactory { + + private AWSConfigClientFactory() { + } + + /** + * Return the correct AWS Config client (based on remote vs local). + * + * @param configuration configuration + * @return ConfigClient + */ + public static AWSConfigInternalClient getConfigClient(AWSConfigConfiguration configuration) { + if (Boolean.TRUE.equals(configuration.isUseDefaultCredentialsProvider())) { + return new AWSConfigClientIAMOptimizedImpl(configuration); + } else if (Boolean.TRUE.equals(configuration.isUseProfileCredentialsProvider())) { + return new AWSConfigClientIAMProfileOptimizedImpl(configuration); + } else { + return new AWSConfigClientStandardImpl(configuration); + } + } +} diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/AWSConfigInternalClient.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/AWSConfigInternalClient.java new file mode 100644 index 00000000000..f77cabfb0b4 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/AWSConfigInternalClient.java @@ -0,0 +1,32 @@ +/* + * 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.config.client; + +import software.amazon.awssdk.services.config.ConfigClient; + +/** + * Manage the required actions of a Config client for either local or remote. + */ +public interface AWSConfigInternalClient { + + /** + * Returns a Config client after a factory method determines which one to return. + * + * @return ConfigClient ConfigClient + */ + ConfigClient getConfigClient(); +} diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/impl/AWSConfigClientIAMOptimizedImpl.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/impl/AWSConfigClientIAMOptimizedImpl.java new file mode 100644 index 00000000000..0ca273f9554 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/impl/AWSConfigClientIAMOptimizedImpl.java @@ -0,0 +1,93 @@ +/* + * 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.config.client.impl; + +import java.net.URI; + +import org.apache.camel.component.aws.config.AWSConfigConfiguration; +import org.apache.camel.component.aws.config.client.AWSConfigInternalClient; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.SdkHttpConfigurationOption; +import software.amazon.awssdk.http.apache.ApacheHttpClient; +import software.amazon.awssdk.http.apache.ProxyConfiguration; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.config.ConfigClient; +import software.amazon.awssdk.services.config.ConfigClientBuilder; +import software.amazon.awssdk.utils.AttributeMap; + +/** + * Manage an AWS Config client for all users to use (enabling temporary creds). This implementation is for remote + * instances to manage the credentials on their own (eliminating credential rotations) + */ +public class AWSConfigClientIAMOptimizedImpl implements AWSConfigInternalClient { + private static final Logger LOG = LoggerFactory.getLogger(AWSConfigClientIAMOptimizedImpl.class); + private AWSConfigConfiguration configuration; + + /** + * Constructor that uses the config file. + */ + public AWSConfigClientIAMOptimizedImpl(AWSConfigConfiguration configuration) { + LOG.trace("Creating an AWS Config client for an ec2 instance with IAM temporary credentials (normal for ec2s)."); + this.configuration = configuration; + } + + /** + * Getting the Config aws client that is used. + * + * @return ConfigClient Client. + */ + @Override + public ConfigClient getConfigClient() { + ConfigClient client = null; + ConfigClientBuilder clientBuilder = ConfigClient.builder(); + ProxyConfiguration.Builder proxyConfig = null; + ApacheHttpClient.Builder httpClientBuilder = null; + if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { + proxyConfig = ProxyConfiguration.builder(); + URI proxyEndpoint = URI.create(configuration.getProxyProtocol() + "://" + configuration.getProxyHost() + ":" + + configuration.getProxyPort()); + proxyConfig.endpoint(proxyEndpoint); + httpClientBuilder = ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build()); + clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder); + } + if (ObjectHelper.isNotEmpty(configuration.getRegion())) { + clientBuilder = clientBuilder.region(Region.of(configuration.getRegion())); + } + if (configuration.isOverrideEndpoint()) { + clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride())); + } + if (configuration.isTrustAllCertificates()) { + if (httpClientBuilder == null) { + httpClientBuilder = ApacheHttpClient.builder(); + } + SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap + .builder() + .put( + SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, + Boolean.TRUE) + .build()); + // set created http client to use instead of builder + clientBuilder.httpClient(ahc); + clientBuilder.httpClientBuilder(null); + } + client = clientBuilder.build(); + return client; + } +} diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/impl/AWSConfigClientIAMProfileOptimizedImpl.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/impl/AWSConfigClientIAMProfileOptimizedImpl.java new file mode 100644 index 00000000000..fb5bc657e41 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/impl/AWSConfigClientIAMProfileOptimizedImpl.java @@ -0,0 +1,98 @@ +/* + * 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.config.client.impl; + +import java.net.URI; + +import org.apache.camel.component.aws.config.AWSConfigConfiguration; +import org.apache.camel.component.aws.config.client.AWSConfigInternalClient; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.SdkHttpConfigurationOption; +import software.amazon.awssdk.http.apache.ApacheHttpClient; +import software.amazon.awssdk.http.apache.ProxyConfiguration; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.config.ConfigClient; +import software.amazon.awssdk.services.config.ConfigClientBuilder; +import software.amazon.awssdk.utils.AttributeMap; + +/** + * Manage an AWS Config client for all users to use (enabling temporary creds). This implementation is for remote + * instances to manage the credentials on their own (eliminating credential rotations) + */ +public class AWSConfigClientIAMProfileOptimizedImpl implements AWSConfigInternalClient { + private static final Logger LOG = LoggerFactory.getLogger(AWSConfigClientIAMProfileOptimizedImpl.class); + private AWSConfigConfiguration configuration; + + /** + * Constructor that uses the config file. + */ + public AWSConfigClientIAMProfileOptimizedImpl(AWSConfigConfiguration configuration) { + LOG.trace("Creating an AWS Config client for an ec2 instance with IAM temporary credentials (normal for ec2s)."); + this.configuration = configuration; + } + + /** + * Getting the Config aws client that is used. + * + * @return ConfigClient Client. + */ + @Override + public ConfigClient getConfigClient() { + ConfigClient client = null; + ConfigClientBuilder clientBuilder = ConfigClient.builder(); + ProxyConfiguration.Builder proxyConfig = null; + ApacheHttpClient.Builder httpClientBuilder = null; + if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { + proxyConfig = ProxyConfiguration.builder(); + URI proxyEndpoint = URI.create(configuration.getProxyProtocol() + "://" + configuration.getProxyHost() + ":" + + configuration.getProxyPort()); + proxyConfig.endpoint(proxyEndpoint); + httpClientBuilder = ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build()); + clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder); + } + if (configuration.getProfileCredentialsName() != null) { + clientBuilder = clientBuilder + .credentialsProvider(ProfileCredentialsProvider.create(configuration.getProfileCredentialsName())); + } + if (ObjectHelper.isNotEmpty(configuration.getRegion())) { + clientBuilder = clientBuilder.region(Region.of(configuration.getRegion())); + } + if (configuration.isOverrideEndpoint()) { + clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride())); + } + if (configuration.isTrustAllCertificates()) { + if (httpClientBuilder == null) { + httpClientBuilder = ApacheHttpClient.builder(); + } + SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap + .builder() + .put( + SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, + Boolean.TRUE) + .build()); + // set created http client to use instead of builder + clientBuilder.httpClient(ahc); + clientBuilder.httpClientBuilder(null); + } + client = clientBuilder.build(); + return client; + } +} diff --git a/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/impl/AWSConfigClientStandardImpl.java b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/impl/AWSConfigClientStandardImpl.java new file mode 100644 index 00000000000..741c3967df6 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/main/java/org/apache/camel/component/aws/config/client/impl/AWSConfigClientStandardImpl.java @@ -0,0 +1,109 @@ +/* + * 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.config.client.impl; + +import java.net.URI; + +import org.apache.camel.component.aws.config.AWSConfigConfiguration; +import org.apache.camel.component.aws.config.client.AWSConfigInternalClient; +import org.apache.camel.util.ObjectHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.SdkHttpConfigurationOption; +import software.amazon.awssdk.http.apache.ApacheHttpClient; +import software.amazon.awssdk.http.apache.ProxyConfiguration; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.config.ConfigClient; +import software.amazon.awssdk.services.config.ConfigClientBuilder; +import software.amazon.awssdk.utils.AttributeMap; + +/** + * Manage an AWS Config client for all users to use. This implementation is for local instances to use a static and + * solid credential set. + */ +public class AWSConfigClientStandardImpl implements AWSConfigInternalClient { + private static final Logger LOG = LoggerFactory.getLogger(AWSConfigClientStandardImpl.class); + private AWSConfigConfiguration configuration; + + /** + * Constructor that uses the config file. + */ + public AWSConfigClientStandardImpl(AWSConfigConfiguration configuration) { + LOG.trace("Creating an AWS ECS manager using static credentials."); + this.configuration = configuration; + } + + /** + * Getting the Config AWS client that is used. + * + * @return Amazon Config Client. + */ + @Override + public ConfigClient getConfigClient() { + ConfigClient client = null; + ConfigClientBuilder clientBuilder = ConfigClient.builder(); + ProxyConfiguration.Builder proxyConfig = null; + ApacheHttpClient.Builder httpClientBuilder = null; + boolean isClientConfigFound = false; + if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) { + proxyConfig = ProxyConfiguration.builder(); + URI proxyEndpoint = URI.create(configuration.getProxyProtocol() + "://" + configuration.getProxyHost() + ":" + + configuration.getProxyPort()); + proxyConfig.endpoint(proxyEndpoint); + httpClientBuilder = ApacheHttpClient.builder().proxyConfiguration(proxyConfig.build()); + isClientConfigFound = true; + } + if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) { + AwsBasicCredentials cred = AwsBasicCredentials.create(configuration.getAccessKey(), configuration.getSecretKey()); + if (isClientConfigFound) { + clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder) + .credentialsProvider(StaticCredentialsProvider.create(cred)); + } else { + clientBuilder = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred)); + } + } else { + if (!isClientConfigFound) { + clientBuilder = clientBuilder.httpClientBuilder(httpClientBuilder); + } + } + if (ObjectHelper.isNotEmpty(configuration.getRegion())) { + clientBuilder = clientBuilder.region(Region.of(configuration.getRegion())); + } + if (configuration.isOverrideEndpoint()) { + clientBuilder.endpointOverride(URI.create(configuration.getUriEndpointOverride())); + } + if (configuration.isTrustAllCertificates()) { + if (httpClientBuilder == null) { + httpClientBuilder = ApacheHttpClient.builder(); + } + SdkHttpClient ahc = httpClientBuilder.buildWithDefaults(AttributeMap + .builder() + .put( + SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, + Boolean.TRUE) + .build()); + // set created http client to use instead of builder + clientBuilder.httpClient(ahc); + clientBuilder.httpClientBuilder(null); + } + client = clientBuilder.build(); + return client; + } +} diff --git a/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigClientFactoryTest.java b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigClientFactoryTest.java new file mode 100644 index 00000000000..d3a0dcfc1d3 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigClientFactoryTest.java @@ -0,0 +1,51 @@ +/* + * 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.config; + +import org.apache.camel.component.aws.config.client.AWSConfigClientFactory; +import org.apache.camel.component.aws.config.client.AWSConfigInternalClient; +import org.apache.camel.component.aws.config.client.impl.AWSConfigClientIAMOptimizedImpl; +import org.apache.camel.component.aws.config.client.impl.AWSConfigClientStandardImpl; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class AWSConfigClientFactoryTest { + + @Test + public void getStandardECS2ClientDefault() { + AWSConfigConfiguration configConfiguration = new AWSConfigConfiguration(); + AWSConfigInternalClient configClient = AWSConfigClientFactory.getConfigClient(configConfiguration); + assertTrue(configClient instanceof AWSConfigClientStandardImpl); + } + + @Test + public void getStandardECS2Client() { + AWSConfigConfiguration configConfiguration = new AWSConfigConfiguration(); + configConfiguration.setUseDefaultCredentialsProvider(false); + AWSConfigInternalClient configClient = AWSConfigClientFactory.getConfigClient(configConfiguration); + assertTrue(configClient instanceof AWSConfigClientStandardImpl); + } + + @Test + public void getIAMOptimizedECS2Client() { + AWSConfigConfiguration configConfiguration = new AWSConfigConfiguration(); + configConfiguration.setUseDefaultCredentialsProvider(true); + AWSConfigInternalClient configClient = AWSConfigClientFactory.getConfigClient(configConfiguration); + assertTrue(configClient instanceof AWSConfigClientIAMOptimizedImpl); + } +} diff --git a/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigProducerHealthCheckProfileCredsTest.java b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigProducerHealthCheckProfileCredsTest.java new file mode 100644 index 00000000000..c69492f91be --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigProducerHealthCheckProfileCredsTest.java @@ -0,0 +1,99 @@ +/* + * 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.config; + +import java.util.Collection; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.health.HealthCheck; +import org.apache.camel.health.HealthCheckHelper; +import org.apache.camel.health.HealthCheckRegistry; +import org.apache.camel.health.HealthCheckRepository; +import org.apache.camel.impl.health.DefaultHealthCheckRegistry; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.awaitility.Awaitility.await; + +public class AWSConfigProducerHealthCheckProfileCredsTest extends CamelTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(AWSConfigProducerHealthCheckProfileCredsTest.class); + + CamelContext context; + + @Override + protected CamelContext createCamelContext() throws Exception { + context = super.createCamelContext(); + context.getPropertiesComponent().setLocation("ref:prop"); + + // install health check manually (yes a bit cumbersome) + HealthCheckRegistry registry = new DefaultHealthCheckRegistry(); + registry.setCamelContext(context); + Object hc = registry.resolveById("context"); + registry.register(hc); + hc = registry.resolveById("routes"); + registry.register(hc); + hc = registry.resolveById("consumers"); + registry.register(hc); + HealthCheckRepository hcr = (HealthCheckRepository) registry.resolveById("producers"); + hcr.setEnabled(true); + registry.register(hcr); + context.getCamelContextExtension().addContextPlugin(HealthCheckRegistry.class, registry); + + return context; + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + + @Override + public void configure() { + from("direct:listClusters") + .to("aws-config://test?operation=putConfigRule®ion=l&useDefaultCredentialsProvider=true"); + } + }; + } + + @Test + public void testConnectivity() { + + Collection<HealthCheck.Result> res = HealthCheckHelper.invokeLiveness(context); + boolean up = res.stream().allMatch(r -> r.getState().equals(HealthCheck.State.UP)); + Assertions.assertTrue(up, "liveness check"); + + // health-check readiness should be down + await().atMost(20, TimeUnit.SECONDS).untilAsserted(() -> { + Collection<HealthCheck.Result> res2 = HealthCheckHelper.invokeReadiness(context); + boolean down = res2.stream().allMatch(r -> r.getState().equals(HealthCheck.State.DOWN)); + boolean containsAws2EcsHealthCheck = res2.stream() + .anyMatch(result -> result.getCheck().getId().startsWith("producer:aws-config")); + boolean hasRegionMessage = res2.stream() + .anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region"))); + Assertions.assertTrue(down, "liveness check"); + Assertions.assertTrue(containsAws2EcsHealthCheck, "aws2-ecs check"); + Assertions.assertTrue(hasRegionMessage, "aws2-ecs check error message"); + }); + + } +} diff --git a/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigProducerHealthCheckStaticCredsTest.java b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigProducerHealthCheckStaticCredsTest.java new file mode 100644 index 00000000000..af67f1127e7 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/AWSConfigProducerHealthCheckStaticCredsTest.java @@ -0,0 +1,99 @@ +/* + * 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.config; + +import java.util.Collection; +import java.util.concurrent.TimeUnit; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.health.HealthCheck; +import org.apache.camel.health.HealthCheckHelper; +import org.apache.camel.health.HealthCheckRegistry; +import org.apache.camel.health.HealthCheckRepository; +import org.apache.camel.impl.health.DefaultHealthCheckRegistry; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.awaitility.Awaitility.await; + +public class AWSConfigProducerHealthCheckStaticCredsTest extends CamelTestSupport { + + private static final Logger LOG = LoggerFactory.getLogger(AWSConfigProducerHealthCheckStaticCredsTest.class); + + CamelContext context; + + @Override + protected CamelContext createCamelContext() throws Exception { + context = super.createCamelContext(); + context.getPropertiesComponent().setLocation("ref:prop"); + + // install health check manually (yes a bit cumbersome) + HealthCheckRegistry registry = new DefaultHealthCheckRegistry(); + registry.setCamelContext(context); + Object hc = registry.resolveById("context"); + registry.register(hc); + hc = registry.resolveById("routes"); + registry.register(hc); + hc = registry.resolveById("consumers"); + registry.register(hc); + HealthCheckRepository hcr = (HealthCheckRepository) registry.resolveById("producers"); + hcr.setEnabled(true); + registry.register(hcr); + context.getCamelContextExtension().addContextPlugin(HealthCheckRegistry.class, registry); + + return context; + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + + @Override + public void configure() { + from("direct:listClusters") + .to("aws-config://test?operation=putConfigRule®ion=l&secretKey=l&accessKey=k"); + } + }; + } + + @Test + public void testConnectivity() { + + Collection<HealthCheck.Result> res = HealthCheckHelper.invokeLiveness(context); + boolean up = res.stream().allMatch(r -> r.getState().equals(HealthCheck.State.UP)); + Assertions.assertTrue(up, "liveness check"); + + // health-check readiness should be down + await().atMost(20, TimeUnit.SECONDS).untilAsserted(() -> { + Collection<HealthCheck.Result> res2 = HealthCheckHelper.invokeReadiness(context); + boolean down = res2.stream().allMatch(r -> r.getState().equals(HealthCheck.State.DOWN)); + boolean containsAws2EcsHealthCheck = res2.stream() + .anyMatch(result -> result.getCheck().getId().startsWith("producer:aws-config")); + boolean hasRegionMessage = res2.stream() + .anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region"))); + Assertions.assertTrue(down, "liveness check"); + Assertions.assertTrue(containsAws2EcsHealthCheck, "aws2-ecs check"); + Assertions.assertTrue(hasRegionMessage, "aws2-ecs check error message"); + }); + + } +} 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 new file mode 100644 index 00000000000..97f5f755e32 --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/test/java/org/apache/camel/component/aws/config/integration/AWSConfigProducerManualIT.java @@ -0,0 +1,88 @@ +/* + * 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.config.integration; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.aws.config.AWSConfigConstants; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit5.CamelTestSupport; +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.PutConfigRuleResponse; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +// Must be manually tested. Provide your own accessKey and secretKey using -Daws.manual.access.key and -Daws.manual.secret.key +@EnabledIfSystemProperties({ + @EnabledIfSystemProperty(named = "aws.manual.access.key", matches = ".*", disabledReason = "Access key not provided"), + @EnabledIfSystemProperty(named = "aws.manual.secret.key", matches = ".*", disabledReason = "Secret key not provided") +}) +public class AWSConfigProducerManualIT extends CamelTestSupport { + + @EndpointInject("mock:result") + private MockEndpoint mock; + + @Test + public void translateTextTest() { + + 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_LIFECYCLE_POLICY_CHECK"); + exchange.getMessage().setHeader(AWSConfigConstants.RULE_NAME, "Test"); + } + }); + + PutConfigRuleResponse resultGet = (PutConfigRuleResponse) exchange.getIn().getBody(); + assertTrue(resultGet.sdkHttpResponse().isSuccessful()); + + exchange = template.request("direct:removeConfigRule", new Processor() { + @Override + public void process(Exchange exchange) { + + exchange.getMessage().setHeader(AWSConfigConstants.RULE_NAME, "Test"); + } + }); + + DeleteConfigRuleResponse deleteResponse = (DeleteConfigRuleResponse) exchange.getIn().getBody(); + assertTrue(deleteResponse.sdkHttpResponse().isSuccessful()); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:putConfigRule") + .to("aws-config://test?accessKey=RAW({{aws.manual.access.key}})&secretKey=RAW({{aws.manual.secret.key}})®ion=eu-west-1&operation=putConfigRule") + .to("mock:result"); + + from("direct:removeConfigRule") + .to("aws-config://test?accessKey=RAW({{aws.manual.access.key}})&secretKey=RAW({{aws.manual.secret.key}})®ion=eu-west-1&operation=removeConfigRule") + .to("mock:result"); + } + }; + } +} diff --git a/components/camel-aws/camel-aws-config/src/test/resources/log4j2.properties b/components/camel-aws/camel-aws-config/src/test/resources/log4j2.properties new file mode 100644 index 00000000000..e21f367395e --- /dev/null +++ b/components/camel-aws/camel-aws-config/src/test/resources/log4j2.properties @@ -0,0 +1,28 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-aws-config-test.log +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +rootLogger.level = INFO +rootLogger.appenderRef.file.ref = file diff --git a/parent/pom.xml b/parent/pom.xml index 16a3eca99c6..3a5922ab9b3 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -718,6 +718,11 @@ <artifactId>camel-aws-cloudtrail</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-aws-config</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-aws-secrets-manager</artifactId>
