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 <[email protected]>
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();
+        });
+    }
 }

Reply via email to