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 c0acd275de634952fb63dd97c9570e499e5a001d Author: Andrea Cosentino <[email protected]> AuthorDate: Wed Jul 22 09:23:43 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS-IAM --- .../component/aws/iam/IAMComponentConfigurer.java | 5 ++++ .../component/aws/iam/IAMEndpointConfigurer.java | 5 ++++ .../apache/camel/component/aws/iam/aws-iam.json | 2 ++ .../src/main/docs/aws-iam-component.adoc | 6 +++-- .../camel/component/aws/iam/IAMComponent.java | 4 +++- .../camel/component/aws/iam/IAMConfiguration.java | 15 ++++++++++++ .../aws/iam/IAMComponentClientRegistryTest.java | 24 +++++++++++++++++++ .../dsl/AwsIamComponentBuilderFactory.java | 16 +++++++++++++ .../builder/endpoint/StaticEndpointBuilders.java | 8 +++---- .../endpoint/dsl/IAMEndpointBuilderFactory.java | 28 ++++++++++++++++++++++ 10 files changed, 106 insertions(+), 7 deletions(-) diff --git a/components/camel-aws-iam/src/generated/java/org/apache/camel/component/aws/iam/IAMComponentConfigurer.java b/components/camel-aws-iam/src/generated/java/org/apache/camel/component/aws/iam/IAMComponentConfigurer.java index 03de71a..cbc3254 100644 --- a/components/camel-aws-iam/src/generated/java/org/apache/camel/component/aws/iam/IAMComponentConfigurer.java +++ b/components/camel-aws-iam/src/generated/java/org/apache/camel/component/aws/iam/IAMComponentConfigurer.java @@ -28,6 +28,8 @@ public class IAMComponentConfigurer 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.iam.IAMConfiguration.class, value)); return true; @@ -53,6 +55,7 @@ public class IAMComponentConfigurer 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.iam.IAMConfiguration.class); answer.put("iamClient", com.amazonaws.services.identitymanagement.AmazonIdentityManagement.class); @@ -72,6 +75,8 @@ public class IAMComponentConfigurer 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-iam/src/generated/java/org/apache/camel/component/aws/iam/IAMEndpointConfigurer.java b/components/camel-aws-iam/src/generated/java/org/apache/camel/component/aws/iam/IAMEndpointConfigurer.java index 929f5cf..1f4e709 100644 --- a/components/camel-aws-iam/src/generated/java/org/apache/camel/component/aws/iam/IAMEndpointConfigurer.java +++ b/components/camel-aws-iam/src/generated/java/org/apache/camel/component/aws/iam/IAMEndpointConfigurer.java @@ -21,6 +21,8 @@ public class IAMEndpointConfigurer 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 "iamclient": @@ -46,6 +48,7 @@ public class IAMEndpointConfigurer 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("iamClient", com.amazonaws.services.identitymanagement.AmazonIdentityManagement.class); answer.put("lazyStartProducer", boolean.class); @@ -65,6 +68,8 @@ public class IAMEndpointConfigurer 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 "iamclient": diff --git a/components/camel-aws-iam/src/generated/resources/org/apache/camel/component/aws/iam/aws-iam.json b/components/camel-aws-iam/src/generated/resources/org/apache/camel/component/aws/iam/aws-iam.json index 3ba6555..3c67cc2 100644 --- a/components/camel-aws-iam/src/generated/resources/org/apache/camel/component/aws/iam/aws-iam.json +++ b/components/camel-aws-iam/src/generated/resources/org/apache/camel/component/aws/iam/aws-iam.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.iam.IAMConfiguration", "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.iam.IAMConfiguration", "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.iam.IAMConfiguration", "deprecated": false, "secret": false, "description": "The component configuration" }, "iamClient": { "kind": "property", "displayName": "Iam Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.identitymanagement.AmazonIdentityManagement", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.iam.IAMConfiguration", "configurationField": "configuration", "description": "To use a existing configured AWS IAM 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.iam.IAMConfiguration", "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.iam.IAMConfiguration", "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.iam.IAMConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "iamClient": { "kind": "parameter", "displayName": "Iam Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.identitymanagement.AmazonIdentityManagement", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.iam.IAMConfiguration", "configurationField": "configuration", "description": "To use a existing configured AWS IAM 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-iam/src/main/docs/aws-iam-component.adoc b/components/camel-aws-iam/src/main/docs/aws-iam-component.adoc index 1428c92..f4a0e56 100644 --- a/components/camel-aws-iam/src/main/docs/aws-iam-component.adoc +++ b/components/camel-aws-iam/src/main/docs/aws-iam-component.adoc @@ -36,13 +36,14 @@ You can append query options to the URI in the following format, // component options: START -The AWS Identity and Access Management (IAM) component supports 11 options, which are listed below. +The AWS Identity and Access Management (IAM) 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 | | IAMConfiguration | *iamClient* (producer) | To use a existing configured AWS IAM as client | | AmazonIdentityManagement @@ -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 | *iamClient* (producer) | To use a existing configured AWS IAM as client | | AmazonIdentityManagement | *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-iam/src/main/java/org/apache/camel/component/aws/iam/IAMComponent.java b/components/camel-aws-iam/src/main/java/org/apache/camel/component/aws/iam/IAMComponent.java index 44d6d1d..072087e 100644 --- a/components/camel-aws-iam/src/main/java/org/apache/camel/component/aws/iam/IAMComponent.java +++ b/components/camel-aws-iam/src/main/java/org/apache/camel/component/aws/iam/IAMComponent.java @@ -50,7 +50,9 @@ public class IAMComponent extends DefaultComponent { IAMConfiguration configuration = this.configuration != null ? this.configuration.copy() : new IAMConfiguration(); IAMEndpoint endpoint = new IAMEndpoint(uri, this, configuration); setProperties(endpoint, parameters); - checkAndSetRegistryClient(configuration); + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration); + } if (configuration.getIamClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("Amazon IAM client or accessKey and secretKey must be specified"); } diff --git a/components/camel-aws-iam/src/main/java/org/apache/camel/component/aws/iam/IAMConfiguration.java b/components/camel-aws-iam/src/main/java/org/apache/camel/component/aws/iam/IAMConfiguration.java index c98830d..eb87221 100644 --- a/components/camel-aws-iam/src/main/java/org/apache/camel/component/aws/iam/IAMConfiguration.java +++ b/components/camel-aws-iam/src/main/java/org/apache/camel/component/aws/iam/IAMConfiguration.java @@ -47,6 +47,8 @@ public class IAMConfiguration implements Cloneable { private Integer proxyPort; @UriParam private String region; + @UriParam(label = "common", defaultValue = "true") + private boolean autoDiscoverClient = true; public AmazonIdentityManagement getIamClient() { return iamClient; @@ -136,6 +138,19 @@ public class IAMConfiguration implements Cloneable { public void setRegion(String region) { 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-iam/src/test/java/org/apache/camel/component/aws/iam/IAMComponentClientRegistryTest.java b/components/camel-aws-iam/src/test/java/org/apache/camel/component/aws/iam/IAMComponentClientRegistryTest.java index 047f040..cc7c3ec 100644 --- a/components/camel-aws-iam/src/test/java/org/apache/camel/component/aws/iam/IAMComponentClientRegistryTest.java +++ b/components/camel-aws-iam/src/test/java/org/apache/camel/component/aws/iam/IAMComponentClientRegistryTest.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 IAMComponentClientRegistryTest extends CamelTestSupport { @@ -42,4 +44,26 @@ public class IAMComponentClientRegistryTest extends CamelTestSupport { assertThrows(IllegalArgumentException.class, () -> component.createEndpoint("aws-iam://TestDomain")); } + + @Test + public void createEndpointWithAutoDiscoverClientFalse() throws Exception { + + AmazonIAMClientMock clientMock = new AmazonIAMClientMock(); + context.getRegistry().bind("amazonIamClient", clientMock); + IAMComponent component = context.getComponent("aws-iam", IAMComponent.class); + IAMEndpoint endpoint = (IAMEndpoint)component.createEndpoint("aws-iam://TestDomain?accessKey=xxx&secretKey=yyy&autoDiscoverClient=false"); + + assertNotSame(clientMock, endpoint.getConfiguration().getIamClient()); + } + + @Test + public void createEndpointWithAutoDiscoverClientTrue() throws Exception { + + AmazonIAMClientMock clientMock = new AmazonIAMClientMock(); + context.getRegistry().bind("amazonIamClient", clientMock); + IAMComponent component = context.getComponent("aws-iam", IAMComponent.class); + IAMEndpoint endpoint = (IAMEndpoint)component.createEndpoint("aws-iam://TestDomain?accessKey=xxx&secretKey=yyy"); + + assertSame(clientMock, endpoint.getConfiguration().getIamClient()); + } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsIamComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsIamComponentBuilderFactory.java index ddb306d..bad8b64 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsIamComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsIamComponentBuilderFactory.java @@ -47,6 +47,21 @@ public interface AwsIamComponentBuilderFactory { */ interface AwsIamComponentBuilder extends ComponentBuilder<IAMComponent> { /** + * 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 AwsIamComponentBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type. @@ -216,6 +231,7 @@ public interface AwsIamComponentBuilderFactory { String name, Object value) { switch (name) { + case "autoDiscoverClient": getOrCreateConfiguration((IAMComponent) component).setAutoDiscoverClient((boolean) value); return true; case "accessKey": getOrCreateConfiguration((IAMComponent) component).setAccessKey((java.lang.String) value); return true; case "configuration": ((IAMComponent) component).setConfiguration((org.apache.camel.component.aws.iam.IAMConfiguration) value); return true; case "iamClient": getOrCreateConfiguration((IAMComponent) component).setIamClient((com.amazonaws.services.identitymanagement.AmazonIdentityManagement) 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 1bfe52a..45e5300 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 @@ -1086,7 +1086,7 @@ public class StaticEndpointBuilders { * * @param path label */ - static org.apache.camel.builder.endpoint.dsl.EKS2EndpointBuilderFactory.EKS2EndpointBuilder aws2Eks( + public static org.apache.camel.builder.endpoint.dsl.EKS2EndpointBuilderFactory.EKS2EndpointBuilder aws2Eks( String path) { return org.apache.camel.builder.endpoint.dsl.EKS2EndpointBuilderFactory.endpointBuilder("aws2-eks", path); } @@ -1107,7 +1107,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path label */ - static org.apache.camel.builder.endpoint.dsl.EKS2EndpointBuilderFactory.EKS2EndpointBuilder aws2Eks( + public static org.apache.camel.builder.endpoint.dsl.EKS2EndpointBuilderFactory.EKS2EndpointBuilder aws2Eks( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.EKS2EndpointBuilderFactory.endpointBuilder(componentName, path); @@ -1873,7 +1873,7 @@ public class StaticEndpointBuilders { * * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.IAMEndpointBuilderFactory.IAMEndpointBuilder awsIam( + static org.apache.camel.builder.endpoint.dsl.IAMEndpointBuilderFactory.IAMEndpointBuilder awsIam( String path) { return org.apache.camel.builder.endpoint.dsl.IAMEndpointBuilderFactory.endpointBuilder("aws-iam", path); } @@ -1894,7 +1894,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.IAMEndpointBuilderFactory.IAMEndpointBuilder awsIam( + static org.apache.camel.builder.endpoint.dsl.IAMEndpointBuilderFactory.IAMEndpointBuilder awsIam( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.IAMEndpointBuilderFactory.endpointBuilder(componentName, path); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/IAMEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/IAMEndpointBuilderFactory.java index 3d19110..eb1b66e 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/IAMEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/IAMEndpointBuilderFactory.java @@ -39,6 +39,34 @@ public interface IAMEndpointBuilderFactory { return (AdvancedIAMEndpointBuilder) 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 IAMEndpointBuilder 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 IAMEndpointBuilder autoDiscoverClient(String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type.
