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/03/01 14:10:43 UTC

[camel] branch main updated (5ab1e77 -> 372662e)

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 5ab1e77  CAMEL-17701: camel-core-model - Add labels to EIP options
     new 42cacc3  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new dd5fa6f  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new acd6847  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new 5609422  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new 91edb90  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new 8ad3655  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new c7561fc  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new 710637f  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new c984b42  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new 0e3e81d  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new 0f7a04e  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new a0c2349  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new 26b6057  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
     new 372662e  CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

The 14 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:
 .../main/camel-main-configuration-metadata.json    |   5 +-
 .../camel-google-secret-manager/pom.xml            |   4 +
 .../org/apache/camel/properties-function/gcp       |   2 +
 .../GoogleSecretManagerPropertiesFunction.java     | 192 ++++++++++++++++++++
 ...leSecretManagerPropertiesNoEnvSourceTestIT.java | 198 +++++++++++++++++++++
 .../GoogleSecretManagerPropertiesSourceTestIT.java | 190 ++++++++++++++++++++
 ...nfiguration.java => GcpVaultConfiguration.java} |  36 ++--
 .../org/apache/camel/vault/VaultConfiguration.java |  19 ++
 .../AwsVaultConfigurationPropertiesConfigurer.java |   6 +
 ...GcpVaultConfigurationPropertiesConfigurer.java} |  50 +++---
 .../camel-main-configuration-metadata.json         |   5 +-
 ...ache.camel.main.GcpVaultConfigurationProperties |   2 +
 core/camel-main/src/main/docs/main.adoc            |  10 ++
 .../org/apache/camel/main/BaseMainSupport.java     |   4 +
 .../camel/main/DefaultConfigurationConfigurer.java |   7 +
 ...s.java => GcpVaultConfigurationProperties.java} |  35 ++--
 .../camel/main/VaultConfigurationProperties.java   |  11 ++
 .../java/org/apache/camel/main/MainVaultTest.java  |  48 ++++-
 .../maven/packaging/PrepareCamelMainMojo.java      |  21 ++-
 19 files changed, 784 insertions(+), 61 deletions(-)
 create mode 100644 components/camel-google/camel-google-secret-manager/src/generated/resources/META-INF/services/org/apache/camel/properties-function/gcp
 create mode 100644 components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
 create mode 100644 components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesNoEnvSourceTestIT.java
 create mode 100644 components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
 copy core/camel-api/src/main/java/org/apache/camel/vault/{VaultConfiguration.java => GcpVaultConfiguration.java} (56%)
 copy core/camel-main/src/generated/java/org/apache/camel/main/{AwsVaultConfigurationPropertiesConfigurer.java => GcpVaultConfigurationPropertiesConfigurer.java} (52%)
 create mode 100644 core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.GcpVaultConfigurationProperties
 copy core/camel-main/src/main/java/org/apache/camel/main/{VaultConfigurationProperties.java => GcpVaultConfigurationProperties.java} (64%)

[camel] 07/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 c7561fc6b98d0ff56c98c228298e348b49678c55
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 14:28:49 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 components/camel-google/camel-google-secret-manager/pom.xml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/components/camel-google/camel-google-secret-manager/pom.xml b/components/camel-google/camel-google-secret-manager/pom.xml
index 823dd64..dbabb71 100644
--- a/components/camel-google/camel-google-secret-manager/pom.xml
+++ b/components/camel-google/camel-google-secret-manager/pom.xml
@@ -87,6 +87,10 @@
             <artifactId>google-auth-library-oauth2-http</artifactId>
             <version>${google-auth-library-oauth2-http-version}</version>
         </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>org.apache.camel</groupId>

[camel] 14/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 372662e432b020ebf8a5a5e06e0e4c4657acb3ce
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 15:07:22 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 ...leSecretManagerPropertiesNoEnvSourceTestIT.java | 198 +++++++++++++++++++++
 1 file changed, 198 insertions(+)

