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

commit 47342dbf4a7650c101d44b24a21c1b5404236a9b
Author: Andrea Cosentino <anco...@gmail.com>
AuthorDate: Tue May 28 13:04:36 2019 +0200

    CAMEL-13591 - Camel-AWS S3: Add an option for the autocreation of the bucket
---
 .../camel-aws-s3/src/main/docs/aws-s3-component.adoc      |  3 ++-
 .../apache/camel/component/aws/s3/S3Configuration.java    | 15 ++++++++++++++-
 .../org/apache/camel/component/aws/s3/S3Endpoint.java     |  2 ++
 .../component/aws/s3/S3ComponentConfigurationTest.java    | 13 +++++++++++++
 .../aws/s3/springboot/S3ComponentConfiguration.java       | 12 ++++++++++++
 5 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/components/camel-aws-s3/src/main/docs/aws-s3-component.adoc 
b/components/camel-aws-s3/src/main/docs/aws-s3-component.adoc
index e5a3120..23020b4 100644
--- a/components/camel-aws-s3/src/main/docs/aws-s3-component.adoc
+++ b/components/camel-aws-s3/src/main/docs/aws-s3-component.adoc
@@ -81,13 +81,14 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (52 parameters):
+==== Query Parameters (53 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
 | *amazonS3Client* (common) | Reference to a 
com.amazonaws.services.s3.AmazonS3 in the link:registry.htmlRegistry. |  | 
AmazonS3
+| *autoCreateBucket* (common) | Setting the autocreation of the bucket | true 
| boolean
 | *pathStyleAccess* (common) | Whether or not the S3 client should use path 
style access | false | boolean
 | *policy* (common) | The policy for this queue to set in the 
com.amazonaws.services.s3.AmazonS3#setBucketPolicy() method. |  | String
 | *proxyHost* (common) | To define a proxy host when instantiating the SQS 
client |  | String
diff --git 
a/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
 
b/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
index 7c71a2f..86f4382 100644
--- 
a/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
+++ 
b/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java
@@ -82,6 +82,8 @@ public class S3Configuration implements Cloneable {
     private boolean payloadSigningEnabled;
     @UriParam(label = "common, advanced", defaultValue = "false")
     private boolean forceGlobalBucketAccessEnabled;
+    @UriParam(label = "common", defaultValue = "true")
+    private boolean autoCreateBucket = true;
     @UriParam(label = "producer,advanced", defaultValue = "false")
     private boolean useAwsKMS;
     @UriParam(label = "producer,advanced")
@@ -462,7 +464,18 @@ public class S3Configuration implements Cloneable {
         return useIAMCredentials;
     }
 
-    public boolean hasProxyConfiguration() {
+    public boolean isAutoCreateBucket() {
+               return autoCreateBucket;
+       }
+
+    /**
+     * Setting the autocreation of the bucket
+     */
+       public void setAutoCreateBucket(boolean autoCreateBucket) {
+               this.autoCreateBucket = autoCreateBucket;
+       }
+
+       public boolean hasProxyConfiguration() {
         return ObjectHelper.isNotEmpty(getProxyHost()) && 
ObjectHelper.isNotEmpty(getProxyPort());
     }
     
diff --git 
a/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java
 
b/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java
index c8cb678..d11aae7 100644
--- 
a/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java
+++ 
b/components/camel-aws-s3/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java
@@ -110,6 +110,7 @@ public class S3Endpoint extends ScheduledPollEndpoint {
 
         LOG.trace("Bucket [{}] doesn't exist yet", bucketName);
 
+        if (getConfiguration().isAutoCreateBucket()) {
         // creates the new bucket because it doesn't exist yet
         CreateBucketRequest createBucketRequest = new 
CreateBucketRequest(getConfiguration().getBucketName());
 
@@ -118,6 +119,7 @@ public class S3Endpoint extends ScheduledPollEndpoint {
         s3Client.createBucket(createBucketRequest);
 
         LOG.trace("Bucket created");
+        }
 
         if (configuration.getPolicy() != null) {
             LOG.trace("Updating bucket [{}] with policy [{}]", bucketName, 
configuration.getPolicy());
diff --git 
a/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
 
b/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
index e81a4c0..bde0a75 100644
--- 
a/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
+++ 
b/components/camel-aws-s3/src/test/java/org/apache/camel/component/aws/s3/S3ComponentConfigurationTest.java
@@ -219,6 +219,19 @@ public class S3ComponentConfigurationTest extends 
CamelTestSupport {
         assertEquals("yyy", endpoint.getConfiguration().getSecretKey());
         
assertTrue(endpoint.getConfiguration().isForceGlobalBucketAccessEnabled());
     }
+    
+    @Test
+    public void createEndpointWithAutocreateOption() throws Exception {
+
+        S3Component component = new S3Component(context);
+        S3Endpoint endpoint = 
(S3Endpoint)component.createEndpoint("aws-s3://MyBucket?forceGlobalBucketAccessEnabled=true&accessKey=xxx&secretKey=yyy&region=US_WEST_1&autoCreateBucket=false");
+
+        assertEquals("MyBucket", endpoint.getConfiguration().getBucketName());
+        assertEquals("xxx", endpoint.getConfiguration().getAccessKey());
+        assertEquals("yyy", endpoint.getConfiguration().getSecretKey());
+        
assertTrue(endpoint.getConfiguration().isForceGlobalBucketAccessEnabled());
+        assertFalse(endpoint.getConfiguration().isAutoCreateBucket());
+    }
 
     @Test
     public void createEndpointWithoutSecretKeyAndAccessKeyConfiguration() 
throws Exception {
diff --git 
a/platforms/spring-boot/components-starter/camel-aws-s3-starter/src/main/java/org/apache/camel/component/aws/s3/springboot/S3ComponentConfiguration.java
 
b/platforms/spring-boot/components-starter/camel-aws-s3-starter/src/main/java/org/apache/camel/component/aws/s3/springboot/S3ComponentConfiguration.java
index 6aa6895..66eda9d 100644
--- 
a/platforms/spring-boot/components-starter/camel-aws-s3-starter/src/main/java/org/apache/camel/component/aws/s3/springboot/S3ComponentConfiguration.java
+++ 
b/platforms/spring-boot/components-starter/camel-aws-s3-starter/src/main/java/org/apache/camel/component/aws/s3/springboot/S3ComponentConfiguration.java
@@ -276,6 +276,10 @@ public class S3ComponentConfiguration
          * instance or to expect static credentials to be passed in.
          */
         private Boolean useIAMCredentials = false;
+        /**
+         * Setting the autocreation of the bucket
+         */
+        private Boolean autoCreateBucket = true;
 
         public Long getPartSize() {
             return partSize;
@@ -526,5 +530,13 @@ public class S3ComponentConfiguration
         public void setUseIAMCredentials(Boolean useIAMCredentials) {
             this.useIAMCredentials = useIAMCredentials;
         }
+
+        public Boolean getAutoCreateBucket() {
+            return autoCreateBucket;
+        }
+
+        public void setAutoCreateBucket(Boolean autoCreateBucket) {
+            this.autoCreateBucket = autoCreateBucket;
+        }
     }
 }
\ No newline at end of file

Reply via email to