camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-9844: support for arn in aws component. Thanks to Tristan Hill for the patch.
Date Thu, 14 Apr 2016 12:21:33 GMT
Repository: camel
Updated Branches:
  refs/heads/master 5183c6ea9 -> 3c3341297


CAMEL-9844: support for arn in aws component. Thanks to Tristan Hill for the patch.


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

Branch: refs/heads/master
Commit: ddb720800d3afbb002f65d9077ca0a3810845a66
Parents: 5183c6e
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Apr 14 14:12:09 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Apr 14 14:12:09 2016 +0200

----------------------------------------------------------------------
 .../camel/component/aws/s3/S3Component.java     |  5 +++-
 .../camel/component/aws/s3/S3Endpoint.java      |  4 +--
 .../camel/component/aws/sns/SnsComponent.java   |  8 ++++--
 .../camel/component/aws/sns/SnsEndpoint.java    | 26 +++++++++++---------
 .../camel/component/aws/sqs/SqsComponent.java   | 15 +++++++++--
 .../camel/component/aws/sqs/SqsEndpoint.java    |  2 +-
 .../aws/s3/S3ComponentConfigurationTest.java    | 12 +++++++--
 .../aws/sns/SnsComponentConfigurationTest.java  | 12 +++++++--
 .../aws/sqs/SqsComponentConfigurationTest.java  | 13 +++++++++-
 9 files changed, 72 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ddb72080/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Component.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Component.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Component.java
