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 2019/12/11 11:50:58 UTC

[camel] branch master updated: CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-iam

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 fb8c059  CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-iam
fb8c059 is described below

commit fb8c0597623da066894b5666e8f71791a89e2124
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Dec 11 12:50:38 2019 +0100

    CAMEL-14284: Configuring endpoint should set properties on endpoint and not configuration object - aws-iam
---
 .../camel/component/aws/iam/IAMComponent.java      | 33 ++++++++--------------
 .../aws/iam/IAMComponentClientRegistryTest.java    |  4 +--
 .../aws/iam/IAMComponentConfigurationTest.java     |  6 ++--
 3 files changed, 17 insertions(+), 26 deletions(-)

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 856d99c..410410c 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
@@ -25,7 +25,6 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
 import org.apache.camel.support.DefaultComponent;
-import org.apache.camel.util.ObjectHelper;
 
 /**
  * For working with Amazon IAM.
@@ -49,30 +48,22 @@ public class IAMComponent extends DefaultComponent {
     public IAMComponent(CamelContext context) {
         super(context);
 
-        this.configuration = new IAMConfiguration();
         registerExtension(new IAMComponentVerifierExtension());
     }
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
-        IAMConfiguration configuration = this.configuration.copy();
-        setProperties(configuration, parameters);
-
-        if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
-            setAccessKey(accessKey);
-        }
-        if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
-            setSecretKey(secretKey);
-        }
-        if (ObjectHelper.isEmpty(configuration.getRegion())) {
-            setRegion(region);
-        }
+        IAMConfiguration configuration = this.configuration != null ? this.configuration.copy() : new IAMConfiguration();
+        IAMEndpoint endpoint = new IAMEndpoint(uri, this, configuration);
+        endpoint.getConfiguration().setAccessKey(accessKey);
+        endpoint.getConfiguration().setSecretKey(secretKey);
+        endpoint.getConfiguration().setRegion(region);
+        setProperties(endpoint, parameters);
         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");
         }
 
-        IAMEndpoint endpoint = new IAMEndpoint(uri, this, configuration);
         return endpoint;
     }
 
@@ -88,36 +79,36 @@ public class IAMComponent extends DefaultComponent {
     }
 
     public String getAccessKey() {
-        return configuration.getAccessKey();
+        return accessKey;
     }
 
     /**
      * Amazon AWS Access Key
      */
     public void setAccessKey(String accessKey) {
-        configuration.setAccessKey(accessKey);
+        this.accessKey = accessKey;
     }
 
     public String getSecretKey() {
-        return configuration.getSecretKey();
+        return secretKey;
     }
 
     /**
      * Amazon AWS Secret Key
      */
     public void setSecretKey(String secretKey) {
-        configuration.setSecretKey(secretKey);
+        this.secretKey = secretKey;
     }
 
     public String getRegion() {
-        return configuration.getRegion();
+        return region;
     }
 
     /**
      * The region in which IAM client needs to work
      */
     public void setRegion(String region) {
-        configuration.setRegion(region);
+        this.region = region;
     }
 
     private void checkAndSetRegistryClient(IAMConfiguration configuration) {
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 fb44819..9aca8da 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
@@ -26,7 +26,7 @@ public class IAMComponentClientRegistryTest extends CamelTestSupport {
 
         AmazonIAMClientMock clientMock = new AmazonIAMClientMock();
         context.getRegistry().bind("amazonIamClient", clientMock);
-        IAMComponent component = new IAMComponent(context);
+        IAMComponent component = context.getComponent("aws-iam", IAMComponent.class);
         IAMEndpoint endpoint = (IAMEndpoint)component.createEndpoint("aws-iam://TestDomain");
 
         assertNotNull(endpoint.getConfiguration().getIamClient());
@@ -35,7 +35,7 @@ public class IAMComponentClientRegistryTest extends CamelTestSupport {
     @Test(expected = IllegalArgumentException.class)
     public void createEndpointWithMinimalECSClientMisconfiguration() throws Exception {
 
-        IAMComponent component = new IAMComponent(context);
+        IAMComponent component = context.getComponent("aws-iam", IAMComponent.class);
         IAMEndpoint endpoint = (IAMEndpoint)component.createEndpoint("aws-iam://TestDomain");
     }
 }
diff --git a/components/camel-aws-iam/src/test/java/org/apache/camel/component/aws/iam/IAMComponentConfigurationTest.java b/components/camel-aws-iam/src/test/java/org/apache/camel/component/aws/iam/IAMComponentConfigurationTest.java
index eec6aa0..6668ced 100644
--- a/components/camel-aws-iam/src/test/java/org/apache/camel/component/aws/iam/IAMComponentConfigurationTest.java
+++ b/components/camel-aws-iam/src/test/java/org/apache/camel/component/aws/iam/IAMComponentConfigurationTest.java
@@ -26,7 +26,7 @@ public class IAMComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentElements() throws Exception {
-        IAMComponent component = new IAMComponent(context);
+        IAMComponent component = context.getComponent("aws-iam", IAMComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         IAMEndpoint endpoint = (IAMEndpoint)component.createEndpoint("aws-iam://label");
@@ -37,7 +37,7 @@ public class IAMComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentAndEndpointElements() throws Exception {
-        IAMComponent component = new IAMComponent(context);
+        IAMComponent component = context.getComponent("aws-iam", IAMComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());
@@ -50,7 +50,7 @@ public class IAMComponentConfigurationTest extends CamelTestSupport {
     
     @Test
     public void createEndpointWithComponentEndpointElementsAndProxy() throws Exception {
-        IAMComponent component = new IAMComponent(context);
+        IAMComponent component = context.getComponent("aws-iam", IAMComponent.class);
         component.setAccessKey("XXX");
         component.setSecretKey("YYY");
         component.setRegion(Regions.US_WEST_1.toString());