diff --git a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesNoEnvSourceTestIT.java b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesNoEnvSourceTestIT.java
new file mode 100644
index 0000000..31662ef
--- /dev/null
+++ b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesNoEnvSourceTestIT.java
@@ -0,0 +1,198 @@
+/*
+ * 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.google.secret.manager.integration;
+
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperties;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+// Must be manually tested. Provide your own accessKey and secretKey using -Dcamel.vault.gcp.serviceAccountKey and -Dcamel.vault.gcp.projectId
+@EnabledIfSystemProperties({
+        @EnabledIfSystemProperty(named = "camel.vault.gcp.serviceAccountKey", matches = ".*",
+                                 disabledReason = "Service Account Key not provided"),
+        @EnabledIfSystemProperty(named = "camel.vault.gcp.projectId", matches = ".*",
+                                 disabledReason = "Project Id not provided")
+})
+public class GoogleSecretManagerPropertiesNoEnvSourceTestIT extends CamelTestSupport {
+
+    @Test
+    public void testFunction() throws Exception {
+        context.getVaultConfiguration().gcp().setServiceAccountKey(System.getProperty("camel.vault.gcp.serviceAccountKey"));
+        context.getVaultConfiguration().gcp().setProjectId(System.getProperty("camel.vault.gcp.projectId"));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").setBody(simple("{{gcp:hello}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("hello");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testComplexPropertiesFunction() throws Exception {
+        context.getVaultConfiguration().gcp().setServiceAccountKey(System.getProperty("camel.vault.gcp.serviceAccountKey"));
+        context.getVaultConfiguration().gcp().setProjectId(System.getProperty("camel.vault.gcp.projectId"));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{gcp:database_sample/username}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{gcp:database_sample/password}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "password123");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testComplexPropertiesWithDefaultFunction() throws Exception {
+        context.getVaultConfiguration().gcp().setServiceAccountKey(System.getProperty("camel.vault.gcp.serviceAccountKey"));
+        context.getVaultConfiguration().gcp().setProjectId(System.getProperty("camel.vault.gcp.projectId"));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{gcp:database_sample/username:oscerd}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{gcp:database_sample/password:password}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "password123");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testSecretNotFoundFunction() throws Exception {
+        context.getVaultConfiguration().gcp().setServiceAccountKey(System.getProperty("camel.vault.gcp.serviceAccountKey"));
+        context.getVaultConfiguration().gcp().setProjectId(System.getProperty("camel.vault.gcp.projectId"));
+        Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:start").setBody(simple("{{gcp:testExample}}")).to("mock:bar");
+                }
+            });
+            context.start();
+
+            getMockEndpoint("mock:bar").expectedBodiesReceived("hello");
+
+            template.sendBody("direct:start", "Hello World");
+
+            assertMockEndpointsSatisfied();
+        });
+    }
+
+    @Test
+    public void testComplexCustomPropertiesDefaultValueFunction() throws Exception {
+        context.getVaultConfiguration().gcp().setServiceAccountKey(System.getProperty("camel.vault.gcp.serviceAccountKey"));
+        context.getVaultConfiguration().gcp().setProjectId(System.getProperty("camel.vault.gcp.projectId"));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{gcp:postgresql/additional1:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{gcp: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().gcp().setServiceAccountKey(System.getProperty("camel.vault.gcp.serviceAccountKey"));
+        context.getVaultConfiguration().gcp().setProjectId(System.getProperty("camel.vault.gcp.projectId"));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{gcp:test-3/additional1:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{gcp: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().gcp().setServiceAccountKey(System.getProperty("camel.vault.gcp.serviceAccountKey"));
+        context.getVaultConfiguration().gcp().setProjectId(System.getProperty("camel.vault.gcp.projectId"));
+        Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:username").setBody(simple("{{gcp:test-3/additional1}}")).to("mock:bar");
+                    from("direct:password").setBody(simple("{{gcp: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().gcp().setServiceAccountKey(System.getProperty("camel.vault.gcp.serviceAccountKey"));
+        context.getVaultConfiguration().gcp().setProjectId(System.getProperty("camel.vault.gcp.projectId"));
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{gcp:test-3:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{gcp: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();
+    }
+}

[camel] 13/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 26b605785ed6ba16e5de22df5ba9368261830e39
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 14:58:23 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 .../integration/GoogleSecretManagerPropertiesSourceTestIT.java        | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
index e574c90..76972dc 100644
--- a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
+++ b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
@@ -175,8 +175,8 @@ public class GoogleSecretManagerPropertiesSourceTestIT extends CamelTestSupport
         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");
+                from("direct:username").setBody(simple("{{gcp:test-3:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{gcp:test-1:secret}}")).to("mock:bar");
             }
         });
         context.start();

[camel] 01/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 42cacc37ca4a9ad7c235364f93c1ea6cf147a9d0
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 12:28:54 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 ...nfiguration.java => GcpVaultConfiguration.java} | 36 ++++++++++++++--------
 .../org/apache/camel/vault/VaultConfiguration.java | 19 ++++++++++++
 .../camel/main/DefaultConfigurationConfigurer.java |  7 +++++
 ...s.java => GcpVaultConfigurationProperties.java} | 36 ++++++++++++++--------
 .../camel/main/VaultConfigurationProperties.java   | 12 ++++++++
 .../maven/packaging/PrepareCamelMainMojo.java      | 21 +++++++++++--
 6 files changed, 102 insertions(+), 29 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java
similarity index 56%
copy from core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java
copy to core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java
index 5375d8d..205cbe5 100644
--- a/core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java
+++ b/core/camel-api/src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java
@@ -16,28 +16,38 @@
  */
 package org.apache.camel.vault;
 
+import org.apache.camel.spi.Metadata;
+
 /**
- * Base configuration for access to Vaults.
+ * Configuration for access to AWS Secret.
  */
