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 2018/01/23 12:13:18 UTC

[camel] branch master updated: CAMEL-12173 - Camel-AWS Kinesis Firehose: Add the ability to specify credentials and region at component level

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 adca91c  CAMEL-12173 - Camel-AWS Kinesis Firehose: Add the ability to specify credentials and region at component level
adca91c is described below

commit adca91c614dc730f242c4072e8382d7e206ec5ed
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Jan 23 13:12:38 2018 +0100

    CAMEL-12173 - Camel-AWS Kinesis Firehose: Add the ability to specify credentials and region at component level
---
 .../main/docs/aws-kinesis-firehose-component.adoc  |  14 ++-
 .../aws/firehose/KinesisFirehoseComponent.java     |  71 ++++++++++++-
 .../aws/firehose/KinesisFirehoseConfiguration.java |  15 ++-
 .../KinesisFirehoseComponentConfigurationTest.java |  62 +++++++++++
 .../KinesisFirehoseComponentConfiguration.java     | 118 +++++++++++++++++++++
 5 files changed, 277 insertions(+), 3 deletions(-)

diff --git a/components/camel-aws/src/main/docs/aws-kinesis-firehose-component.adoc b/components/camel-aws/src/main/docs/aws-kinesis-firehose-component.adoc
index af94962..befb88f 100644
--- a/components/camel-aws/src/main/docs/aws-kinesis-firehose-component.adoc
+++ b/components/camel-aws/src/main/docs/aws-kinesis-firehose-component.adoc
@@ -25,7 +25,19 @@ The stream needs to be created prior to it being used. +
 
 
 // component options: START
-The AWS Kinesis Firehose component has no options.
+The AWS Kinesis Firehose component supports 5 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *configuration* (advanced) | The AWS Kinesis Firehose default configuration |  | KinesisFirehose Configuration
+| *accessKey* (producer) | Amazon AWS Access Key |  | String
+| *secretKey* (producer) | Amazon AWS Secret Key |  | String
+| *region* (producer) | Amazon AWS Region |  | String
+| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
+|===
 // component options: END
 
 
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/firehose/KinesisFirehoseComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/firehose/KinesisFirehoseComponent.java
index 369c695..9fec233 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/firehose/KinesisFirehoseComponent.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/firehose/KinesisFirehoseComponent.java
@@ -21,23 +21,92 @@ import java.util.Map;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.util.ObjectHelper;
 
 public class KinesisFirehoseComponent extends DefaultComponent {
 
+    @Metadata
+    private String accessKey;
+    @Metadata
+    private String secretKey;
+    @Metadata
+    private String region;
+    @Metadata(label = "advanced")    
+    private KinesisFirehoseConfiguration configuration;
+    
     public KinesisFirehoseComponent() {
         this(null);
     }
 
     public KinesisFirehoseComponent(CamelContext context) {
         super(context);
+        
+        this.configuration = new KinesisFirehoseConfiguration();
     }
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
-        KinesisFirehoseConfiguration configuration = new KinesisFirehoseConfiguration();
+        KinesisFirehoseConfiguration configuration = this.configuration.copy();
         configuration.setStreamName(remaining);
         setProperties(configuration, parameters);
+        if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
+            setAccessKey(accessKey);
+        }
+        if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
+            setSecretKey(secretKey);
+        }
+        if (ObjectHelper.isEmpty(configuration.getRegion())) {
+            setRegion(region);
+        }
+        if (configuration.getAmazonKinesisFirehoseClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
+            throw new IllegalArgumentException("AmazonKinesisClient or accessKey and secretKey must be specified");
+        }
         KinesisFirehoseEndpoint endpoint = new KinesisFirehoseEndpoint(uri, configuration, this);
         return endpoint;
     }
