You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/02/28 15:09:57 UTC

[camel] branch master updated: CAMEL-14568 - Fixed AWS KMS

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


The following commit(s) were added to refs/heads/master by this push:
     new 3f4c065  CAMEL-14568 - Fixed AWS KMS
3f4c065 is described below

commit 3f4c06533f6db571739c0e765adeabb7fa948899
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Feb 28 16:09:23 2020 +0100

    CAMEL-14568 - Fixed AWS KMS
---
 .../component/aws/kms/KMSComponentConfigurer.java  |  7 ++--
 .../apache/camel/component/aws/kms/aws-kms.json    |  8 ++--
 .../src/main/docs/aws-kms-component.adoc           |  2 +-
 .../camel/component/aws/kms/KMSComponent.java      | 46 +---------------------
 .../aws/kms/KMSComponentConfigurationTest.java     | 16 ++++----
 .../dsl/AwsKmsComponentBuilderFactory.java         | 34 ++++++++--------
 6 files changed, 35 insertions(+), 78 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 d705f2d..b0f165f 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
@@ -23,7 +23,8 @@ public class KMSComponentConfigurer extends PropertyConfigurerSupport implements
         KMSComponent target = (KMSComponent) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
         case "accesskey":
-        case "accessKey": target.setAccessKey(property(camelContext, java.lang.String.class, value)); return true;
+        case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true;
+        case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.aws.kms.KMSConfiguration.class, value)); return true;
         case "kmsclient":
         case "kmsClient": getOrCreateConfiguration(target).setKmsClient(property(camelContext, com.amazonaws.services.kms.AWSKMS.class, value)); return true;
         case "lazystartproducer":
@@ -35,13 +36,11 @@ public class KMSComponentConfigurer extends PropertyConfigurerSupport implements
         case "proxyPort": getOrCreateConfiguration(target).setProxyPort(property(camelContext, java.lang.Integer.class, value)); return true;
         case "proxyprotocol":
         case "proxyProtocol": getOrCreateConfiguration(target).setProxyProtocol(property(camelContext, com.amazonaws.Protocol.class, value)); return true;
-        case "region": target.setRegion(property(camelContext, java.lang.String.class, value)); return true;
         case "region": getOrCreateConfiguration(target).setRegion(property(camelContext, java.lang.String.class, value)); return true;
         case "secretkey":