-public class VaultConfiguration {
+public class GcpVaultConfiguration extends VaultConfiguration {
+
+    @Metadata(secret = true)
+    private String serviceAccountKey;
+    @Metadata
+    private String projectId;
 
-    private AwsVaultConfiguration aws;
+    public String getServiceAccountKey() {
+        return serviceAccountKey;
+    }
 
     /**
-     * AWS Vault Configuration
+     * The Service Account Key location
      */
-    public AwsVaultConfiguration aws() {
-        if (aws == null) {
-            aws = new AwsVaultConfiguration();
-        }
-        return aws;
+    public void setServiceAccountKey(String serviceAccountKey) {
+        this.serviceAccountKey = serviceAccountKey;
     }
 
-    public AwsVaultConfiguration getAwsVaultConfiguration() {
-        return aws;
+    public String getProjectId() {
+        return projectId;
     }
 
-    public void setAwsVaultConfiguration(AwsVaultConfiguration aws) {
-        this.aws = aws;
+    /**
+     * The GCP Project ID
+     */
+    public void setProjectId(String projectId) {
+        this.projectId = projectId;
     }
+
 }
diff --git a/core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java
index 5375d8d..d630ea2 100644
--- a/core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java
+++ b/core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java
@@ -22,6 +22,7 @@ package org.apache.camel.vault;
 public class VaultConfiguration {
 
     private AwsVaultConfiguration aws;
+    private GcpVaultConfiguration gcp;
 
     /**
      * AWS Vault Configuration
@@ -33,6 +34,16 @@ public class VaultConfiguration {
         return aws;
     }
 
+    /**
+     * GCP Vault Configuration
+     */
+    public GcpVaultConfiguration gcp() {
+        if (gcp == null) {
+            gcp = new GcpVaultConfiguration();
+        }
+        return gcp;
+    }
+
     public AwsVaultConfiguration getAwsVaultConfiguration() {
         return aws;
     }
@@ -40,4 +51,12 @@ public class VaultConfiguration {
     public void setAwsVaultConfiguration(AwsVaultConfiguration aws) {
         this.aws = aws;
     }
+
+    public GcpVaultConfiguration getGcpVaultConfiguration() {
+        return gcp;
+    }
+
+    public void setGcpVaultConfiguration(GcpVaultConfiguration gcp) {
+        this.gcp = gcp;
+    }
 }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
index 2c6fe86..5b1a71d 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
@@ -84,6 +84,7 @@ import org.apache.camel.support.jsse.GlobalSSLContextParametersSupplier;
 import org.apache.camel.support.startup.LoggingStartupStepRecorder;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.vault.AwsVaultConfiguration;
+import org.apache.camel.vault.GcpVaultConfiguration;
 import org.apache.camel.vault.VaultConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -549,6 +550,12 @@ public final class DefaultConfigurationConfigurer {
             vault.setAwsVaultConfiguration(aws);
         }
 
+        GcpVaultConfiguration gcp = getSingleBeanOfType(registry, GcpVaultConfiguration.class);
+        if (gcp != null) {
+            VaultConfiguration vault = camelContext.getVaultConfiguration();
+            vault.setGcpVaultConfiguration(gcp);
+        }
+
         // set the default thread pool profile if defined
         initThreadPoolProfiles(registry, camelContext);
     }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
similarity index 62%
copy from core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java
copy to core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
index 0002430..8ef1720 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
@@ -17,14 +17,19 @@
 package org.apache.camel.main;
 
 import org.apache.camel.spi.BootstrapCloseable;
-import org.apache.camel.vault.VaultConfiguration;
+import org.apache.camel.spi.Configurer;
+import org.apache.camel.vault.AwsVaultConfiguration;
+import org.apache.camel.vault.GcpVaultConfiguration;
 
-public class VaultConfigurationProperties extends VaultConfiguration implements BootstrapCloseable {
+/**
+ * Configuration for access to GCP Secret.
+ */
+@Configurer(bootstrap = true)
+public class GcpVaultConfigurationProperties extends GcpVaultConfiguration implements BootstrapCloseable {
 
     private MainConfigurationProperties parent;
-    private AwsVaultConfigurationProperties aws;
 
-    public VaultConfigurationProperties(MainConfigurationProperties parent) {
+    public GcpVaultConfigurationProperties(MainConfigurationProperties parent) {
         this.parent = parent;
     }
 
@@ -35,9 +40,6 @@ public class VaultConfigurationProperties extends VaultConfiguration implements
     @Override
     public void close() {
         parent = null;
-        if (aws != null) {
-            aws.close();
-        }
     }
 
     // getter and setters
@@ -48,12 +50,20 @@ public class VaultConfigurationProperties extends VaultConfiguration implements
     // fluent builders
     // --------------------------------------------------------------
 
-    @Override
-    public AwsVaultConfigurationProperties aws() {
-        if (aws == null) {
-            aws = new AwsVaultConfigurationProperties(parent);
-        }
-        return aws;
+    /**
+     * The Service Account Key location
+     */
+    public GcpVaultConfigurationProperties withServiceAccountKey(String serviceAccountKey) {
+        setServiceAccountKey(serviceAccountKey);
+        return this;
+    }
+
+    /**
+     * The GCP Project ID
+     */
+    public GcpVaultConfigurationProperties withProjectId(String projectId) {
+        setProjectId(projectId);
+        return this;
     }
 
 }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java
index 0002430..4b13d55 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java
@@ -17,12 +17,14 @@
 package org.apache.camel.main;
 
 import org.apache.camel.spi.BootstrapCloseable;
+import org.apache.camel.vault.GcpVaultConfiguration;
 import org.apache.camel.vault.VaultConfiguration;
 
 public class VaultConfigurationProperties extends VaultConfiguration implements BootstrapCloseable {
 
     private MainConfigurationProperties parent;
     private AwsVaultConfigurationProperties aws;
+    private GcpVaultConfigurationProperties gcp;
 
     public VaultConfigurationProperties(MainConfigurationProperties parent) {
         this.parent = parent;
@@ -38,6 +40,9 @@ public class VaultConfigurationProperties extends VaultConfiguration implements
         if (aws != null) {
             aws.close();
         }
+        if (gcp != null) {
+            gcp.close();
+        }
     }
 
     // getter and setters
@@ -56,4 +61,11 @@ public class VaultConfigurationProperties extends VaultConfiguration implements
         return aws;
     }
 
+    @Override
+    public GcpVaultConfigurationProperties gcp() {
+        if (gcp == null) {
+            gcp = new GcpVaultConfigurationProperties(parent);
+        }
+        return gcp;
+    }
 }
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java
index 843fd6e..169fe6e 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCamelMainMojo.java
@@ -197,6 +197,8 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo {
                     prefix = "camel.rest.";
                 } else if (file.getName().contains("AwsVault")) {
                     prefix = "camel.vault.aws.";
+                } else if (file.getName().contains("GcpVault")) {
+                    prefix = "camel.vault.gcp.";
                     // TODO: add more vault providers here
                 } else if (file.getName().contains("Health")) {
                     prefix = "camel.health.";
@@ -230,13 +232,22 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo {
         }
         // include additional vault configuration from camel-api
         // TODO: add more vault providers here
-        File vaultConfig = new File(camelApiDir, "src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java");
+        File awsVaultConfig = new File(camelApiDir, "src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java");
         try {
-            List<MainModel.MainOptionModel> model = parseConfigurationSource(vaultConfig);
+            List<MainModel.MainOptionModel> model = parseConfigurationSource(awsVaultConfig);
             model.forEach(m -> m.setName("camel.vault.aws." + m.getName()));
             data.addAll(model);
         } catch (Exception e) {
-            throw new MojoFailureException("Error parsing file " + restConfig + " due " + e.getMessage(), e);
+            throw new MojoFailureException("Error parsing file " + awsVaultConfig + " due " + e.getMessage(), e);
+        }
+
+        File gcpVaultConfig = new File(camelApiDir, "src/main/java/org/apache/camel/vault/GcpVaultConfiguration.java");
+        try {
+            List<MainModel.MainOptionModel> model = parseConfigurationSource(gcpVaultConfig);
+            model.forEach(m -> m.setName("camel.vault.gcp." + m.getName()));
+            data.addAll(model);
+        } catch (Exception e) {
+            throw new MojoFailureException("Error parsing file " + gcpVaultConfig + " due " + e.getMessage(), e);
         }
 
         // lets sort so they are always ordered (but camel.main in top)
@@ -269,6 +280,10 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo {
                     new MainGroupModel(
                             "camel.vault.aws", "Camel AWS Vault configurations",
                             "org.apache.camel.vault.AwsVaultConfiguration"));
+            model.getGroups().add(
+                    new MainGroupModel(
+                            "camel.vault.gcp", "Camel GCP Vault configurations",
+                            "org.apache.camel.vault.GcpVaultConfiguration"));
             // TODO: add more vault providers here
             model.getGroups()
                     .add(new MainGroupModel(

[camel] 03/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 acd6847892b454bbcfe844e58a0bcec5378daa44
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 13:18:49 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 .../java/org/apache/camel/main/MainVaultTest.java  | 48 +++++++++++++++++++++-
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
index effe4c2..7553d18 100644
--- a/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.main;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.vault.AwsVaultConfiguration;
+import org.apache.camel.vault.GcpVaultConfiguration;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
@@ -26,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 public class MainVaultTest {
 
     @Test
-    public void testMain() throws Exception {
+    public void testMainAws() throws Exception {
         Main main = new Main();
 
         main.addInitialProperty("camel.vault.aws.accessKey", "myKey");
@@ -51,7 +52,7 @@ public class MainVaultTest {
     }
 
     @Test
-    public void testMainFluent() throws Exception {
+    public void testMainAwsFluent() throws Exception {
         Main main = new Main();
         main.configure().vault().aws()
                 .withAccessKey("myKey")
@@ -76,4 +77,47 @@ public class MainVaultTest {
         main.stop();
     }
 
+    @Test
+    public void testMainGcp() throws Exception {
+        Main main = new Main();
+
+        main.addInitialProperty("camel.vault.aws.serviceAccountKey", "file:////myKey");
+        main.addInitialProperty("camel.vault.aws.processId", "gcp-project");
+
+        main.start();
+
+        CamelContext context = main.getCamelContext();
+        assertNotNull(context);
+
+        GcpVaultConfiguration cfg = context.getVaultConfiguration().gcp();
+        assertNotNull(cfg);
+
+        Assertions.assertEquals("file:////myKey", cfg.getServiceAccountKey());
+        Assertions.assertEquals("gcp-project", cfg.getProjectId());
+
+        main.stop();
+    }
+
+    @Test
+    public void testMainGcpFluent() throws Exception {
+        Main main = new Main();
+        main.configure().vault().gcp()
+                .withServiceAccountKey("file:////myKey")
+                .withProjectId("gcp-project")
+                .end();
+
+        main.start();
+
+        CamelContext context = main.getCamelContext();
+        assertNotNull(context);
+
+        GcpVaultConfiguration cfg = context.getVaultConfiguration().gcp();
+        assertNotNull(cfg);
+
+        Assertions.assertEquals("file:////myKey", cfg.getServiceAccountKey());
+        Assertions.assertEquals("gcp-project", cfg.getProjectId());
+
+        main.stop();
+    }
+
 }

[camel] 09/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 c984b42e3cb48958d2792cffd23f32200a58fcc7
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 14:34:55 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 .../GoogleSecretManagerPropertiesSourceTestIT.java   | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
index 473cbbd..4253ba9 100644
--- a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
+++ b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
@@ -48,6 +48,26 @@ public class GoogleSecretManagerPropertiesSourceTestIT extends CamelTestSupport
     @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", matches = ".*")
     @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_PROJECT_ID", matches = ".*")
     @Test
+    public void testComplexPropertiesFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{gcp:database_sample/username}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{gcp:database_sample/password}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "password123");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
+
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", matches = ".*")
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_PROJECT_ID", matches = ".*")
+    @Test
     public void testSecretNotFoundFunction() throws Exception {
         Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
             context.addRoutes(new RouteBuilder() {

[camel] 04/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 560942227d8d924264df57d1d024e6041687b069
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 13:19:54 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 .../camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
index 7553d18..a2001b7 100644
--- a/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
@@ -81,8 +81,8 @@ public class MainVaultTest {
     public void testMainGcp() throws Exception {
         Main main = new Main();
 
-        main.addInitialProperty("camel.vault.aws.serviceAccountKey", "file:////myKey");
-        main.addInitialProperty("camel.vault.aws.processId", "gcp-project");
+        main.addInitialProperty("camel.vault.gcp.serviceAccountKey", "file:////myKey");
+        main.addInitialProperty("camel.vault.gcp.processId", "gcp-project");
 
         main.start();
 

[camel] 05/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 91edb90903ad27211e70651c4642615e4658b342
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 13:33:58 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 .../src/main/java/org/apache/camel/main/BaseMainSupport.java          | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index e43c66d..959a3fa 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -1130,6 +1130,10 @@ public abstract class BaseMainSupport extends BaseService {
                 // TODO: add more vault providers here
                 target = target.aws();
             }
+            if ("gcp".equalsIgnoreCase(name)) {
+                // TODO: add more vault providers here
+                target = target.gcp();
+            }
             // configure all the properties on the vault at once (to ensure they are configured in right order)
             Map<String, Object> config = PropertiesHelper.extractProperties(properties, name + ".");
             setPropertiesOnTarget(camelContext, target, config, "camel.vault." + name + ".", failIfNotSet, true,

[camel] 11/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 0f7a04e6c41113d9140d61a9c467a5a0cc67a4e0
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 14:53:15 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 .../google/secret/manager/GoogleSecretManagerPropertiesFunction.java   | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
index 07973fe..54f138a 100644
--- a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
+++ b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
@@ -128,6 +128,9 @@ public class GoogleSecretManagerPropertiesFunction extends ServiceSupport implem
             key = StringHelper.before(remainder, "/");
             subkey = StringHelper.after(remainder, "/");
             defaultValue = StringHelper.after(subkey, ":");
+            if (subkey.contains(":")) {
+                subkey = StringHelper.before(subkey, ":");
+            }
         } else if (remainder.contains(":")) {
             key = StringHelper.before(remainder, ":");
             defaultValue = StringHelper.after(remainder, ":");

[camel] 02/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 dd5fa6f956cd334c0cae30f4300ff06a027aba9b
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 13:12:05 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 .../main/camel-main-configuration-metadata.json    |  5 ++-
 .../AwsVaultConfigurationPropertiesConfigurer.java |  6 +++
 ...GcpVaultConfigurationPropertiesConfigurer.java} | 50 ++++++++++------------
 .../camel-main-configuration-metadata.json         |  5 ++-
 ...ache.camel.main.GcpVaultConfigurationProperties |  2 +
 core/camel-main/src/main/docs/main.adoc            | 10 +++++
 .../main/GcpVaultConfigurationProperties.java      |  1 -
 .../camel/main/VaultConfigurationProperties.java   |  1 -
 8 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
index 5b98061..19e2c3c 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
@@ -5,6 +5,7 @@
     { "name": "camel.health", "description": "Camel Health Check configurations", "sourceType": "org.apache.camel.main.HealthConfigurationProperties" },
     { "name": "camel.rest", "description": "Camel Rest-DSL configurations", "sourceType": "org.apache.camel.spi.RestConfiguration" },
     { "name": "camel.vault.aws", "description": "Camel AWS Vault configurations", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration" },
+    { "name": "camel.vault.gcp", "description": "Camel GCP Vault configurations", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration" },
     { "name": "camel.faulttolerance", "description": "Fault Tolerance EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.FaultToleranceConfigurationProperties" },
     { "name": "camel.resilience4j", "description": "Resilience4j EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.Resilience4jConfigurationProperties" },
     { "name": "camel.hystrix", "description": "Hystrix (deprecated) EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.HystrixConfigurationProperties" },
@@ -229,6 +230,8 @@
     { "name": "camel.vault.aws.accessKey", "description": "The AWS access key", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
     { "name": "camel.vault.aws.defaultCredentialsProvider", "description": "Define if we want to use the AWS Default Credentials Provider or not", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.vault.aws.region", "description": "The AWS region", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
-    { "name": "camel.vault.aws.secretKey", "description": "The AWS secret key", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" }
+    { "name": "camel.vault.aws.secretKey", "description": "The AWS secret key", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+    { "name": "camel.vault.gcp.projectId", "description": "The GCP Project ID", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+    { "name": "camel.vault.gcp.serviceAccountKey", "description": "The Service Account Key location", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" }
   ]
 }
diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java
index 910b357..1727ab3 100644
--- a/core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java
+++ b/core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java
@@ -27,6 +27,8 @@ public class AwsVaultConfigurationPropertiesConfigurer extends org.apache.camel.
         case "AwsVaultConfiguration": target.setAwsVaultConfiguration(property(camelContext, org.apache.camel.vault.AwsVaultConfiguration.class, value)); return true;
         case "defaultcredentialsprovider":
         case "DefaultCredentialsProvider": target.setDefaultCredentialsProvider(property(camelContext, boolean.class, value)); return true;
+        case "gcpvaultconfiguration":
+        case "GcpVaultConfiguration": target.setGcpVaultConfiguration(property(camelContext, org.apache.camel.vault.GcpVaultConfiguration.class, value)); return true;
         case "region":
         case "Region": target.setRegion(property(camelContext, java.lang.String.class, value)); return true;
         case "secretkey":
@@ -44,6 +46,8 @@ public class AwsVaultConfigurationPropertiesConfigurer extends org.apache.camel.
         case "AwsVaultConfiguration": return org.apache.camel.vault.AwsVaultConfiguration.class;
         case "defaultcredentialsprovider":
         case "DefaultCredentialsProvider": return boolean.class;
+        case "gcpvaultconfiguration":
+        case "GcpVaultConfiguration": return org.apache.camel.vault.GcpVaultConfiguration.class;
         case "region":
         case "Region": return java.lang.String.class;
         case "secretkey":
@@ -62,6 +66,8 @@ public class AwsVaultConfigurationPropertiesConfigurer extends org.apache.camel.
         case "AwsVaultConfiguration": return target.getAwsVaultConfiguration();
         case "defaultcredentialsprovider":
         case "DefaultCredentialsProvider": return target.isDefaultCredentialsProvider();
+        case "gcpvaultconfiguration":
+        case "GcpVaultConfiguration": return target.getGcpVaultConfiguration();
         case "region":
         case "Region": return target.getRegion();
         case "secretkey":
diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/GcpVaultConfigurationPropertiesConfigurer.java
similarity index 52%
copy from core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java
copy to core/camel-main/src/generated/java/org/apache/camel/main/GcpVaultConfigurationPropertiesConfigurer.java
index 910b357..8f0e826 100644
--- a/core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java
+++ b/core/camel-main/src/generated/java/org/apache/camel/main/GcpVaultConfigurationPropertiesConfigurer.java
@@ -9,28 +9,26 @@ import org.apache.camel.spi.PropertyConfigurerGetter;
 import org.apache.camel.spi.ConfigurerStrategy;
 import org.apache.camel.spi.GeneratedPropertyConfigurer;
 import org.apache.camel.util.CaseInsensitiveMap;
-import org.apache.camel.main.AwsVaultConfigurationProperties;
+import org.apache.camel.main.GcpVaultConfigurationProperties;
 
 /**
  * Generated by camel build tools - do NOT edit this file!
  */
 @SuppressWarnings("unchecked")
-public class AwsVaultConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
+public class GcpVaultConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter {
 
     @Override
     public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {
-        org.apache.camel.main.AwsVaultConfigurationProperties target = (org.apache.camel.main.AwsVaultConfigurationProperties) obj;
+        org.apache.camel.main.GcpVaultConfigurationProperties target = (org.apache.camel.main.GcpVaultConfigurationProperties) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
-        case "accesskey":
-        case "AccessKey": target.setAccessKey(property(camelContext, java.lang.String.class, value)); return true;
         case "awsvaultconfiguration":
         case "AwsVaultConfiguration": target.setAwsVaultConfiguration(property(camelContext, org.apache.camel.vault.AwsVaultConfiguration.class, value)); return true;
-        case "defaultcredentialsprovider":
-        case "DefaultCredentialsProvider": target.setDefaultCredentialsProvider(property(camelContext, boolean.class, value)); return true;
-        case "region":
-        case "Region": target.setRegion(property(camelContext, java.lang.String.class, value)); return true;
-        case "secretkey":
-        case "SecretKey": target.setSecretKey(property(camelContext, java.lang.String.class, value)); return true;
+        case "gcpvaultconfiguration":
+        case "GcpVaultConfiguration": target.setGcpVaultConfiguration(property(camelContext, org.apache.camel.vault.GcpVaultConfiguration.class, value)); return true;
+        case "projectid":
+        case "ProjectId": target.setProjectId(property(camelContext, java.lang.String.class, value)); return true;
+        case "serviceaccountkey":
+        case "ServiceAccountKey": target.setServiceAccountKey(property(camelContext, java.lang.String.class, value)); return true;
         default: return false;
         }
     }
@@ -38,34 +36,30 @@ public class AwsVaultConfigurationPropertiesConfigurer extends org.apache.camel.
     @Override
     public Class<?> getOptionType(String name, boolean ignoreCase) {
         switch (ignoreCase ? name.toLowerCase() : name) {
-        case "accesskey":
-        case "AccessKey": return java.lang.String.class;
         case "awsvaultconfiguration":
         case "AwsVaultConfiguration": return org.apache.camel.vault.AwsVaultConfiguration.class;
-        case "defaultcredentialsprovider":
-        case "DefaultCredentialsProvider": return boolean.class;
-        case "region":
-        case "Region": return java.lang.String.class;
-        case "secretkey":
-        case "SecretKey": return java.lang.String.class;
+        case "gcpvaultconfiguration":
+        case "GcpVaultConfiguration": return org.apache.camel.vault.GcpVaultConfiguration.class;
+        case "projectid":
+        case "ProjectId": return java.lang.String.class;
+        case "serviceaccountkey":
+        case "ServiceAccountKey": return java.lang.String.class;
         default: return null;
         }
     }
 
     @Override
     public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
-        org.apache.camel.main.AwsVaultConfigurationProperties target = (org.apache.camel.main.AwsVaultConfigurationProperties) obj;
+        org.apache.camel.main.GcpVaultConfigurationProperties target = (org.apache.camel.main.GcpVaultConfigurationProperties) obj;
         switch (ignoreCase ? name.toLowerCase() : name) {
-        case "accesskey":
-        case "AccessKey": return target.getAccessKey();
         case "awsvaultconfiguration":
         case "AwsVaultConfiguration": return target.getAwsVaultConfiguration();
-        case "defaultcredentialsprovider":
-        case "DefaultCredentialsProvider": return target.isDefaultCredentialsProvider();
-        case "region":
-        case "Region": return target.getRegion();
-        case "secretkey":
-        case "SecretKey": return target.getSecretKey();
+        case "gcpvaultconfiguration":
+        case "GcpVaultConfiguration": return target.getGcpVaultConfiguration();
+        case "projectid":
+        case "ProjectId": return target.getProjectId();
+        case "serviceaccountkey":
+        case "ServiceAccountKey": return target.getServiceAccountKey();
         default: return null;
         }
     }
diff --git a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index 5b98061..19e2c3c 100644
--- a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++ b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -5,6 +5,7 @@
     { "name": "camel.health", "description": "Camel Health Check configurations", "sourceType": "org.apache.camel.main.HealthConfigurationProperties" },
     { "name": "camel.rest", "description": "Camel Rest-DSL configurations", "sourceType": "org.apache.camel.spi.RestConfiguration" },
     { "name": "camel.vault.aws", "description": "Camel AWS Vault configurations", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration" },
+    { "name": "camel.vault.gcp", "description": "Camel GCP Vault configurations", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration" },
     { "name": "camel.faulttolerance", "description": "Fault Tolerance EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.FaultToleranceConfigurationProperties" },
     { "name": "camel.resilience4j", "description": "Resilience4j EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.Resilience4jConfigurationProperties" },
     { "name": "camel.hystrix", "description": "Hystrix (deprecated) EIP Circuit Breaker configurations", "sourceType": "org.apache.camel.main.HystrixConfigurationProperties" },
@@ -229,6 +230,8 @@
     { "name": "camel.vault.aws.accessKey", "description": "The AWS access key", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
     { "name": "camel.vault.aws.defaultCredentialsProvider", "description": "Define if we want to use the AWS Default Credentials Provider or not", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
     { "name": "camel.vault.aws.region", "description": "The AWS region", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
-    { "name": "camel.vault.aws.secretKey", "description": "The AWS secret key", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" }
+    { "name": "camel.vault.aws.secretKey", "description": "The AWS secret key", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+    { "name": "camel.vault.gcp.projectId", "description": "The GCP Project ID", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+    { "name": "camel.vault.gcp.serviceAccountKey", "description": "The Service Account Key location", "sourceType": "org.apache.camel.vault.GcpVaultConfiguration", "type": "string", "javaType": "java.lang.String" }
   ]
 }
diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.GcpVaultConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.GcpVaultConfigurationProperties
new file mode 100644
index 0000000..ddc3a1e
--- /dev/null
+++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.GcpVaultConfigurationProperties
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.main.GcpVaultConfigurationPropertiesConfigurer
diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc
index bc2ca85..4f8222c 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -209,6 +209,16 @@ The camel.vault.aws supports 4 options, which are listed below.
 | *camel.vault.aws.secretKey* | The AWS secret key |  | String
 |===
 
+=== Camel GCP Vault configurations
+The camel.vault.gcp supports 2 options, which are listed below.
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *camel.vault.gcp.projectId* | The GCP Project ID |  | String
+| *camel.vault.gcp.serviceAccount{zwsp}Key* | The Service Account Key location |  | String
+|===
+
 === Fault Tolerance EIP Circuit Breaker configurations
 The camel.faulttolerance supports 13 options, which are listed below.
 
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
index 8ef1720..38353bd 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/GcpVaultConfigurationProperties.java
@@ -18,7 +18,6 @@ package org.apache.camel.main;
 
 import org.apache.camel.spi.BootstrapCloseable;
 import org.apache.camel.spi.Configurer;
-import org.apache.camel.vault.AwsVaultConfiguration;
 import org.apache.camel.vault.GcpVaultConfiguration;
 
 /**
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java
index 4b13d55..4e53b86 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java
@@ -17,7 +17,6 @@
 package org.apache.camel.main;
 
 import org.apache.camel.spi.BootstrapCloseable;
-import org.apache.camel.vault.GcpVaultConfiguration;
 import org.apache.camel.vault.VaultConfiguration;
 
 public class VaultConfigurationProperties extends VaultConfiguration implements BootstrapCloseable {

[camel] 06/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 8ad3655c575512f521b044b3c2842bf350f609f2
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 13:36:51 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
index a2001b7..d4c7ac3 100644
--- a/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
@@ -82,7 +82,7 @@ public class MainVaultTest {
         Main main = new Main();
 
         main.addInitialProperty("camel.vault.gcp.serviceAccountKey", "file:////myKey");
-        main.addInitialProperty("camel.vault.gcp.processId", "gcp-project");
+        main.addInitialProperty("camel.vault.gcp.projectId", "gcp-project");
 
         main.start();
 

[camel] 08/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 710637f4d3f875c9186da6f51660ab961afeafb6
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 14:30:25 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 .../org/apache/camel/properties-function/gcp       |   2 +
 .../GoogleSecretManagerPropertiesFunction.java     | 189 +++++++++++++++++++++
 .../GoogleSecretManagerPropertiesSourceTestIT.java | 130 ++++++++++++++
 3 files changed, 321 insertions(+)

diff --git a/components/camel-google/camel-google-secret-manager/src/generated/resources/META-INF/services/org/apache/camel/properties-function/gcp b/components/camel-google/camel-google-secret-manager/src/generated/resources/META-INF/services/org/apache/camel/properties-function/gcp
new file mode 100644
index 0000000..b8e8b3a
--- /dev/null
+++ b/components/camel-google/camel-google-secret-manager/src/generated/resources/META-INF/services/org/apache/camel/properties-function/gcp
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.google.secret.manager.GoogleSecretManagerPropertiesFunction
diff --git a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
new file mode 100644
index 0000000..07973fe
--- /dev/null
+++ b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerPropertiesFunction.java
@@ -0,0 +1,189 @@
+/*
+ * 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.google.secret.manager;
+
+import java.io.InputStream;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.api.gax.core.FixedCredentialsProvider;
+import com.google.api.gax.rpc.NotFoundException;
+import com.google.auth.Credentials;
+import com.google.auth.oauth2.ServiceAccountCredentials;
+import com.google.cloud.secretmanager.v1.AccessSecretVersionResponse;
+import com.google.cloud.secretmanager.v1.SecretManagerServiceClient;
+import com.google.cloud.secretmanager.v1.SecretManagerServiceSettings;
+import com.google.cloud.secretmanager.v1.SecretVersionName;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.spi.PropertiesFunction;
+import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.support.service.ServiceSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StringHelper;
+import org.apache.camel.vault.GcpVaultConfiguration;
+
+/**
+ * A {@link PropertiesFunction} that lookup the property value from GCP Secrets Manager service.
+ * <p/>
+ * The credentials to access Secrets Manager is defined using three environment variables representing the static
+ * credentials:
+ * <ul>
+ * <li><tt>CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY</tt></li>
+ * <li><tt>CAMEL_VAULT_GCP_PROJECT_ID</tt></li>
+ * </ul>
+ * <p/>
+ *
+ * Otherwise it is possible to specify the credentials as properties:
+ *
+ * <ul>
+ * <li><tt>camel.vault.aws.serviceAccountKey</tt></li>
+ * <li><tt>camel.vault.aws.projectId</tt></li>
+ * </ul>
+ * <p/>
+ *
+ * This implementation is to return the secret value associated with a key. The properties related to this kind of
+ * Properties Function are all prefixed with <tt>gcp:</tt>. For example asking for <tt>gcp:token</tt>, will return the
+ * secret value associated to the secret named token on GCP Secrets Manager.
+ *
+ * Another way of retrieving a secret value is using the following notation <tt>gcp:database/username</tt>: in this case
+ * the field username of the secret database will be returned. As a fallback, the user could provide a default value,
+ * which will be returned in case the secret doesn't exist, the secret has been marked for deletion or, for example, if
+ * a particular field of the secret doesn't exist. For using this feature, the user could use the following notation
+ * <tt>gcp:database/username:admin</tt>. The admin value will be returned as default value, if the conditions above were
+ * all met.
+ */
+
+@org.apache.camel.spi.annotations.PropertiesFunction("gcp")
+public class GoogleSecretManagerPropertiesFunction extends ServiceSupport implements PropertiesFunction, CamelContextAware {
+
+    private static final String CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY";
+    private static final String CAMEL_VAULT_GCP_PROJECT_ID = "CAMEL_VAULT_GCP_PROJECT_ID";
+    private CamelContext camelContext;
+    private SecretManagerServiceClient client;
+    private String projectId;
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        String serviceAccountKey = System.getenv(CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY);
+        projectId = System.getenv(CAMEL_VAULT_GCP_PROJECT_ID);
+        if (ObjectHelper.isEmpty(serviceAccountKey) && ObjectHelper.isEmpty(projectId)) {
+            GcpVaultConfiguration gcpVaultConfiguration = getCamelContext().getVaultConfiguration().gcp();
+            if (ObjectHelper.isNotEmpty(gcpVaultConfiguration)) {
+                serviceAccountKey = gcpVaultConfiguration.getServiceAccountKey();
+                projectId = gcpVaultConfiguration.getProjectId();
+            }
+        }
+        if (ObjectHelper.isNotEmpty(serviceAccountKey) && ObjectHelper.isNotEmpty(projectId)) {
+            InputStream resolveMandatoryResourceAsInputStream
+                    = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), serviceAccountKey);
+            Credentials myCredentials = ServiceAccountCredentials
+                    .fromStream(resolveMandatoryResourceAsInputStream);
+            SecretManagerServiceSettings settings = SecretManagerServiceSettings.newBuilder()
+                    .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)).build();
+            client = SecretManagerServiceClient.create(settings);
+        } else {
+            throw new RuntimeCamelException(
+                    "Using the AWS Secrets Manager Properties Function requires setting AWS credentials as application properties or environment variables");
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (client != null) {
+            client.close();
+        }
+        super.doStop();
+    }
+
+    @Override
+    public String getName() {
+        return "aws";
+    }
+
+    @Override
+    public String apply(String remainder) {
+        String key = remainder;
+        String subkey = null;
+        String returnValue = null;
+        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, ":");
+            defaultValue = StringHelper.after(remainder, ":");
+        }
+
+        if (key != null) {
+            try {
+                returnValue = getSecretFromSource(key, subkey, defaultValue);
+            } catch (JsonProcessingException e) {
+                throw new RuntimeCamelException("Something went wrong while recovering " + key + " from vault");
+            }
+        }
+
+        return returnValue;
+    }
+
+    private String getSecretFromSource(
+            String key, String subkey, String defaultValue)
+            throws JsonProcessingException {
+        String returnValue = null;
+        try {
+            SecretVersionName secretVersionName = SecretVersionName.of(projectId, key, "latest");
+            AccessSecretVersionResponse response = client.accessSecretVersion(secretVersionName);
+            if (ObjectHelper.isNotEmpty(response)) {
+                returnValue = response.getPayload().getData().toStringUtf8();
+            }
+            if (ObjectHelper.isNotEmpty(subkey) && ObjectHelper.isNotEmpty(returnValue)) {
+                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 (NotFoundException ex) {
+            if (ObjectHelper.isNotEmpty(defaultValue)) {
+                returnValue = defaultValue;
+            } else {
+                throw ex;
+            }
+        }
+        return returnValue;
+    }
+
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    @Override
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+}
diff --git a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
new file mode 100644
index 0000000..473cbbd
--- /dev/null
+++ b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
@@ -0,0 +1,130 @@
+/*
+ * 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.google.secret.manager.integration;
+
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class GoogleSecretManagerPropertiesSourceTestIT extends CamelTestSupport {
+
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", matches = ".*")
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_PROJECT_ID", matches = ".*")
+    @Test
+    public void testFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").setBody(simple("{{gcp:hello}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("hello");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", matches = ".*")
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_PROJECT_ID", matches = ".*")
+    @Test
+    public void testSecretNotFoundFunction() throws Exception {
+        Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:start").setBody(simple("{{gcp:testExample}}")).to("mock:bar");
+                }
+            });
+            context.start();
+
+            getMockEndpoint("mock:bar").expectedBodiesReceived("hello");
+
+            template.sendBody("direct:start", "Hello World");
+
+            assertMockEndpointsSatisfied();
+        });
+    }
+
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", matches = ".*")
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_PROJECT_ID", matches = ".*")
+    @Test
+    public void testComplexCustomPropertiesDefaultValueFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{gcp:postgresql/additional1:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{gcp: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();
+    }
+
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", matches = ".*")
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_PROJECT_ID", matches = ".*")
+    @Test
+    public void testComplexCustomPropertiesDefaultValueExceptionFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{gcp:test-3/additional1:admin}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{gcp: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();
+    }
+
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", matches = ".*")
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_PROJECT_ID", matches = ".*")
+    @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("{{gcp:test-3/additional1}}")).to("mock:bar");
+                    from("direct:password").setBody(simple("{{gcp: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();
+        });
+    }
+}

[camel] 10/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 0e3e81d605dfd3f7aaa22831daa3d84ec0b086b2
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 14:36:39 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 .../GoogleSecretManagerPropertiesSourceTestIT.java   | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
index 4253ba9..7321799 100644
--- a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
+++ b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
@@ -68,6 +68,26 @@ public class GoogleSecretManagerPropertiesSourceTestIT extends CamelTestSupport
     @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", matches = ".*")
     @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_PROJECT_ID", matches = ".*")
     @Test
+    public void testComplexPropertiesWithDefaultFunction() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:username").setBody(simple("{{gcp:database_sample/username:oscerd}}")).to("mock:bar");
+                from("direct:password").setBody(simple("{{gcp:database_sample/password:password}}")).to("mock:bar");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:bar").expectedBodiesReceived("admin", "password123");
+
+        template.sendBody("direct:username", "Hello World");
+        template.sendBody("direct:password", "Hello World");
+        assertMockEndpointsSatisfied();
+    }
+
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", matches = ".*")
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_PROJECT_ID", matches = ".*")
+    @Test
     public void testSecretNotFoundFunction() throws Exception {
         Exception exception = assertThrows(FailedToCreateRouteException.class, () -> {
             context.addRoutes(new RouteBuilder() {

[camel] 12/14: CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager

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 a0c2349667b1d2424414a1eb55f6b9243adc413f
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 1 14:54:51 2022 +0100

    CAMEL-17684 - Support ability to load properties from Vault/Secrets cloud services - GCP Secrets Manager
---
 .../GoogleSecretManagerPropertiesSourceTestIT.java   | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
index 7321799..e574c90 100644
--- a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
+++ b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/integration/GoogleSecretManagerPropertiesSourceTestIT.java
@@ -167,4 +167,24 @@ public class GoogleSecretManagerPropertiesSourceTestIT extends CamelTestSupport
             assertMockEndpointsSatisfied();
         });
     }
+
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_SERVICE_ACCOUNT_KEY", matches = ".*")
+    @EnabledIfEnvironmentVariable(named = "CAMEL_VAULT_GCP_PROJECT_ID", matches = ".*")
+    @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();
+    }
 }