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 2022/02/23 13:29:38 UTC

[camel] branch main updated (5a5ee2e -> 458d019)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 5a5ee2e  CAMEL-17694: improve handling of sendToAll header
     new 368cbf5  CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value
     new db5d13c  CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value
     new e260b3f  CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value
     new a696cbe  CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value
     new 481d0a2  CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value
     new 458d019  Regen

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/camel/catalog/schemas/camel-spring.xsd  | 110 ++++++++-------
 .../main/docs/aws-secrets-manager-component.adoc   |  30 ++++-
 .../SecretsManagerPropertiesFunction.java          |  68 ++++++----
 .../SecretsManagerNoEnvPropertiesSourceTestIT.java | 149 +++++++++++++++++++++
 .../SecretsManagerPropertiesSourceTestIT.java      | 137 ++++++++++++++++++-
 docs/user-manual/modules/ROOT/pages/security.adoc  |  30 ++++-
 6 files changed, 448 insertions(+), 76 deletions(-)

[camel] 03/06: CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e260b3f3e10f229eb9c136b6abd321dcdc5c4295
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Feb 23 10:50:48 2022 +0100

    CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value
---
 .../main/docs/aws-secrets-manager-component.adoc   | 30 +++++++++++++++++++++-
 .../SecretsManagerPropertiesSourceTestIT.java      | 20 +++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc b/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc
index 4a3b4ff..ac65a98 100644
--- a/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc
+++ b/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc
@@ -72,6 +72,20 @@ At this point you'll be able to reference a property in the following way:
 
 Where route will be the name of the secret stored in the AWS Secrets Manager Service.
 
+You could specify a default value in case the secret is not present on AWS Secret Manager:
+
+[source,xml]
+----
+<camelContext>
+    <route>
+        <from uri="direct:start"/>
+        <to uri="{{aws:route:default}}"/>
+    </route>
+</camelContext>
+----
+
+In this case if the secret doesn't exist, the property will fallback to "default" as value.
+
 Also you are able to get particular field of the secret, if you have for example a secret named database of this form:
 
 [source,bash]
@@ -93,13 +107,27 @@ You're able to do get single secret value in your route, like for example:
 <camelContext>
     <route>
         <from uri="direct:start"/>
-        <log message="Username is {{aws:database:username}}"/>
+        <log message="Username is {{aws:database/username}}"/>
     </route>
 </camelContext>
 ----
 
 Or re-use the property as part of an endpoint.
 
+You could specify a default value in case the particular field of secret is not present on AWS Secret Manager:
+
+[source,xml]
+----
+<camelContext>
+    <route>
+        <from uri="direct:start"/>
+        <log message="Username is {{aws:database/username:admin}}"/>
+    </route>
+</camelContext>
+----
+
+In this case if the secret doesn't exist or the secret exists, but the username field is not part of the secret, the property will fallback to "admin" as value.
+
 For the moment we are not considering the rotation function, if any will be applied, but it is in the work to be done.
 
 The only requirement is adding the camel-aws-secrets-manager jar to your Camel application.
diff --git a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java
index b8b928e..47e646f 100644
--- a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java
+++ b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java
@@ -210,4 +210,24 @@ public class SecretsManagerPropertiesSourceTestIT extends CamelTestSupport {
             assertMockEndpointsSatisfied();
         });
     }
+
+    @Test
+    public void testComplexCustomPropertiesNoDefaultValueFunction() throws Exception {
+        Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{aws:postgresql/additional1}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{aws:postgresql/additional2}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+        });
+    }
 }

[camel] 02/06: CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit db5d13c8ca46700b7cc4e5e2475248148fcdacaa
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Feb 23 10:43:48 2022 +0100

    CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value
---
 .../SecretsManagerNoEnvPropertiesSourceTestIT.java | 107 +++++++++++++++++++++
 1 file changed, 107 insertions(+)