+    
+    public KinesisFirehoseConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    /**
+     * The AWS Kinesis Firehose default configuration
+     */
+    public void setConfiguration(KinesisFirehoseConfiguration configuration) {
+        this.configuration = configuration;
+    }
+    
+    public String getAccessKey() {
+        return configuration.getAccessKey();
+    }
+
+    /**
+     * Amazon AWS Access Key
+     */
+    public void setAccessKey(String accessKey) {
+        configuration.setAccessKey(accessKey);
+    }
+
+    public String getSecretKey() {
+        return configuration.getSecretKey();
+    }
+
+    /**
+     * Amazon AWS Secret Key
+     */
+    public void setSecretKey(String secretKey) {
+        configuration.setSecretKey(secretKey);
+    }
+    
+    public String getRegion() {
+        return configuration.getRegion();
+    }
+
+    /**
+     * Amazon AWS Region
+     */
+    public void setRegion(String region) {
+        configuration.setRegion(region);
+    }
 }
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/firehose/KinesisFirehoseConfiguration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/firehose/KinesisFirehoseConfiguration.java
index 699a2ca..d70ec0e 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/firehose/KinesisFirehoseConfiguration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/firehose/KinesisFirehoseConfiguration.java
@@ -18,13 +18,14 @@ package org.apache.camel.component.aws.firehose;
 
 import com.amazonaws.services.kinesisfirehose.AmazonKinesisFirehose;
 
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
 import org.apache.camel.spi.UriPath;
 
 @UriParams
-public class KinesisFirehoseConfiguration {
+public class KinesisFirehoseConfiguration implements Cloneable {
 
     @UriPath(description = "Name of the stream")
     @Metadata(required = "true")
@@ -97,4 +98,16 @@ public class KinesisFirehoseConfiguration {
     public void setProxyPort(Integer proxyPort) {
         this.proxyPort = proxyPort;
     }
+    
+    // *************************************************
+    //
+    // *************************************************
+
+    public KinesisFirehoseConfiguration copy() {
+        try {
+            return (KinesisFirehoseConfiguration)super.clone();
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
 }
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/firehose/KinesisFirehoseComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/firehose/KinesisFirehoseComponentConfigurationTest.java
new file mode 100644
index 0000000..bd92459
--- /dev/null
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/firehose/KinesisFirehoseComponentConfigurationTest.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws.firehose;
+
+import com.amazonaws.regions.Regions;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class KinesisFirehoseComponentConfigurationTest extends CamelTestSupport {
+    
+    @Test
+    public void createEndpointWithAccessAndSecretKey() throws Exception {
+        KinesisFirehoseComponent component = new KinesisFirehoseComponent(context);
+        KinesisFirehoseEndpoint endpoint = (KinesisFirehoseEndpoint)component.createEndpoint("aws-kinesis-firehose://some_stream_name?accessKey=xxxxx&secretKey=yyyyy");
+        
+        assertEquals("some_stream_name", endpoint.getConfiguration().getStreamName());
+        assertEquals("xxxxx", endpoint.getConfiguration().getAccessKey());
+        assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey());    
+    }
+    
+    @Test
+    public void createEndpointWithComponentElements() throws Exception {
+        KinesisFirehoseComponent component = new KinesisFirehoseComponent(context);
+        component.setAccessKey("XXX");
+        component.setSecretKey("YYY");
+        KinesisFirehoseEndpoint endpoint = (KinesisFirehoseEndpoint)component.createEndpoint("aws-kinesis-firehose://some_stream_name");
+        
+        assertEquals("some_stream_name", endpoint.getConfiguration().getStreamName());
+        assertEquals("XXX", endpoint.getConfiguration().getAccessKey());
+        assertEquals("YYY", endpoint.getConfiguration().getSecretKey());
+    }
+    
+    @Test
+    public void createEndpointWithComponentAndEndpointElements() throws Exception {
+        KinesisFirehoseComponent component = new KinesisFirehoseComponent(context);
+        component.setAccessKey("XXX");
+        component.setSecretKey("YYY");
+        component.setRegion(Regions.US_WEST_1.toString());
+        KinesisFirehoseEndpoint endpoint = (KinesisFirehoseEndpoint)component.createEndpoint("aws-kinesis-firehose://some_stream_name?accessKey=xxxxxx&secretKey=yyyyy&region=US_EAST_1");
+        
+        assertEquals("some_stream_name", endpoint.getConfiguration().getStreamName());
+        assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey());
+        assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey());
+        assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion());
+    }
+    
+}
\ No newline at end of file
diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/firehose/springboot/KinesisFirehoseComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/firehose/springboot/KinesisFirehoseComponentConfiguration.java
index f6946cf..4695577 100644
--- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/firehose/springboot/KinesisFirehoseComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/firehose/springboot/KinesisFirehoseComponentConfiguration.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.aws.firehose.springboot;
 
 import javax.annotation.Generated;
