CAMEL-9210 - accessKey and secretKey options for CloudWatch is now optional

accessKey and secretKey options for CloudWatch is now optional
and AWS Java SDK handles those keys unless they are not provided in URI.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/901b6a48
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/901b6a48
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/901b6a48

Branch: refs/heads/master
Commit: 901b6a4885d4f0687c7780462b24e738f7ce30d6
Parents: f05f319
Author: onders86 <[email protected]>
Authored: Fri Jan 20 18:42:26 2017 +0200
Committer: Claus Ibsen <[email protected]>
Committed: Sat Jan 21 09:02:15 2017 +0100

----------------------------------------------------------------------
 .../camel/component/aws/cw/CwComponent.java     |  4 ++--
 .../camel/component/aws/cw/CwEndpoint.java      | 21 ++++++++++++++++----
 .../aws/cw/CwComponentConfigurationTest.java    |  6 ++++++
 3 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/901b6a48/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java
 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java
index 06e106a..8e3069d 100644
--- 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java
+++ 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java
@@ -41,8 +41,8 @@ public class CwComponent extends UriEndpointComponent {
         }
         configuration.setNamespace(remaining);
 
-        if (configuration.getAmazonCwClient() == null && 
(configuration.getAccessKey() == null || configuration.getSecretKey() == null)) 
{
-            throw new IllegalArgumentException("AmazonCwClient or accessKey 
and secretKey must be specified");
+        if (configuration.getAmazonCwClient() == null) {
+            throw new IllegalArgumentException("AmazonCwClient must be 
specified");
         }
 
         CwEndpoint endpoint = new CwEndpoint(uri, this, configuration);

http://git-wip-us.apache.org/repos/asf/camel/blob/901b6a48/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwEndpoint.java
----------------------------------------------------------------------
diff --git 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwEndpoint.java
 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwEndpoint.java
index b26288b..8d102cc 100644
--- 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwEndpoint.java
+++ 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwEndpoint.java
@@ -95,14 +95,27 @@ public class CwEndpoint extends DefaultEndpoint {
 
     AmazonCloudWatch createCloudWatchClient() {
         AmazonCloudWatch client = null;
-        AWSCredentials credentials = new 
BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
+        ClientConfiguration clientConfiguration = null;
+        boolean isClientConfigFound = false;
         if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && 
ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
-            ClientConfiguration clientConfiguration = new 
ClientConfiguration();
+               clientConfiguration = new ClientConfiguration();
             clientConfiguration.setProxyHost(configuration.getProxyHost());
             clientConfiguration.setProxyPort(configuration.getProxyPort());
-            client = new AmazonCloudWatchClient(credentials, 
clientConfiguration);
+            isClientConfigFound = true;
+        }
+        if( (configuration.getAccessKey() != null && 
configuration.getSecretKey() != null) ) {
+            AWSCredentials credentials = new 
BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
+            if (isClientConfigFound) {
+                client = new AmazonCloudWatchClient(credentials, 
clientConfiguration);
+            } else {
+                client = new AmazonCloudWatchClient(credentials);
+            }
         } else {
-            client = new AmazonCloudWatchClient(credentials);
+               if (isClientConfigFound) {
+                       client = new AmazonCloudWatchClient();
+            } else {
+                client = new AmazonCloudWatchClient(clientConfiguration);
+            }
         }
         return client;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/901b6a48/components/camel-aws/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-aws/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
 
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
index 2254e3c..59dd982 100644
--- 
a/components/camel-aws/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
+++ 
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
@@ -53,6 +53,12 @@ public class CwComponentConfigurationTest extends 
CamelTestSupport {
         CwComponent component = new CwComponent(context);
         
component.createEndpoint("aws-cw://camel.apache.org/test?accessKey=xxx");
     }
+    
+    @Test
+    public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() 
throws Exception {
+        CwComponent component = new CwComponent(context);
+        
component.createEndpoint("aws-cw://camel.apache.org/test?amazonCwClient=#amazonCwClient&accessKey=xxx");
+    }
 
     @Override
     protected JndiRegistry createRegistry() throws Exception {

Reply via email to