diff --git a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java
index 3633b6b..25320a3 100644
--- a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java
+++ b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java
@@ -139,4 +139,111 @@ public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport
             assertMockEndpointsSatisfied();
         });
     }
+
+    @Test
+    public void testComplexCustomPropertiesDefaultValueFunction() throws Exception {
+        context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey"));
+        context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey"));
+        context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region"));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{aws:postgresql/additional1:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{aws:postgresql/additional2:secret}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testComplexCustomPropertiesDefaultValueExceptionFunction() throws Exception {
+        context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey"));
+        context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey"));
+        context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region"));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{aws:test-3/additional1:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{aws:test-3/additional2:secret}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testComplexCustomPropertiesExceptionFunction() throws Exception {
+        context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey"));
+        context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey"));
+        context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region"));
+        Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:username").setBody(simple("{{aws:test-3/additional1}}")).to("mock:bar");
+                    from("direct:password").setBody(simple("{{aws:test-3/additional2}}")).to("mock:bar");
+                }
+            });
+            context.start();
+
+            getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+            template.sendBody("direct:username", "Hello World");
+            template.sendBody("direct:password", "Hello World");
+            assertMockEndpointsSatisfied();
+        });
+    }
+
+    @Test
+    public void testComplexSimpleDefaultValueExceptionFunction() throws Exception {
+        context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey"));
+        context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey"));
+        context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region"));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{aws:test-3:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{aws:test-1:secret}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testComplexSimpleNoDefaultValueExceptionFunction() throws Exception {
+        context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey"));
+        context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey"));
+        context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region"));
+        Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:username").setBody(simple("{{aws:secretsuper}}")).to("mock:bar");
+                }
+            });
+            context.start();
+
+            getMockEndpoint("mock:bar").expectedBodiesReceived("admin");
+
+            template.sendBody("direct:username", "Hello World");
+            assertMockEndpointsSatisfied();
+        });
+    }
 }

[camel] 04/06: CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a696cbe3e1b3d151d16eca5d343966103576a805
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Feb 23 10:55:38 2022 +0100

    CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value
---
 .../SecretsManagerNoEnvPropertiesSourceTestIT.java | 42 ++++++++++++++++++++++
 .../SecretsManagerPropertiesSourceTestIT.java      | 26 +++++++++++---
 2 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java
index 25320a3..ec8a32d 100644
--- a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java
+++ b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerNoEnvPropertiesSourceTestIT.java
@@ -246,4 +246,46 @@ public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport
             assertMockEndpointsSatisfied();
         });
     }
+
+    @Test
+    public void testComplexCustomPropertiesNoDefaultValueFunction() throws Exception {
+        context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey"));
+        context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey"));
+        context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region"));
+        Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:username").setBody(simple("{{aws:postgresql/additional1}}")).to("mock:bar");
+                    from("direct:password").setBody(simple("{{aws:postgresql/additional2}}")).to("mock:bar");
+                }
+            });
+            context.start();
+
+            getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+            template.sendBody("direct:username", "Hello World");
+            template.sendBody("direct:password", "Hello World");
+            assertMockEndpointsSatisfied();
+        });
+    }
+
+    @Test
+    public void testComplexCustomPropertiesNotExistentDefaultValueFunction() throws Exception {
+        context.getVaultConfiguration().aws().setAccessKey(System.getProperty("camel.vault.aws.accessKey"));
+        context.getVaultConfiguration().aws().setSecretKey(System.getProperty("camel.vault.aws.secretKey"));
+        context.getVaultConfiguration().aws().setRegion(System.getProperty("camel.vault.aws.region"));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{aws:newsecret/additional1:admin}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin");
+
+        template.sendBody("direct:username", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
 }
diff --git a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java
index 47e646f..7e9158a 100644
--- a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java
+++ b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java
@@ -214,20 +214,36 @@ public class SecretsManagerPropertiesSourceTestIT extends CamelTestSupport {
     @Test
     public void testComplexCustomPropertiesNoDefaultValueFunction() throws Exception {
         Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:username").setBody(simple("{{aws:postgresql/additional1}}")).to("mock:bar");
+                    from("direct:password").setBody(simple("{{aws:postgresql/additional2}}")).to("mock:bar");
+                }
+            });
+            context.start();
+
+            getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+            template.sendBody("direct:username", "Hello World");
+            template.sendBody("direct:password", "Hello World");
+            assertMockEndpointsSatisfied();
+        });
+    }
+
+    @Test
+    public void testComplexCustomPropertiesNotExistentDefaultValueFunction() throws Exception {
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:username").setBody(simple("{{aws:postgresql/additional1}}")).to("mock:bar");
-                from("direct:password").setBody(simple("{{aws:postgresql/additional2}}")).to("mock:bar");
+                from("direct:username").setBody(simple("{{aws:newsecret/additional1:admin}}")).to("mock:bar");
             }
         });
         context.start();
 