index 33c92d5..a481267 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Component.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Component.java
@@ -39,6 +39,9 @@ public class S3Component extends UriEndpointComponent {
         if (remaining == null || remaining.trim().length() == 0) {
             throw new IllegalArgumentException("Bucket name must be specified.");
         }
+        if (remaining.startsWith("arn:")) {
+            remaining = remaining.substring(remaining.lastIndexOf(":") + 1, remaining.length());
+        }
         configuration.setBucketName(remaining);
 
         if (configuration.getAmazonS3Client() == null && (configuration.getAccessKey()
== null || configuration.getSecretKey() == null)) {
@@ -49,4 +52,4 @@ public class S3Component extends UriEndpointComponent {
         setProperties(endpoint, parameters);
         return endpoint;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ddb72080/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java
index 5d5ed75..b95dfa1 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java
@@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory;
 /**
  * The aws-s3 component is used for storing and retrieving objetc from Amazon S3 Storage
Service.
  */
-@UriEndpoint(scheme = "aws-s3", title = "AWS S3 Storage Service", syntax = "aws-s3:bucketName",
consumerClass = S3Consumer.class, label = "cloud,file")
+@UriEndpoint(scheme = "aws-s3", title = "AWS S3 Storage Service", syntax = "aws-s3:bucketNameOrArn",
consumerClass = S3Consumer.class, label = "cloud,file")
 public class S3Endpoint extends ScheduledPollEndpoint {
 
     private static final Logger LOG = LoggerFactory.getLogger(S3Endpoint.class);
@@ -234,4 +234,4 @@ public class S3Endpoint extends ScheduledPollEndpoint {
     public void setMaxMessagesPerPoll(int maxMessagesPerPoll) {
         this.maxMessagesPerPoll = maxMessagesPerPoll;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ddb72080/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java
index f3e1812..da6b311 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsComponent.java
@@ -39,7 +39,11 @@ public class SnsComponent extends UriEndpointComponent {
         if (remaining == null || remaining.trim().length() == 0) {
             throw new IllegalArgumentException("Topic name must be specified.");
         }
-        configuration.setTopicName(remaining);
+        if (remaining.startsWith("arn:")) {
+            configuration.setTopicArn(remaining);
+        } else {
+            configuration.setTopicName(remaining);
+        }
 
         if (configuration.getAmazonSNSClient() == null && (configuration.getAccessKey()
== null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("AmazonSNSClient or accessKey and secretKey
must be specified");
@@ -48,4 +52,4 @@ public class SnsComponent extends UriEndpointComponent {
         SnsEndpoint endpoint = new SnsEndpoint(uri, this, configuration);
         return endpoint;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ddb72080/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java
index 6dfad27..9991310 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sns/SnsEndpoint.java
@@ -40,7 +40,7 @@ import org.slf4j.LoggerFactory;
 /**
  * The aws-sns component is used for sending messages to an Amazon Simple Notification Topic.
  */
-@UriEndpoint(scheme = "aws-sns", title = "AWS Simple Notification System", syntax = "aws-sns:topicName",
producerOnly = true, label = "cloud,mobile,messaging")
+@UriEndpoint(scheme = "aws-sns", title = "AWS Simple Notification System", syntax = "aws-sns:topicNameOrArn",
producerOnly = true, label = "cloud,mobile,messaging")
 public class SnsEndpoint extends DefaultEndpoint {
 
     private static final Logger LOG = LoggerFactory.getLogger(SnsEndpoint.class);
@@ -83,16 +83,18 @@ public class SnsEndpoint extends DefaultEndpoint {
             LOG.trace("Updating the SNS region with : {} " + configuration.getAmazonSNSEndpoint());
             snsClient.setEndpoint(configuration.getAmazonSNSEndpoint());
         }
-        
-        // creates a new topic, or returns the URL of an existing one
-        CreateTopicRequest request = new CreateTopicRequest(configuration.getTopicName());
-        
-        LOG.trace("Creating topic [{}] with request [{}]...", configuration.getTopicName(),
request);
-        
-        CreateTopicResult result = snsClient.createTopic(request);
-        configuration.setTopicArn(result.getTopicArn());
-        
-        LOG.trace("Topic created with Amazon resource name: {}", configuration.getTopicArn());
+
+        if (configuration.getTopicArn() == null) {
+            // creates a new topic, or returns the URL of an existing one
+            CreateTopicRequest request = new CreateTopicRequest(configuration.getTopicName());
+
+            LOG.trace("Creating topic [{}] with request [{}]...", configuration.getTopicName(),
request);
+
+            CreateTopicResult result = snsClient.createTopic(request);
+            configuration.setTopicArn(result.getTopicArn());
+
+            LOG.trace("Topic created with Amazon resource name: {}", configuration.getTopicArn());
+        }
         
         if (ObjectHelper.isNotEmpty(configuration.getPolicy())) {
             LOG.trace("Updating topic [{}] with policy [{}]", configuration.getTopicArn(),
configuration.getPolicy());
@@ -138,4 +140,4 @@ public class SnsEndpoint extends DefaultEndpoint {
         }
         return client;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ddb72080/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java
index 8497e45..f865670 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsComponent.java
@@ -40,7 +40,18 @@ public class SqsComponent extends UriEndpointComponent {
         if (remaining == null || remaining.trim().length() == 0) {
             throw new IllegalArgumentException("Queue name must be specified.");
         }
-        configuration.setQueueName(remaining);
+
+        if (remaining.startsWith("arn:")) {
+            String[] parts = remaining.split(":");
+            if (parts.length != 6 || !parts[2].equals("sqs")) {
+                throw new IllegalArgumentException("Queue arn must be in format arn:aws:sqs:region:account:name.");
+            }
+            configuration.setRegion(parts[3]);
+            configuration.setQueueOwnerAWSAccountId(parts[4]);
+            configuration.setQueueName(parts[5]);
+        } else {
+            configuration.setQueueName(remaining);
+        }
 
         if (configuration.getAmazonSQSClient() == null && (configuration.getAccessKey()
== null || configuration.getSecretKey() == null)) {
             throw new IllegalArgumentException("AmazonSQSClient or accessKey and secretKey
must be specified.");
@@ -55,4 +66,4 @@ public class SqsComponent extends UriEndpointComponent {
         sqsEndpoint.setConsumerProperties(parameters);
         return sqsEndpoint;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ddb72080/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
index c7aef0a..c9ca0d2 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/sqs/SqsEndpoint.java
@@ -52,7 +52,7 @@ import org.slf4j.LoggerFactory;
 /**
  * The aws-sqs component is used for sending and receiving messages to Amazon's SQS service.
  */
-@UriEndpoint(scheme = "aws-sqs", title = "AWS Simple Queue Service", syntax = "aws-sqs:queueName",
consumerClass = SqsConsumer.class, label = "cloud,messaging")
+@UriEndpoint(scheme = "aws-sqs", title = "AWS Simple Queue Service", syntax = "aws-sqs:queueNameOrArn",
consumerClass = SqsConsumer.class, label = "cloud,messaging")
 public class SqsEndpoint extends ScheduledPollEndpoint implements HeaderFilterStrategyAware
{
     
     private static final Logger LOG = LoggerFactory.getLogger(SqsEndpoint.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/ddb72080/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
index 1490f69..ec4afd3 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
@@ -40,7 +40,15 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
         assertNull(endpoint.getConfiguration().getPrefix());
         assertTrue(endpoint.getConfiguration().isIncludeBody());
     }
-    
+
+    @Test
+    public void createEndpointWithMinimalArnConfiguration() throws Exception {
+        S3Component component = new S3Component(context);
+        S3Endpoint endpoint = (S3Endpoint) component.createEndpoint("aws-s3://arn:aws:s3:::MyBucket?accessKey=xxx&secretKey=yyy");
+
+        assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
+    }
+
     @Test
     public void createEndpointWithMinimalConfigurationAndProvidedClient() throws Exception
{
         AmazonS3ClientMock mock = new AmazonS3ClientMock();
@@ -104,4 +112,4 @@ public class S3ComponentConfigurationTest extends CamelTestSupport {
         S3Component component = new S3Component(context);
         component.createEndpoint("aws-sns://MyTopic?accessKey=xxx");
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ddb72080/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java
index 8a1283b..f1b2e46 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sns/SnsComponentConfigurationTest.java
@@ -37,7 +37,15 @@ public class SnsComponentConfigurationTest extends CamelTestSupport {
         assertNull(endpoint.getConfiguration().getAmazonSNSEndpoint());
         assertNull(endpoint.getConfiguration().getPolicy());
     }
-    
+
+    public void createEndpointWithMinimalArnConfiguration() throws Exception {
+        SnsComponent component = new SnsComponent(context);
+        SnsEndpoint endpoint = (SnsEndpoint) component.createEndpoint("aws-sns://arn:aws:sns:region:account:MyTopic?accessKey=xxx&secretKey=yyy");
+
+        assertNull(endpoint.getConfiguration().getTopicName());
+        assertEquals("arn:aws:sns:region:account:MyTopic", endpoint.getConfiguration().getTopicArn());
+    }
+
     @Test
     public void createEndpointWithMinimalConfigurationAndProvidedClient() throws Exception
{
         AmazonSNSClientMock mock = new AmazonSNSClientMock();
@@ -93,4 +101,4 @@ public class SnsComponentConfigurationTest extends CamelTestSupport {
         SnsComponent component = new SnsComponent(context);
         component.createEndpoint("aws-sns://MyTopic?accessKey=xxx");
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ddb72080/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
index 7da07bb..cfc21d0 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sqs/SqsComponentConfigurationTest.java
@@ -45,6 +45,17 @@ public class SqsComponentConfigurationTest extends CamelTestSupport {
     }
     
     @Test
+    public void createEndpointWithMinimalArnConfiguration() throws Exception {
+        SqsComponent component = new SqsComponent(context);
+        SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://arn:aws:sqs:region:account:MyQueue?accessKey=xxx&secretKey=yyy");
+
+        assertEquals("region", endpoint.getConfiguration().getRegion());
+        assertEquals("account", endpoint.getConfiguration().getQueueOwnerAWSAccountId());
+        assertEquals("MyQueue", endpoint.getConfiguration().getQueueName());
+        assertEquals("xxx", endpoint.getConfiguration().getAccessKey());
+    }
+
+    @Test
     public void createEndpointAttributeNames() throws Exception {
         SqsComponent component = new SqsComponent(context);
         SqsEndpoint endpoint = (SqsEndpoint) component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy&attributeNames=foo,bar");
@@ -155,4 +166,4 @@ public class SqsComponentConfigurationTest extends CamelTestSupport {
         SqsComponent component = new SqsComponent(context);
         assertNotNull(component.createEndpoint("aws-sqs://MyQueue?accessKey=xxx&secretKey=yyy&visibilityTimeout=30&extendMessageVisibility=false"));
     }
-}
\ No newline at end of file
+}


Mime
View raw message