+import com.amazonaws.services.kinesisfirehose.AmazonKinesisFirehose;
 import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 
@@ -33,12 +34,61 @@ public class KinesisFirehoseComponentConfiguration
             ComponentConfigurationPropertiesCommon {
 
     /**
+     * The AWS Kinesis Firehose default configuration
+     */
+    private KinesisFirehoseConfigurationNestedConfiguration configuration;
+    /**
+     * Amazon AWS Access Key
+     */
+    private String accessKey;
+    /**
+     * Amazon AWS Secret Key
+     */
+    private String secretKey;
+    /**
+     * Amazon AWS Region
+     */
+    private String region;
+    /**
      * Whether the component should resolve property placeholders on itself when
      * starting. Only properties which are of String type can use property
      * placeholders.
      */
     private Boolean resolvePropertyPlaceholders = true;
 
+    public KinesisFirehoseConfigurationNestedConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    public void setConfiguration(
+            KinesisFirehoseConfigurationNestedConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    public String getAccessKey() {
+        return accessKey;
+    }
+
+    public void setAccessKey(String accessKey) {
+        this.accessKey = accessKey;
+    }
+
+    public String getSecretKey() {
+        return secretKey;
+    }
+
+    public void setSecretKey(String secretKey) {
+        this.secretKey = secretKey;
+    }
+
+    public String getRegion() {
+        return region;
+    }
+
+    public void setRegion(String region) {
+        this.region = region;
+    }
+
     public Boolean getResolvePropertyPlaceholders() {
         return resolvePropertyPlaceholders;
     }
@@ -47,4 +97,72 @@ public class KinesisFirehoseComponentConfiguration
             Boolean resolvePropertyPlaceholders) {
         this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
     }
+
+    public static class KinesisFirehoseConfigurationNestedConfiguration {
+        public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.aws.firehose.KinesisFirehoseConfiguration.class;
+        private AmazonKinesisFirehose amazonKinesisFirehoseClient;
+        private String streamName;
+        private String accessKey;
+        private String secretKey;
+        private String region;
+        private String proxyHost;
+        private Integer proxyPort;
+
+        public AmazonKinesisFirehose getAmazonKinesisFirehoseClient() {
+            return amazonKinesisFirehoseClient;
+        }
+
+        public void setAmazonKinesisFirehoseClient(
+                AmazonKinesisFirehose amazonKinesisFirehoseClient) {
+            this.amazonKinesisFirehoseClient = amazonKinesisFirehoseClient;
+        }
+
+        public String getStreamName() {
+            return streamName;
+        }
+
+        public void setStreamName(String streamName) {
+            this.streamName = streamName;
+        }
+
+        public String getAccessKey() {
+            return accessKey;
+        }
+
+        public void setAccessKey(String accessKey) {
+            this.accessKey = accessKey;
+        }
+
+        public String getSecretKey() {
+            return secretKey;
+        }
+
+        public void setSecretKey(String secretKey) {
+            this.secretKey = secretKey;
+        }
+
+        public String getRegion() {
+            return region;
+        }
+
+        public void setRegion(String region) {
+            this.region = region;
+        }
+
+        public String getProxyHost() {
+            return proxyHost;
+        }
+
+        public void setProxyHost(String proxyHost) {
+            this.proxyHost = proxyHost;
+        }
+
+        public Integer getProxyPort() {
+            return proxyPort;
+        }
+
+        public void setProxyPort(Integer proxyPort) {
+            this.proxyPort = proxyPort;
+        }
+    }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
acosentino@apache.org.