-        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin");
 
         template.sendBody("direct:username", "Hello World");
-        template.sendBody("direct:password", "Hello World");
         assertMockEndpointsSatisfied();
-        });
     }
 }

[camel] 05/06: CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 481d0a2d2ee1803fcb0d700cb3a51fa6918cc4fd
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Feb 23 11:00:15 2022 +0100

    CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value
---
 docs/user-manual/modules/ROOT/pages/security.adoc | 30 ++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/docs/user-manual/modules/ROOT/pages/security.adoc b/docs/user-manual/modules/ROOT/pages/security.adoc
index ea51160..8823024 100644
--- a/docs/user-manual/modules/ROOT/pages/security.adoc
+++ b/docs/user-manual/modules/ROOT/pages/security.adoc
@@ -100,6 +100,20 @@ At this point you'll be able to reference a property in the following way by usi
 
 Where `route` will be the name of the secret stored in the AWS Secrets Manager Service.
 
+You could specify a default value in case the secret is not present on AWS Secret Manager:
+
+[source,xml]
+----
+<camelContext>
+    <route>
+        <from uri="direct:start"/>
+        <to uri="{{aws:route:default}}"/>
+    </route>
+</camelContext>
+----
+
+In this case if the secret doesn't exist, the property will fallback to "default" as value.
+
 Also, you are able to get particular field of the secret, if you have for example a secret named database of this form:
 
 [source,json]
@@ -121,13 +135,27 @@ You're able to do get single secret value in your route, like for example:
 <camelContext>
     <route>
         <from uri="direct:start"/>
-        <log message="Username is {{aws:database:username}}"/>
+        <log message="Username is {{aws:database/username}}"/>
     </route>
 </camelContext>
 ----
 
 Or re-use the property as part of an endpoint.
 
+You could specify a default value in case the particular field of secret is not present on AWS Secret Manager:
+
+[source,xml]
+----
+<camelContext>
+    <route>
+        <from uri="direct:start"/>
+        <log message="Username is {{aws:database/username:admin}}"/>
+    </route>
+</camelContext>
+----
+
+In this case if the secret doesn't exist or the secret exists, but the username field is not part of the secret, the property will fallback to "admin" as value.
+
 NOTE: For the moment we are not considering the rotation function, if any will be applied, but it is in the work to be done.
 
 The only requirement is adding `camel-aws-secrets-manager` JAR to your Camel application.

[camel] 01/06: CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 368cbf505e12a9cfb49e6235e73764c56604ce0c
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Feb 23 10:42:19 2022 +0100

    CAMEL-17700 - AWS Secret Manager Properties Source: Provide a fallback default value
---
 .../SecretsManagerPropertiesFunction.java          |  68 +++++++++-----
 .../SecretsManagerPropertiesSourceTestIT.java      | 101 ++++++++++++++++++++-
 2 files changed, 140 insertions(+), 29 deletions(-)

