This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit c7e01a928a30d97c2173a7703c534b05ea20afe5 Author: Andrea Cosentino <[email protected]> AuthorDate: Thu Jul 23 09:27:38 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS-KMS --- .../component/aws/kms/KMSComponentConfigurer.java | 5 ++++ .../component/aws/kms/KMSEndpointConfigurer.java | 5 ++++ .../apache/camel/component/aws/kms/aws-kms.json | 2 ++ .../src/main/docs/aws-kms-component.adoc | 6 +++-- .../camel/component/aws/kms/KMSComponent.java | 4 +++- .../camel/component/aws/kms/KMSConfiguration.java | 15 ++++++++++++ .../aws/kms/KMSComponentClientRegistryTest.java | 25 +++++++++++++++++++ .../dsl/AwsKmsComponentBuilderFactory.java | 16 +++++++++++++ .../builder/endpoint/StaticEndpointBuilders.java | 8 +++---- .../endpoint/dsl/KMSEndpointBuilderFactory.java | 28 ++++++++++++++++++++++ 10 files changed, 107 insertions(+), 7 deletions(-) diff --git a/components/camel-aws-kms/src/generated/java/org/apache/camel/component/aws/kms/KMSComponentConfigurer.java b/components/camel-aws-kms/src/generated/java/org/apache/camel/component/aws/kms/KMSComponentConfigurer.java index 02776f7..469af65 100644 --- a/components/camel-aws-kms/src/generated/java/org/apache/camel/component/aws/kms/KMSComponentConfigurer.java +++ b/components/camel-aws-kms/src/generated/java/org/apache/camel/component/aws/kms/KMSComponentConfigurer.java @@ -28,6 +28,8 @@ public class KMSComponentConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true; + case "autodiscoverclient": + case "autoDiscoverClient": getOrCreateConfiguration(target).setAutoDiscoverClient(property(camelContext, boolean.class, value)); return true; case "basicpropertybinding": case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.aws.kms.KMSConfiguration.class, value)); return true; @@ -53,6 +55,7 @@ public class KMSComponentConfigurer extends PropertyConfigurerSupport implements public Map<String, Object> getAllOptions(Object target) { Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("configuration", org.apache.camel.component.aws.kms.KMSConfiguration.class); answer.put("kmsClient", com.amazonaws.services.kms.AWSKMS.class); @@ -72,6 +75,8 @@ public class KMSComponentConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); + case "autodiscoverclient": + case "autoDiscoverClient": return getOrCreateConfiguration(target).isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "configuration": return target.getConfiguration(); diff --git a/components/camel-aws-kms/src/generated/java/org/apache/camel/component/aws/kms/KMSEndpointConfigurer.java b/components/camel-aws-kms/src/generated/java/org/apache/camel/component/aws/kms/KMSEndpointConfigurer.java index 1ff79a3..e896e78 100644 --- a/components/camel-aws-kms/src/generated/java/org/apache/camel/component/aws/kms/KMSEndpointConfigurer.java +++ b/components/camel-aws-kms/src/generated/java/org/apache/camel/component/aws/kms/KMSEndpointConfigurer.java @@ -21,6 +21,8 @@ public class KMSEndpointConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.class, value)); return true; + case "autodiscoverclient": + case "autoDiscoverClient": target.getConfiguration().setAutoDiscoverClient(property(camelContext, boolean.class, value)); return true; case "basicpropertybinding": case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; case "kmsclient": @@ -46,6 +48,7 @@ public class KMSEndpointConfigurer extends PropertyConfigurerSupport implements public Map<String, Object> getAllOptions(Object target) { Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("kmsClient", com.amazonaws.services.kms.AWSKMS.class); answer.put("lazyStartProducer", boolean.class); @@ -65,6 +68,8 @@ public class KMSEndpointConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": return target.getConfiguration().getAccessKey(); + case "autodiscoverclient": + case "autoDiscoverClient": return target.getConfiguration().isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "kmsclient": diff --git a/components/camel-aws-kms/src/generated/resources/org/apache/camel/component/aws/kms/aws-kms.json b/components/camel-aws-kms/src/generated/resources/org/apache/camel/component/aws/kms/aws-kms.json index 5eed283..81492b5 100644 --- a/components/camel-aws-kms/src/generated/resources/org/apache/camel/component/aws/kms/aws-kms.json +++ b/components/camel-aws-kms/src/generated/resources/org/apache/camel/component/aws/kms/aws-kms.json @@ -21,6 +21,7 @@ "lenientProperties": false }, "componentProperties": { + "autoDiscoverClient": { "kind": "property", "displayName": "Auto Discover Client", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "true", "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry [...] "accessKey": { "kind": "property", "displayName": "Access Key", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": true, "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.kms.KMSConfiguration", "deprecated": false, "secret": false, "description": "The Component configuration" }, "kmsClient": { "kind": "property", "displayName": "Kms Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.kms.AWSKMS", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "description": "To use a existing configured AWS KMS as client" }, @@ -35,6 +36,7 @@ }, "properties": { "label": { "kind": "path", "displayName": "Label", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "description": "Logical name" }, + "autoDiscoverClient": { "kind": "parameter", "displayName": "Auto Discover Client", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "true", "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registr [...] "accessKey": { "kind": "parameter", "displayName": "Access Key", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": true, "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "kmsClient": { "kind": "parameter", "displayName": "Kms Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.kms.AWSKMS", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "description": "To use a existing configured AWS KMS as client" }, "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": 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 during starting and cause the [...] diff --git a/components/camel-aws-kms/src/main/docs/aws-kms-component.adoc b/components/camel-aws-kms/src/main/docs/aws-kms-component.adoc index 88195aa..275e347 100644 --- a/components/camel-aws-kms/src/main/docs/aws-kms-component.adoc +++ b/components/camel-aws-kms/src/main/docs/aws-kms-component.adoc @@ -36,13 +36,14 @@ You can append query options to the URI in the following format, // component options: START -The AWS Key Management Service (KMS) component supports 11 options, which are listed below. +The AWS Key Management Service (KMS) component supports 12 options, which are listed below. [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type +| *autoDiscoverClient* (common) | Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry automatically otherwise it will skip that checking. | true | boolean | *accessKey* (producer) | Amazon AWS Access Key | | String | *configuration* (producer) | The Component configuration | | KMSConfiguration | *kmsClient* (producer) | To use a existing configured AWS KMS as client | | AWSKMS @@ -79,12 +80,13 @@ with the following path and query parameters: |=== -=== Query Parameters (11 parameters): +=== Query Parameters (12 parameters): [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type +| *autoDiscoverClient* (common) | Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry automatically otherwise it will skip that checking. | true | boolean | *accessKey* (producer) | Amazon AWS Access Key | | String | *kmsClient* (producer) | To use a existing configured AWS KMS as client | | AWSKMS | *lazyStartProducer* (producer) | 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 during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] diff --git a/components/camel-aws-kms/src/main/java/org/apache/camel/component/aws/kms/KMSComponent.java b/components/camel-aws-kms/src/main/java/org/apache/camel/component/aws/kms/KMSComponent.java index fc2c1d2..44256e4 100644 --- a/components/camel-aws-kms/src/main/java/org/apache/camel/component/aws/kms/KMSComponent.java +++ b/components/camel-aws-kms/src/main/java/org/apache/camel/component/aws/kms/KMSComponent.java @@ -51,7 +51,9 @@ public class KMSComponent extends DefaultComponent { KMSEndpoint endpoint = new KMSEndpoint(uri, this, configuration); setProperties(endpoint, parameters); - checkAndSetRegistryClient(configuration); + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration); + } if (configuration.getKmsClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("Amazon kms client or accessKey and secretKey must be specified"); } diff --git a/components/camel-aws-kms/src/main/java/org/apache/camel/component/aws/kms/KMSConfiguration.java b/components/camel-aws-kms/src/main/java/org/apache/camel/component/aws/kms/KMSConfiguration.java index 91847dc..a0bb135 100644 --- a/components/camel-aws-kms/src/main/java/org/apache/camel/component/aws/kms/KMSConfiguration.java +++ b/components/camel-aws-kms/src/main/java/org/apache/camel/component/aws/kms/KMSConfiguration.java @@ -47,6 +47,8 @@ public class KMSConfiguration implements Cloneable { private Integer proxyPort; @UriParam private String region; + @UriParam(label = "common", defaultValue = "true") + private boolean autoDiscoverClient = true; public AWSKMS getKmsClient() { return kmsClient; @@ -137,6 +139,19 @@ public class KMSConfiguration implements Cloneable { this.region = region; } + public boolean isAutoDiscoverClient() { + return autoDiscoverClient; + } + + /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + */ + public void setAutoDiscoverClient(boolean autoDiscoverClient) { + this.autoDiscoverClient = autoDiscoverClient; + } + // ************************************************* // // ************************************************* diff --git a/components/camel-aws-kms/src/test/java/org/apache/camel/component/aws/kms/KMSComponentClientRegistryTest.java b/components/camel-aws-kms/src/test/java/org/apache/camel/component/aws/kms/KMSComponentClientRegistryTest.java index cac6b9b..ced2536 100644 --- a/components/camel-aws-kms/src/test/java/org/apache/camel/component/aws/kms/KMSComponentClientRegistryTest.java +++ b/components/camel-aws-kms/src/test/java/org/apache/camel/component/aws/kms/KMSComponentClientRegistryTest.java @@ -20,6 +20,8 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; public class KMSComponentClientRegistryTest extends CamelTestSupport { @@ -42,4 +44,27 @@ public class KMSComponentClientRegistryTest extends CamelTestSupport { assertThrows(IllegalArgumentException.class, () -> component.createEndpoint("aws-kms://TestDomain")); } + + @Test + public void createEndpointWithAutoDiscoverClientFalse() throws Exception { + + AmazonKMSClientMock clientMock = new AmazonKMSClientMock(); + context.getRegistry().bind("amazonKmsClient", clientMock); + KMSComponent component = context.getComponent("aws-kms", KMSComponent.class); + KMSEndpoint endpoint = (KMSEndpoint)component.createEndpoint("aws-kms://TestDomain?accessKey=xxx&secretKey=yyy®ion=eu-west-1&autoDiscoverClient=false"); + + assertNotSame(clientMock, endpoint.getConfiguration().getKmsClient()); + } + + @Test + public void createEndpointWithAutoDiscoverClientTrue() throws Exception { + + AmazonKMSClientMock clientMock = new AmazonKMSClientMock(); + context.getRegistry().bind("amazonKmsClient", clientMock); + KMSComponent component = context.getComponent("aws-kms", KMSComponent.class); + KMSEndpoint endpoint = (KMSEndpoint)component.createEndpoint("aws-kms://TestDomain?accessKey=xxx&secretKey=yyy®ion=eu-west-1"); + + assertNotNull(endpoint.getConfiguration().getKmsClient()); + assertSame(clientMock, endpoint.getConfiguration().getKmsClient()); + } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsKmsComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsKmsComponentBuilderFactory.java index 9696c3e..c15da15 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsKmsComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsKmsComponentBuilderFactory.java @@ -47,6 +47,21 @@ public interface AwsKmsComponentBuilderFactory { */ interface AwsKmsComponentBuilder extends ComponentBuilder<KMSComponent> { /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default AwsKmsComponentBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type. @@ -215,6 +230,7 @@ public interface AwsKmsComponentBuilderFactory { String name, Object value) { switch (name) { + case "autoDiscoverClient": getOrCreateConfiguration((KMSComponent) component).setAutoDiscoverClient((boolean) value); return true; case "accessKey": getOrCreateConfiguration((KMSComponent) component).setAccessKey((java.lang.String) value); return true; case "configuration": ((KMSComponent) component).setConfiguration((org.apache.camel.component.aws.kms.KMSConfiguration) value); return true; case "kmsClient": getOrCreateConfiguration((KMSComponent) component).setKmsClient((com.amazonaws.services.kms.AWSKMS) value); return true; diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java index 8f4a69d..5b8d333 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java @@ -1169,7 +1169,7 @@ public class StaticEndpointBuilders { * * @param path streamName */ - static org.apache.camel.builder.endpoint.dsl.Kinesis2EndpointBuilderFactory.Kinesis2EndpointBuilder aws2Kinesis( + public static org.apache.camel.builder.endpoint.dsl.Kinesis2EndpointBuilderFactory.Kinesis2EndpointBuilder aws2Kinesis( String path) { return org.apache.camel.builder.endpoint.dsl.Kinesis2EndpointBuilderFactory.endpointBuilder("aws2-kinesis", path); } @@ -1191,7 +1191,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path streamName */ - static org.apache.camel.builder.endpoint.dsl.Kinesis2EndpointBuilderFactory.Kinesis2EndpointBuilder aws2Kinesis( + public static org.apache.camel.builder.endpoint.dsl.Kinesis2EndpointBuilderFactory.Kinesis2EndpointBuilder aws2Kinesis( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.Kinesis2EndpointBuilderFactory.endpointBuilder(componentName, path); @@ -1996,7 +1996,7 @@ public class StaticEndpointBuilders { * * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.KMSEndpointBuilderFactory.KMSEndpointBuilder awsKms( + static org.apache.camel.builder.endpoint.dsl.KMSEndpointBuilderFactory.KMSEndpointBuilder awsKms( String path) { return org.apache.camel.builder.endpoint.dsl.KMSEndpointBuilderFactory.endpointBuilder("aws-kms", path); } @@ -2017,7 +2017,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.KMSEndpointBuilderFactory.KMSEndpointBuilder awsKms( + static org.apache.camel.builder.endpoint.dsl.KMSEndpointBuilderFactory.KMSEndpointBuilder awsKms( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.KMSEndpointBuilderFactory.endpointBuilder(componentName, path); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KMSEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KMSEndpointBuilderFactory.java index 091a205..a1e6dd6 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KMSEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/KMSEndpointBuilderFactory.java @@ -38,6 +38,34 @@ public interface KMSEndpointBuilderFactory { return (AdvancedKMSEndpointBuilder) this; } /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default KMSEndpointBuilder autoDiscoverClient(boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option will be converted to a <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default KMSEndpointBuilder autoDiscoverClient(String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type.