-        case "secretKey": target.setSecretKey(property(camelContext, java.lang.String.class, value)); return true;
+        case "secretKey": getOrCreateConfiguration(target).setSecretKey(property(camelContext, java.lang.String.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;
         default: return false;
         }
     }
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 50955dd..8f4edb7 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
@@ -19,7 +19,8 @@
     "version": "3.2.0-SNAPSHOT"
   },
   "componentProperties": {
-    "accessKey": { "kind": "property", "displayName": "Access Key", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "Amazon AWS Access Key" },
+    "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" },
     "lazyStartProducer": { "kind": "property", "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 r [...]
     "operation": { "kind": "property", "displayName": "Operation", "group": "producer", "label": "producer", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.kms.KMSOperations", "enum": [ "listKeys", "createKey", "disableKey", "scheduleKeyDeletion", "describeKey", "enableKey" ], "deprecated": false, "deprecationNote": "", "secret": false, "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "des [...]
@@ -27,9 +28,8 @@
     "proxyPort": { "kind": "property", "displayName": "Proxy Port", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "description": "To define a proxy port when instantiating the KMS client" },
     "proxyProtocol": { "kind": "property", "displayName": "Proxy Protocol", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "com.amazonaws.Protocol", "enum": [ "HTTP", "HTTPS" ], "deprecated": false, "secret": false, "defaultValue": "HTTPS", "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "description": "To define a proxy protocol when instantiating the KMS client" },
     "region": { "kind": "property", "displayName": "Region", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.kms.KMSConfiguration", "configurationField": "configuration", "description": "The region in which KMS client needs to work. When using this parameter, the configuration will expect the capitalized name of the region (for example AP_EAST [...]
-    "secretKey": { "kind": "property", "displayName": "Secret Key", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "Amazon AWS Secret Key" },
-    "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" },
-    "configuration": { "kind": "property", "displayName": "Configuration", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.kms.KMSConfiguration", "deprecated": false, "secret": false, "description": "The AWS KMS default configuration" }
+    "secretKey": { "kind": "property", "displayName": "Secret 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 Secret Key" },
+    "basicPropertyBinding": { "kind": "property", "displayName": "Basic Property Binding", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities" }
   },
   "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" },
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 7d04fcc..f535294 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
@@ -38,6 +38,7 @@ The AWS KMS component supports 11 options, which are listed below.
 |===
 | Name | Description | Default | Type
 | *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
 | *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 [...]
 | *operation* (producer) | *Required* The operation to perform. The value can be one of: listKeys, createKey, disableKey, scheduleKeyDeletion, describeKey, enableKey |  | KMSOperations
@@ -47,7 +48,6 @@ The AWS KMS component supports 11 options, which are listed below.
 | *region* (producer) | The region in which KMS client needs to work. When using this parameter, the configuration will expect the capitalized name of the region (for example AP_EAST_1) You'll need to use the name Regions.EU_WEST_1.name() |  | String
 | *secretKey* (producer) | Amazon AWS Secret Key |  | String
 | *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
-| *configuration* (advanced) | The AWS KMS default configuration |  | KMSConfiguration
 |===
 // component options: END
 
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 cad3b50..fc2c1d2 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
@@ -33,13 +33,7 @@ import org.apache.camel.support.DefaultComponent;
 public class KMSComponent extends DefaultComponent {
 
     @Metadata
-    private String accessKey;
-    @Metadata
-    private String secretKey;
-    @Metadata
-    private String region;
-    @Metadata(label = "advanced")    
-    private KMSConfiguration configuration;
+    private KMSConfiguration configuration = new KMSConfiguration();
     
     public KMSComponent() {
         this(null);
@@ -56,9 +50,6 @@ public class KMSComponent extends DefaultComponent {
         KMSConfiguration configuration = this.configuration != null ? this.configuration.copy() : new KMSConfiguration();
         
         KMSEndpoint endpoint = new KMSEndpoint(uri, this, configuration);
-        endpoint.getConfiguration().setAccessKey(accessKey);
-        endpoint.getConfiguration().setSecretKey(secretKey);
-        endpoint.getConfiguration().setRegion(region);
         setProperties(endpoint, parameters);
         checkAndSetRegistryClient(configuration);
         if (configuration.getKmsClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
@@ -73,45 +64,12 @@ public class KMSComponent extends DefaultComponent {
     }
 
     /**
-     * The AWS KMS default configuration
+     * The Component configuration
      */
     public void setConfiguration(KMSConfiguration configuration) {
         this.configuration = configuration;
     }
 
-    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 String getRegion() {
-        return region;
-    }
-
-    /**
-     * The region in which KMS client needs to work
-     */
-    public void setRegion(String region) {
-        this.region = region;
-    }
-
     private void checkAndSetRegistryClient(KMSConfiguration configuration) {
         Set<AWSKMS> clients = getCamelContext().getRegistry().findByType(AWSKMS.class);
         if (clients.size() == 1) {
diff --git a/components/camel-aws-kms/src/test/java/org/apache/camel/component/aws/kms/KMSComponentConfigurationTest.java b/components/camel-aws-kms/src/test/java/org/apache/camel/component/aws/kms/KMSComponentConfigurationTest.java
index 81957a8..bded042 100644
--- a/components/camel-aws-kms/src/test/java/org/apache/camel/component/aws/kms/KMSComponentConfigurationTest.java
+++ b/components/camel-aws-kms/src/test/java/org/apache/camel/component/aws/kms/KMSComponentConfigurationTest.java
@@ -27,8 +27,8 @@ public class KMSComponentConfigurationTest extends CamelTestSupport {
     @Test
     public void createEndpointWithComponentElements() throws Exception {
         KMSComponent component = context.getComponent("aws-kms", KMSComponent.class);
-        component.setAccessKey("XXX");
-        component.setSecretKey("YYY");
+        component.getConfiguration().setAccessKey("XXX");
+        component.getConfiguration().setSecretKey("YYY");
         KMSEndpoint endpoint = (KMSEndpoint)component.createEndpoint("aws-kms://label");
         
         assertEquals("XXX", endpoint.getConfiguration().getAccessKey());
@@ -38,9 +38,9 @@ public class KMSComponentConfigurationTest extends CamelTestSupport {
     @Test
     public void createEndpointWithComponentAndEndpointElements() throws Exception {
         KMSComponent component = context.getComponent("aws-kms", KMSComponent.class);
-        component.setAccessKey("XXX");
-        component.setSecretKey("YYY");
-        component.setRegion(Regions.US_WEST_1.toString());
+        component.getConfiguration().setAccessKey("XXX");
+        component.getConfiguration().setSecretKey("YYY");
+        component.getConfiguration().setRegion(Regions.US_WEST_1.toString());
         KMSEndpoint endpoint = (KMSEndpoint)component.createEndpoint("aws-kms://label?accessKey=xxxxxx&secretKey=yyyyy&region=US_EAST_1");
         
         assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey());
@@ -51,9 +51,9 @@ public class KMSComponentConfigurationTest extends CamelTestSupport {
     @Test
     public void createEndpointWithComponentEndpointElementsAndProxy() throws Exception {
         KMSComponent component = context.getComponent("aws-kms", KMSComponent.class);
-        component.setAccessKey("XXX");
-        component.setSecretKey("YYY");
-        component.setRegion(Regions.US_WEST_1.toString());
+        component.getConfiguration().setAccessKey("XXX");
+        component.getConfiguration().setSecretKey("YYY");
+        component.getConfiguration().setRegion(Regions.US_WEST_1.toString());
         KMSEndpoint endpoint = (KMSEndpoint)component.createEndpoint("aws-kms://label?accessKey=xxxxxx&secretKey=yyyyy&region=US_EAST_1&proxyHost=localhost&proxyPort=9000&proxyProtocol=HTTP");
         
         assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey());
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 f98f2af..daf4cf4 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
@@ -58,6 +58,20 @@ public interface AwsKmsComponentBuilderFactory {
             return this;
         }
         /**
+         * The Component configuration.
+         * 
+         * The option is a:
+         * <code>org.apache.camel.component.aws.kms.KMSConfiguration</code>
+         * type.
+         * 
+         * Group: producer
+         */
+        default AwsKmsComponentBuilder configuration(
+                org.apache.camel.component.aws.kms.KMSConfiguration configuration) {
+            doSetProperty("configuration", configuration);
+            return this;
+        }
+        /**
          * To use a existing configured AWS KMS as client.
          * 
          * The option is a: <code>com.amazonaws.services.kms.AWSKMS</code> type.
@@ -177,20 +191,6 @@ public interface AwsKmsComponentBuilderFactory {
             doSetProperty("basicPropertyBinding", basicPropertyBinding);
             return this;
         }
-        /**
-         * The AWS KMS default configuration.
-         * 
-         * The option is a:
-         * <code>org.apache.camel.component.aws.kms.KMSConfiguration</code>
-         * type.
-         * 
-         * Group: advanced
-         */
-        default AwsKmsComponentBuilder configuration(
-                org.apache.camel.component.aws.kms.KMSConfiguration configuration) {
-            doSetProperty("configuration", configuration);
-            return this;
-        }
     }
 
     class AwsKmsComponentBuilderImpl
@@ -215,7 +215,8 @@ public interface AwsKmsComponentBuilderFactory {
                 String name,
                 Object value) {
             switch (name) {
-            case "accessKey": ((KMSComponent) component).setAccessKey((java.lang.String) 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;
             case "lazyStartProducer": ((KMSComponent) component).setLazyStartProducer((boolean) value); return true;
             case "operation": getOrCreateConfiguration((KMSComponent) component).setOperation((org.apache.camel.component.aws.kms.KMSOperations) value); return true;
@@ -223,9 +224,8 @@ public interface AwsKmsComponentBuilderFactory {
             case "proxyPort": getOrCreateConfiguration((KMSComponent) component).setProxyPort((java.lang.Integer) value); return true;
             case "proxyProtocol": getOrCreateConfiguration((KMSComponent) component).setProxyProtocol((com.amazonaws.Protocol) value); return true;
             case "region": getOrCreateConfiguration((KMSComponent) component).setRegion((java.lang.String) value); return true;
-            case "secretKey": ((KMSComponent) component).setSecretKey((java.lang.String) value); return true;
+            case "secretKey": getOrCreateConfiguration((KMSComponent) component).setSecretKey((java.lang.String) value); return true;
             case "basicPropertyBinding": ((KMSComponent) component).setBasicPropertyBinding((boolean) value); return true;
-            case "configuration": ((KMSComponent) component).setConfiguration((org.apache.camel.component.aws.kms.KMSConfiguration) value); return true;
             default: return false;
             }
         }