diff --git a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerPropertiesFunction.java b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerPropertiesFunction.java
index 2144be8..93d2a89 100644
--- a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerPropertiesFunction.java
+++ b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerPropertiesFunction.java
@@ -37,6 +37,7 @@ import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
 import software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder;
 import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
 import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;
+import software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException;
 
 /**
  * A {@link PropertiesFunction} that lookup the property value from AWS Secrets Manager service.
@@ -87,11 +88,16 @@ public class SecretsManagerPropertiesFunction extends ServiceSupport implements
                 region = awsVaultConfiguration.getRegion();
             }
         }
-        SecretsManagerClientBuilder clientBuilder = SecretsManagerClient.builder();
-        AwsBasicCredentials cred = AwsBasicCredentials.create(accessKey, secretKey);
-        clientBuilder = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred));
-        clientBuilder.region(Region.of(region));
-        client = clientBuilder.build();
+        if (ObjectHelper.isNotEmpty(accessKey) && ObjectHelper.isNotEmpty(secretKey) && ObjectHelper.isNotEmpty(region)) {
+            SecretsManagerClientBuilder clientBuilder = SecretsManagerClient.builder();
+            AwsBasicCredentials cred = AwsBasicCredentials.create(accessKey, secretKey);
+            clientBuilder = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred));
+            clientBuilder.region(Region.of(region));
+            client = clientBuilder.build();
+        } else {
+            throw new RuntimeCamelException(
+                    "Using the AWS Secrets Manager Properties Function requires setting AWS credentials as application properties or environment variables");
+        }
     }
 
     @Override
@@ -112,15 +118,19 @@ public class SecretsManagerPropertiesFunction extends ServiceSupport implements
         String key = remainder;
         String subkey = null;
         String returnValue = null;
-
-        if (remainder.contains(":")) {
+        String defaultValue = null;
+        if (remainder.contains("/")) {
+            key = StringHelper.before(remainder, "/");
+            subkey = StringHelper.after(remainder, "/");
+            defaultValue = StringHelper.after(subkey, ":");
+        } else if (remainder.contains(":")) {
             key = StringHelper.before(remainder, ":");
-            subkey = StringHelper.after(remainder, ":");
+            defaultValue = StringHelper.after(remainder, ":");
         }
 
         if (key != null) {
             try {
-                returnValue = getSecretFromSource(key, subkey);
+                returnValue = getSecretFromSource(key, subkey, defaultValue);
             } catch (JsonProcessingException e) {
                 throw new RuntimeCamelException("Something went wrong while recovering " + key + " from vault");
             }
@@ -130,28 +140,38 @@ public class SecretsManagerPropertiesFunction extends ServiceSupport implements
     }
 
     private String getSecretFromSource(
-            String key, String subkey)
+            String key, String subkey, String defaultValue)
             throws JsonProcessingException {
         String returnValue;
         GetSecretValueRequest request;
         GetSecretValueRequest.Builder builder = GetSecretValueRequest.builder();
         builder.secretId(key);
         request = builder.build();
-        GetSecretValueResponse secret = client.getSecretValue(request);
-        returnValue = secret.secretString();
-        if (secret.secretString() != null) {
-            returnValue = secret.secretString();
-        } else {
-            returnValue = new String(Base64.getDecoder().decode(secret.secretBinary().asByteBuffer()).array());
-        }
-        if (subkey != null) {
-            ObjectMapper mapper = new ObjectMapper();
-            JsonNode actualObj = mapper.readTree(returnValue);
-            JsonNode field = actualObj.get(subkey);
-            if (ObjectHelper.isNotEmpty(field)) {
-                returnValue = field.textValue();
+        try {
+            GetSecretValueResponse secret = client.getSecretValue(request);
+            if (ObjectHelper.isNotEmpty(secret.secretString())) {
+                returnValue = secret.secretString();
+            } else {
+                returnValue = new String(Base64.getDecoder().decode(secret.secretBinary().asByteBuffer()).array());
+            }
+            if (ObjectHelper.isNotEmpty(subkey)) {
+                ObjectMapper mapper = new ObjectMapper();
+                JsonNode actualObj = mapper.readTree(returnValue);
+                JsonNode field = actualObj.get(subkey);
+                if (ObjectHelper.isNotEmpty(field)) {
+                    returnValue = field.textValue();
+                } else {
+                    returnValue = null;
+                }
+            }
+            if (ObjectHelper.isEmpty(returnValue)) {
+                returnValue = defaultValue;
+            }
+        } catch (ResourceNotFoundException ex) {
+            if (ObjectHelper.isNotEmpty(defaultValue)) {
+                returnValue = defaultValue;
             } else {
-                returnValue = null;
+                throw ex;
             }
         }
         return returnValue;
diff --git a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java
index 3416c47..b8b928e 100644
--- a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java
+++ b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/integration/SecretsManagerPropertiesSourceTestIT.java
@@ -51,8 +51,8 @@ public class SecretsManagerPropertiesSourceTestIT extends CamelTestSupport {
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:username").setBody(simple("{{aws:database_sample:username}}")).to("mock:bar");
-                from("direct:password").setBody(simple("{{aws:database_sample:password}}")).to("mock:bar");
+                from("direct:username").setBody(simple("{{aws:database_sample/username}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{aws:database_sample/password}}")).to("mock:bar");
             }
         });
         context.start();
@@ -69,8 +69,8 @@ public class SecretsManagerPropertiesSourceTestIT extends CamelTestSupport {
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:username").setBody(simple("{{aws:normalkey:username}}")).to("mock:bar");
-                from("direct:password").setBody(simple("{{aws:normalkey:password}}")).to("mock:bar");
+                from("direct:username").setBody(simple("{{aws:normalkey/username}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{aws:normalkey/password}}")).to("mock:bar");
             }
         });
         context.start();
@@ -107,7 +107,7 @@ public class SecretsManagerPropertiesSourceTestIT extends CamelTestSupport {
             context.addRoutes(new RouteBuilder() {
                 @Override
                 public void configure() throws Exception {
-                    from("direct:username").setBody(simple("{{aws:database_sample:not_existent}}")).to("mock:bar");
+                    from("direct:username").setBody(simple("{{aws:database_sample/not_existent}}")).to("mock:bar");
                 }
             });
             context.start();
@@ -119,4 +119,95 @@ public class SecretsManagerPropertiesSourceTestIT extends CamelTestSupport {
         });
     }
 
+    @Test
+    public void testComplexCustomPropertiesDefaultValueFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{aws:postgresql/additional1:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{aws:postgresql/additional2:secret}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testComplexCustomPropertiesDefaultValueExceptionFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{aws:test-3/additional1:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{aws:test-3/additional2:secret}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testComplexCustomPropertiesExceptionFunction() throws Exception {
+        Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:username").setBody(simple("{{aws:test-3/additional1}}")).to("mock:bar");
+                    from("direct:password").setBody(simple("{{aws:test-3/additional2}}")).to("mock:bar");
+                }
+            });
+            context.start();
+
+            getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+            template.sendBody("direct:username", "Hello World");
+            template.sendBody("direct:password", "Hello World");
+            assertMockEndpointsSatisfied();
+        });
+    }
+
+    @Test
+    public void testComplexSimpleDefaultValueExceptionFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{aws:test-3:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{aws:test-1:secret}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "secret");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testComplexSimpleNoDefaultValueExceptionFunction() throws Exception {
+        Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:username").setBody(simple("{{aws:secretsuper}}")).to("mock:bar");
+                }
+            });
+            context.start();
+
+            getMockEndpoint("mock:bar").expectedBodiesReceived("admin");
+
+            template.sendBody("direct:username", "Hello World");
+            assertMockEndpointsSatisfied();
+        });
+    }
 }

[camel] 06/06: Regen

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 458d019a0e27a5947b8f21fb0495e50dca49f68f
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Feb 23 14:26:57 2022 +0100

    Regen
---
 .../apache/camel/catalog/schemas/camel-spring.xsd  | 110 ++++++++++++---------
 1 file changed, 65 insertions(+), 45 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
index f038a14..fbe3ff0 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
@@ -13871,26 +13871,6 @@ be configured on a parent level.
             ]]></xs:documentation>
           </xs:annotation>
         </xs:attribute>
-        <xs:attribute name="type" type="xs:string">
-          <xs:annotation>
-            <xs:documentation xml:lang="en"><![CDATA[
-Sets the class name to use for binding from input to POJO for the incoming data
-This option will override what may be configured on a parent level. The name of
-the class of the input data. Append a to the end of the name if you want the
-input to be an array type.
-            ]]></xs:documentation>
-          </xs:annotation>
-        </xs:attribute>
-        <xs:attribute name="outType" type="xs:string">
-          <xs:annotation>
-            <xs:documentation xml:lang="en"><![CDATA[
-Sets the class name to use for binding from POJO to output for the outgoing data
-This option will override what may be configured on a parent level The name of
-the class of the input data. Append a to the end of the name if you want the
-input to be an array type.
-            ]]></xs:documentation>
-          </xs:annotation>
-        </xs:attribute>
         <xs:attribute name="bindingMode" type="xs:string">
           <xs:annotation>
             <xs:documentation xml:lang="en"><![CDATA[
@@ -13935,7 +13915,7 @@ value: false
           <xs:annotation>
             <xs:documentation xml:lang="en"><![CDATA[
 Whether to include or exclude this rest operation in API documentation. The
-default value is true. Default value: true
+default value is true. Default value: false
             ]]></xs:documentation>
           </xs:annotation>
         </xs:attribute>
@@ -13947,6 +13927,26 @@ false
             ]]></xs:documentation>
           </xs:annotation>
         </xs:attribute>
+        <xs:attribute name="type" type="xs:string">
+          <xs:annotation>
+            <xs:documentation xml:lang="en"><![CDATA[
+Sets the class name to use for binding from input to POJO for the incoming data
+This option will override what may be configured on a parent level. The name of
+the class of the input data. Append a to the end of the name if you want the
+input to be an array type.
+            ]]></xs:documentation>
+          </xs:annotation>
+        </xs:attribute>
+        <xs:attribute name="outType" type="xs:string">
+          <xs:annotation>
+            <xs:documentation xml:lang="en"><![CDATA[
+Sets the class name to use for binding from POJO to output for the outgoing data
+This option will override what may be configured on a parent level The name of
+the class of the input data. Append a to the end of the name if you want the
+input to be an array type.
+            ]]></xs:documentation>
+          </xs:annotation>
+        </xs:attribute>
       </xs:extension>
     </xs:complexContent>
   </xs:complexType>
@@ -14406,20 +14406,6 @@ The hostname to use for exposing the REST service.
         ]]></xs:documentation>
       </xs:annotation>
     </xs:attribute>
-    <xs:attribute name="port" type="xs:string">
-      <xs:annotation>
-        <xs:documentation xml:lang="en"><![CDATA[
-The port number to use for exposing the REST service. Notice if you use servlet
-component then the port number configured here does not apply, as the port
-number in use is the actual port number the servlet component is using. eg if
-using Apache Tomcat its the tomcat http port, if using Apache Karaf its the HTTP
-service in Karaf that uses port 8181 by default etc. Though in those situations
-setting the port number here, allows tooling and JMX to know the port number, so
-its recommended to set the port number to the number that the servlet engine
-uses.
-        ]]></xs:documentation>
-      </xs:annotation>
-    </xs:attribute>
     <xs:attribute name="apiHost" type="xs:string">
       <xs:annotation>
         <xs:documentation xml:lang="en"><![CDATA[
@@ -14437,6 +14423,20 @@ is true. Default value: true
         ]]></xs:documentation>
       </xs:annotation>
     </xs:attribute>
+    <xs:attribute name="port" type="xs:string">
+      <xs:annotation>
+        <xs:documentation xml:lang="en"><![CDATA[
+The port number to use for exposing the REST service. Notice if you use servlet
+component then the port number configured here does not apply, as the port
+number in use is the actual port number the servlet component is using. eg if
+using Apache Tomcat its the tomcat http port, if using Apache Karaf its the HTTP
+service in Karaf that uses port 8181 by default etc. Though in those situations
+setting the port number here, allows tooling and JMX to know the port number, so
+its recommended to set the port number to the number that the servlet engine
+uses.
+        ]]></xs:documentation>
+      </xs:annotation>
+    </xs:attribute>
     <xs:attribute name="producerApiDoc" type="xs:string">
       <xs:annotation>
         <xs:documentation xml:lang="en"><![CDATA[
@@ -14469,8 +14469,28 @@ application is deployed using a context-path.
     <xs:attribute name="apiContextRouteId" type="xs:string">
       <xs:annotation>
         <xs:documentation xml:lang="en"><![CDATA[
-Deprecated: Sets the route id to use for the route that services the REST API.
-The route will by default use an auto assigned route id.
+Sets the route id to use for the route that services the REST API. The route
+will by default use an auto assigned route id.
+        ]]></xs:documentation>
+      </xs:annotation>
+    </xs:attribute>
+    <xs:attribute name="apiContextIdPattern" type="xs:string">
+      <xs:annotation>
+        <xs:documentation xml:lang="en"><![CDATA[
+Deprecated: Sets an CamelContext id pattern to only allow Rest APIs from rest
+services within CamelContext's which name matches the pattern. The pattern
+#name# refers to the CamelContext name, to match on the current CamelContext
+only. For any other value, the pattern uses the rules from
+PatternHelper#matchPattern(String,String).
+        ]]></xs:documentation>
+      </xs:annotation>
+    </xs:attribute>
+    <xs:attribute name="apiContextListing" type="xs:boolean">
+      <xs:annotation>
+        <xs:documentation xml:lang="en"><![CDATA[
+Deprecated: Sets whether listing of all available CamelContext's with REST
+services in the JVM is enabled. If enabled it allows to discover these contexts,
+if false then only the current CamelContext is in use. Default value: false
         ]]></xs:documentation>
       </xs:annotation>
     </xs:attribute>
@@ -14571,6 +14591,13 @@ Path of the rest service, such as /foo.
             ]]></xs:documentation>
           </xs:annotation>
         </xs:attribute>
+        <xs:attribute name="tag" type="xs:string">
+          <xs:annotation>
+            <xs:documentation xml:lang="en"><![CDATA[
+To configure a special tag for the operations within this rest definition.
+            ]]></xs:documentation>
+          </xs:annotation>
+        </xs:attribute>
         <xs:attribute name="consumes" type="xs:string">
           <xs:annotation>
             <xs:documentation xml:lang="en"><![CDATA[
@@ -14634,14 +14661,7 @@ value: false
             <xs:documentation xml:lang="en"><![CDATA[
 Whether to include or exclude this rest operation in API documentation. This
 option will override what may be configured on a parent level. The default value
-is true. Default value: true
-            ]]></xs:documentation>
-          </xs:annotation>
-        </xs:attribute>
-        <xs:attribute name="tag" type="xs:string">
-          <xs:annotation>
-            <xs:documentation xml:lang="en"><![CDATA[
-To configure a special tag for the operations within this rest definition.
+is true. Default value: false
             ]]></xs:documentation>
           </xs:annotation>
         </xs:attribute>