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/19 13:57:32 UTC

[camel] branch main updated (ba1a644 -> e5463a5)

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 ba1a644  CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws secrets manager
     new c34805b  CAMEL-17644: camel-core - Add VaultConfiguration SPI
     new 21a01c1  CAMEL-17644: camel-core - Add VaultConfiguration SPI
     new 8ae0c2d  CAMEL-17644: camel-core - Add VaultConfiguration SPI
     new 8894721  CAMEL-17644: camel-core - Add VaultConfiguration SPI
     new 1c54076  CAMEL-17644: camel-core - Add VaultConfiguration SPI
     new 3c5ae5f  CAMEL-17644: camel-core - Add VaultConfiguration SPI
     new 4c8b60a  CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws secrets manager
     new 9b11b18  CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws secrets manager
     new e5463a5  CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws secrets manager

The 9 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    |  6 +-
 .../SecretsManagerPropertiesFunction.java          | 33 +++++-----
 .../SecretsManagerNoEnvPropertiesSourceTestIT.java | 44 ++++++-------
 .../main/java/org/apache/camel/CamelContext.java   | 15 +++++
 .../apache/camel/vault/AwsVaultConfiguration.java  | 66 +++++++++++++++++++
 .../org/apache/camel/vault/VaultConfiguration.java | 36 ++++++++++
 .../camel/impl/engine/AbstractCamelContext.java    | 12 ++++
 .../camel/impl/ExtendedCamelContextConfigurer.java |  6 ++
 .../camel/impl/lw/LightweightCamelContext.java     | 11 ++++
 .../impl/lw/LightweightRuntimeCamelContext.java    | 11 ++++
 .../AwsVaultConfigurationPropertiesConfigurer.java | 61 +++++++++++++++++
 .../camel-main-configuration-metadata.json         |  6 +-
 ...ache.camel.main.AwsVaultConfigurationProperties |  2 +
 ....apache.camel.main.VaultConfigurationProperties |  2 +
 core/camel-main/src/main/docs/main.adoc            | 11 ++++
 .../main/AwsVaultConfigurationProperties.java      | 76 ++++++++++++++++++++++
 .../org/apache/camel/main/BaseMainSupport.java     | 45 +++++++++++++
 .../camel/main/MainConfigurationProperties.java    | 22 +++++++
 .../camel/main/VaultConfigurationProperties.java   | 59 +++++++++++++++++
 .../java/org/apache/camel/main/MainVaultTest.java  | 75 +++++++++++++++++++++
 docs/user-manual/modules/ROOT/pages/security.adoc  | 69 +++++++++++++++++++-
 .../maven/packaging/PrepareCamelMainMojo.java      | 18 +++++
 22 files changed, 641 insertions(+), 45 deletions(-)
 create mode 100644 core/camel-api/src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java
 create mode 100644 core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java
 create mode 100644 core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java
 create mode 100644 core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.AwsVaultConfigurationProperties
 create mode 100644 core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.VaultConfigurationProperties
 create mode 100644 core/camel-main/src/main/java/org/apache/camel/main/AwsVaultConfigurationProperties.java
 create mode 100644 core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java
 create mode 100644 core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java

[camel] 07/09: CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws 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 4c8b60a276403f66cfe589cb60abaa920e0edfb5
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Sat Feb 19 14:07:11 2022 +0100

    CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws secrets manager
---
 .../SecretsManagerPropertiesFunction.java          | 22 +++--------
 .../SecretsManagerNoEnvPropertiesSourceTestIT.java | 44 ++++++++++------------
 2 files changed, 25 insertions(+), 41 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 6c14068..a195fb5 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
@@ -26,11 +26,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spi.PropertiesFunction;
 import org.apache.camel.support.service.ServiceSupport;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StringHelper;
+import org.apache.camel.vault.AwsVaultConfiguration;
 import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
 import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
 import software.amazon.awssdk.regions.Region;
@@ -61,9 +61,6 @@ public class SecretsManagerPropertiesFunction extends ServiceSupport implements
     private static final String CAMEL_AWS_VAULT_ACCESS_KEY_ENV = "CAMEL_VAULT_AWS_ACCESS_KEY";
     private static final String CAMEL_AWS_VAULT_SECRET_KEY_ENV = "CAMEL_VAULT_AWS_SECRET_KEY";
     private static final String CAMEL_AWS_VAULT_REGION_ENV = "CAMEL_VAULT_AWS_REGION";
-    private static final String CAMEL_AWS_VAULT_ACCESS_KEY_PROP = "camel.aws.vault.access.key";
-    private static final String CAMEL_AWS_VAULT_SECRET_KEY_PROP = "camel.aws.vault.secret.key";
-    private static final String CAMEL_AWS_VAULT_REGION_PROP = "camel.aws.vault.region";
     private CamelContext camelContext;
     private SecretsManagerClient client;
 
@@ -74,18 +71,11 @@ public class SecretsManagerPropertiesFunction extends ServiceSupport implements
         String secretKey = System.getenv(CAMEL_AWS_VAULT_SECRET_KEY_ENV);
         String region = System.getenv(CAMEL_AWS_VAULT_REGION_ENV);
         if (ObjectHelper.isEmpty(accessKey) && ObjectHelper.isEmpty(secretKey) && ObjectHelper.isEmpty(region)) {
-            PropertiesComponent pc = getCamelContext().getPropertiesComponent();
-            Optional<String> tmpAccessKey = pc.resolveProperty(CAMEL_AWS_VAULT_ACCESS_KEY_PROP);
-            if (tmpAccessKey.isPresent()) {
-                accessKey = tmpAccessKey.get();
-            }
-            Optional<String> tmpSecretKey = pc.resolveProperty(CAMEL_AWS_VAULT_SECRET_KEY_PROP);
-            if (tmpSecretKey.isPresent()) {
-                secretKey = tmpSecretKey.get();
-            }
-            Optional<String> tmpRegion = pc.resolveProperty(CAMEL_AWS_VAULT_REGION_PROP);
-            if (tmpRegion.isPresent()) {
-                region = tmpRegion.get();
+            AwsVaultConfiguration awsVaultConfiguration = getCamelContext().getVaultConfiguration().aws();
+            if (ObjectHelper.isNotEmpty(awsVaultConfiguration)) {
+                accessKey = awsVaultConfiguration.getAccessKey();
+                secretKey = awsVaultConfiguration.getSecretKey();
+                region = awsVaultConfiguration.getRegion();
             }
         }
         SecretsManagerClientBuilder clientBuilder = SecretsManagerClient.builder();
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 83251f2..3633b6b 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
@@ -23,25 +23,23 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.EnabledIfSystemProperties;
 import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
 
-import static org.apache.camel.util.CollectionHelper.propertiesOf;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
-// Must be manually tested. Provide your own accessKey and secretKey using -Dcamel.aws.vault.access.key, -Dcamel.aws.vault.secret.key and -Dcamel.aws.vault.region
+// Must be manually tested. Provide your own accessKey and secretKey using -Dcamel.vault.aws.accessKey, -Dcamel.vault.aws.secretKey and -Dcamel.vault.aws.region
 @EnabledIfSystemProperties({
-        @EnabledIfSystemProperty(named = "camel.aws.vault.access.key", matches = ".*",
+        @EnabledIfSystemProperty(named = "camel.vault.aws.accessKey", matches = ".*",
                                  disabledReason = "Access key not provided"),
-        @EnabledIfSystemProperty(named = "camel.aws.vault.secret.key", matches = ".*",
+        @EnabledIfSystemProperty(named = "camel.vault.aws.secretKey", matches = ".*",
                                  disabledReason = "Secret key not provided"),
-        @EnabledIfSystemProperty(named = "camel.aws.vault.region", matches = ".*", disabledReason = "Region not provided"),
+        @EnabledIfSystemProperty(named = "camel.vault.aws.region", matches = ".*", disabledReason = "Region not provided"),
 })
 public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport {
 
     @Test
     public void testFunction() throws Exception {
-        context.getPropertiesComponent().setOverrideProperties(
-                propertiesOf("camel.aws.vault.access.key", System.getProperty("camel.aws.vault.access.key"),
-                        "camel.aws.vault.secret.key", System.getProperty("camel.aws.vault.secret.key"),
-                        "camel.aws.vault.region", System.getProperty("camel.aws.vault.region")));
+        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 {
@@ -59,10 +57,9 @@ public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport
 
     @Test
     public void testComplexPropertiesFunction() throws Exception {
-        context.getPropertiesComponent().setOverrideProperties(
-                propertiesOf("camel.aws.vault.access.key", System.getProperty("camel.aws.vault.access.key"),
-                        "camel.aws.vault.secret.key", System.getProperty("camel.aws.vault.secret.key"),
-                        "camel.aws.vault.region", System.getProperty("camel.aws.vault.region")));
+        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 {
@@ -81,10 +78,9 @@ public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport
 
     @Test
     public void testComplexCustomPropertiesFunction() throws Exception {
-        context.getPropertiesComponent().setOverrideProperties(
-                propertiesOf("camel.aws.vault.access.key", System.getProperty("camel.aws.vault.access.key"),
-                        "camel.aws.vault.secret.key", System.getProperty("camel.aws.vault.secret.key"),
-                        "camel.aws.vault.region", System.getProperty("camel.aws.vault.region")));
+        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 {
@@ -103,10 +99,9 @@ public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport
 
     @Test
     public void testSecretNotFoundFunction() throws Exception {
-        context.getPropertiesComponent().setOverrideProperties(
-                propertiesOf("camel.aws.vault.access.key", System.getProperty("camel.aws.vault.access.key"),
-                        "camel.aws.vault.secret.key", System.getProperty("camel.aws.vault.secret.key"),
-                        "camel.aws.vault.region", System.getProperty("camel.aws.vault.region")));
+        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
@@ -126,10 +121,9 @@ public class SecretsManagerNoEnvPropertiesSourceTestIT extends CamelTestSupport
 
     @Test
     public void testComplexNoSubkeyPropertiesFunction() throws Exception {
-        context.getPropertiesComponent().setOverrideProperties(
-                propertiesOf("camel.aws.vault.access.key", System.getProperty("camel.aws.vault.access.key"),
-                        "camel.aws.vault.secret.key", System.getProperty("camel.aws.vault.secret.key"),
-                        "camel.aws.vault.region", System.getProperty("camel.aws.vault.region")));
+        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

[camel] 02/09: CAMEL-17644: camel-core - Add VaultConfiguration SPI

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 21a01c19029c9ac00e573f93bf15a983ff164c94
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Feb 19 08:41:18 2022 +0100

    CAMEL-17644: camel-core - Add VaultConfiguration SPI
---
 .../camel-main-configuration-metadata.json         |  6 +-
 core/camel-main/src/main/docs/main.adoc            | 11 ++++
 .../java/org/apache/camel/main/MainVaultTest.java  | 75 ++++++++++++++++++++++
 .../maven/packaging/PrepareCamelMainMojo.java      | 14 ++++
 4 files changed, 105 insertions(+), 1 deletion(-)

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 a3fef16..5404d48 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
@@ -4,6 +4,7 @@
     { "name": "camel.threadpool", "description": "Camel Thread Pool configurations", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties" },
     { "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", "description": "Camel Vault configurations", "sourceType": "org.apache.camel.spi.VaultConfiguration" },
     { "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" },
@@ -227,6 +228,9 @@
     { "name": "camel.threadpool.maxQueueSize", "description": "Sets the default maximum number of tasks in the work queue. Use -1 or an unbounded queue", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "integer", "javaType": "java.lang.Integer" },
     { "name": "camel.threadpool.poolSize", "description": "Sets the default core pool size (threads to keep minimum in pool)", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "integer", "javaType": "java.lang.Integer" },
     { "name": "camel.threadpool.rejectedPolicy", "description": "Sets the default handler for tasks which cannot be executed by the thread pool.", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy", "enum": [ "Abort", "CallerRuns", "DiscardOldest", "Discard" ] },
-    { "name": "camel.threadpool.timeUnit", "description": "Sets the default time unit used for keep alive time", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "java.util.concurrent.TimeUnit" }
+    { "name": "camel.threadpool.timeUnit", "description": "Sets the default time unit used for keep alive time", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "java.util.concurrent.TimeUnit" },
+    { "name": "camel.vault.awsAccessKey", "description": "The AWS access key", "sourceType": "org.apache.camel.spi.VaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+    { "name": "camel.vault.awsRegion", "description": "The AWS region", "sourceType": "org.apache.camel.spi.VaultConfiguration", "type": "string", "javaType": "java.lang.String" },
+    { "name": "camel.vault.awsSecretKey", "description": "The AWS secret key", "sourceType": "org.apache.camel.spi.VaultConfiguration", "type": "string", "javaType": "java.lang.String" }
   ]
 }
diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc
index a29a394..8621ec1 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -200,6 +200,17 @@ The camel.rest supports 28 options, which are listed below.
 | *camel.rest.xmlDataFormat* | Sets a custom xml data format to be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance. |  | String
 |===
 
+=== Camel Vault configurations
+The camel.vault supports 3 options, which are listed below.
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *camel.vault.awsAccessKey* | The AWS access key |  | String
+| *camel.vault.awsRegion* | The AWS region |  | String
+| *camel.vault.awsSecretKey* | The AWS secret key |  | String
+|===
+
 === Fault Tolerance EIP Circuit Breaker configurations
 The camel.faulttolerance supports 13 options, which are listed below.
 
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
new file mode 100644
index 0000000..ac7b43e
--- /dev/null
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.main;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.VaultConfiguration;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class MainVaultTest {
+
+    @Test
+    public void testMain() throws Exception {
+        Main main = new Main();
+
+        main.addInitialProperty("camel.vault.awsAccessKey", "myKey");
+        main.addInitialProperty("camel.vault.awsSecretKey", "mySecret");
+        main.addInitialProperty("camel.vault.awsRegion", "myRegion");
+
+        main.start();
+
+        CamelContext context = main.getCamelContext();
+        assertNotNull(context);
+
+        VaultConfiguration cfg = context.getVaultConfiguration();
+        assertNotNull(cfg);
+
+        Assertions.assertEquals("myKey", cfg.getAwsAccessKey());
+        Assertions.assertEquals("mySecret", cfg.getAwsSecretKey());
+        Assertions.assertEquals("myRegion", cfg.getAwsRegion());
+
+        main.stop();
+    }
+
+    @Test
+    public void testMainFluent() throws Exception {
+        Main main = new Main();
+        main.configure().vault()
+                .withAwsAccessKey("myKey")
+                .withAwsSecretKey("mySecret")
+                .withAwsRegion("myRegion")
+                .end();
+
+        main.start();
+
+        CamelContext context = main.getCamelContext();
+        assertNotNull(context);
+
+        VaultConfiguration cfg = context.getVaultConfiguration();
+        assertNotNull(cfg);
+
+        Assertions.assertEquals("myKey", cfg.getAwsAccessKey());
+        Assertions.assertEquals("mySecret", cfg.getAwsSecretKey());
+        Assertions.assertEquals("myRegion", cfg.getAwsRegion());
+
+        main.stop();
+    }
+
+}
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 5eedad6..a405f4f 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
@@ -195,6 +195,8 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo {
                     prefix = "camel.faulttolerance.";
                 } else if (file.getName().contains("Rest")) {
                     prefix = "camel.rest.";
+                } else if (file.getName().contains("Vault")) {
+                    prefix = "camel.vault.";
                 } else if (file.getName().contains("Health")) {
                     prefix = "camel.health.";
                 } else if (file.getName().contains("Lra")) {
@@ -225,6 +227,15 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo {
         } catch (Exception e) {
             throw new MojoFailureException("Error parsing file " + restConfig + " due " + e.getMessage(), e);
         }
+        // include additional vault configuration from camel-api
+        File vaultConfig = new File(camelApiDir, "src/main/java/org/apache/camel/spi/VaultConfiguration.java");
+        try {
+            List<MainModel.MainOptionModel> model = parseConfigurationSource(vaultConfig);
+            model.forEach(m -> m.setName("camel.vault." + m.getName()));
+            data.addAll(model);
+        } catch (Exception e) {
+            throw new MojoFailureException("Error parsing file " + restConfig + " due " + e.getMessage(), e);
+        }
 
         // lets sort so they are always ordered (but camel.main in top)
         data.sort((o1, o2) -> {
@@ -252,6 +263,9 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo {
             model.getGroups().add(
                     new MainGroupModel(
                             "camel.rest", "Camel Rest-DSL configurations", "org.apache.camel.spi.RestConfiguration"));
+            model.getGroups().add(
+                    new MainGroupModel(
+                            "camel.vault", "Camel Vault configurations", "org.apache.camel.spi.VaultConfiguration"));
             model.getGroups()
                     .add(new MainGroupModel(
                             "camel.faulttolerance", "Fault Tolerance EIP Circuit Breaker configurations",

[camel] 03/09: CAMEL-17644: camel-core - Add VaultConfiguration SPI

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 8ae0c2d620d522536df2b5abcb915e184392029a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Feb 19 10:34:47 2022 +0100

    CAMEL-17644: camel-core - Add VaultConfiguration SPI
---
 .../main/java/org/apache/camel/CamelContext.java   |  4 +-
 .../AwsVaultConfiguration.java}                    | 38 +++++++-------
 .../camel/{spi => vault}/VaultConfiguration.java   | 46 ++++------------
 .../camel/impl/engine/AbstractCamelContext.java    |  2 +-
 .../camel/impl/ExtendedCamelContextConfigurer.java |  4 +-
 .../camel/impl/lw/LightweightCamelContext.java     |  2 +-
 .../impl/lw/LightweightRuntimeCamelContext.java    |  2 +-
 .../AwsVaultConfigurationPropertiesConfigurer.java | 61 ++++++++++++++++++++++
 .../VaultConfigurationPropertiesConfigurer.java    | 61 ----------------------
 .../camel-main-configuration-metadata.json         |  8 +--
 ...ache.camel.main.AwsVaultConfigurationProperties |  2 +
 core/camel-main/src/main/docs/main.adoc            | 10 ++--
 ...s.java => AwsVaultConfigurationProperties.java} | 20 +++----
 .../org/apache/camel/main/BaseMainSupport.java     | 33 ++++++++++--
 .../camel/main/MainConfigurationProperties.java    |  4 +-
 .../camel/main/VaultConfigurationProperties.java   | 55 ++++---------------
 .../java/org/apache/camel/main/MainVaultTest.java  | 32 ++++++------
 .../maven/packaging/PrepareCamelMainMojo.java      | 14 +++--
 18 files changed, 185 insertions(+), 213 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
index 669b56c..d4ddd58 100644
--- a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
+++ b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
@@ -52,8 +52,8 @@ import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spi.Validator;
 import org.apache.camel.spi.ValidatorRegistry;
-import org.apache.camel.spi.VaultConfiguration;
 import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.vault.VaultConfiguration;
 
 /**
  * Interface used to represent the CamelContext used to configure routes and the policies to use during message
@@ -674,7 +674,7 @@ public interface CamelContext extends CamelContextLifecycle, RuntimeConfiguratio
     RestConfiguration getRestConfiguration();
 
     /**
-     * Sets a custom {@link org.apache.camel.spi.VaultConfiguration}
+     * Sets a custom {@link VaultConfiguration}
      *
      * @param vaultConfiguration the vault configuration
      */
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java
similarity index 60%
copy from core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java
copy to core/camel-api/src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java
index b50ee0c..4b2bb00 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java
+++ b/core/camel-api/src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java
@@ -14,51 +14,53 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.spi;
+package org.apache.camel.vault;
+
+import org.apache.camel.spi.Metadata;
 
 /**
- * Configuration for access to Vaults.
+ * Configuration for access to AWS Secret.
  */
-public class VaultConfiguration {
+public class AwsVaultConfiguration extends VaultConfiguration {
 
     @Metadata(secret = true)
-    private String awsAccessKey;
+    private String accessKey;
     @Metadata(secret = true)
-    private String awsSecretKey;
+    private String secretKey;
     @Metadata
-    private String awsRegion;
+    private String region;
 
-    public String getAwsAccessKey() {
-        return awsAccessKey;
+    public String getAccessKey() {
+        return accessKey;
     }
 
     /**
      * The AWS access key
      */
-    public void setAwsAccessKey(String awsAccessKey) {
-        this.awsAccessKey = awsAccessKey;
+    public void setAccessKey(String accessKey) {
+        this.accessKey = accessKey;
     }
 
-    public String getAwsSecretKey() {
-        return awsSecretKey;
+    public String getSecretKey() {
+        return secretKey;
     }
 
     /**
      * The AWS secret key
      */
-    public void setAwsSecretKey(String awsSecretKey) {
-        this.awsSecretKey = awsSecretKey;
+    public void setSecretKey(String secretKey) {
+        this.secretKey = secretKey;
     }
 
-    public String getAwsRegion() {
-        return awsRegion;
+    public String getRegion() {
+        return region;
     }
 
     /**
      * The AWS region
      */
-    public void setAwsRegion(String awsRegion) {
-        this.awsRegion = awsRegion;
+    public void setRegion(String region) {
+        this.region = region;
     }
 
 }
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java
similarity index 50%
rename from core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java
rename to core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java
index b50ee0c..bcbcdb8 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java
+++ b/core/camel-api/src/main/java/org/apache/camel/vault/VaultConfiguration.java
@@ -14,51 +14,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.spi;
+package org.apache.camel.vault;
 
 /**
- * Configuration for access to Vaults.
+ * Base configuration for access to Vaults.
  */
 public class VaultConfiguration {
 
-    @Metadata(secret = true)
-    private String awsAccessKey;
-    @Metadata(secret = true)
-    private String awsSecretKey;
-    @Metadata
-    private String awsRegion;
-
-    public String getAwsAccessKey() {
-        return awsAccessKey;
-    }
-
-    /**
-     * The AWS access key
-     */
-    public void setAwsAccessKey(String awsAccessKey) {
-        this.awsAccessKey = awsAccessKey;
-    }
-
-    public String getAwsSecretKey() {
-        return awsSecretKey;
-    }
-
-    /**
-     * The AWS secret key
-     */
-    public void setAwsSecretKey(String awsSecretKey) {
-        this.awsSecretKey = awsSecretKey;
-    }
-
-    public String getAwsRegion() {
-        return awsRegion;
-    }
+    private AwsVaultConfiguration aws;
 
     /**
-     * The AWS region
+     * AWS Vault Configuration
      */
-    public void setAwsRegion(String awsRegion) {
-        this.awsRegion = awsRegion;
+    public AwsVaultConfiguration aws() {
+        if (aws == null) {
+            aws = new AwsVaultConfiguration();
+        }
+        return aws;
     }
 
 }
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 9ebd16c..dd55c69 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -169,7 +169,6 @@ import org.apache.camel.spi.UriFactoryResolver;
 import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spi.Validator;
 import org.apache.camel.spi.ValidatorRegistry;
-import org.apache.camel.spi.VaultConfiguration;
 import org.apache.camel.spi.XMLRoutesDefinitionLoader;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.EndpointHelper;
@@ -189,6 +188,7 @@ import org.apache.camel.util.StopWatch;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.TimeUtils;
 import org.apache.camel.util.URISupport;
+import org.apache.camel.vault.VaultConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
diff --git a/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java b/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java
index 8eeef0d..8a2bf2a 100644
--- a/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java
+++ b/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java
@@ -212,7 +212,7 @@ public class ExtendedCamelContextConfigurer extends org.apache.camel.support.com
         case "uuidgenerator":
         case "UuidGenerator": target.setUuidGenerator(property(camelContext, org.apache.camel.spi.UuidGenerator.class, value)); return true;
         case "vaultconfiguration":
-        case "VaultConfiguration": target.setVaultConfiguration(property(camelContext, org.apache.camel.spi.VaultConfiguration.class, value)); return true;
+        case "VaultConfiguration": target.setVaultConfiguration(property(camelContext, org.apache.camel.vault.VaultConfiguration.class, value)); return true;
         case "xmlroutesdefinitionloader":
         case "XMLRoutesDefinitionLoader": target.setXMLRoutesDefinitionLoader(property(camelContext, org.apache.camel.spi.XMLRoutesDefinitionLoader.class, value)); return true;
         default: return false;
@@ -413,7 +413,7 @@ public class ExtendedCamelContextConfigurer extends org.apache.camel.support.com
         case "uuidgenerator":
         case "UuidGenerator": return org.apache.camel.spi.UuidGenerator.class;
         case "vaultconfiguration":
-        case "VaultConfiguration": return org.apache.camel.spi.VaultConfiguration.class;
+        case "VaultConfiguration": return org.apache.camel.vault.VaultConfiguration.class;
         case "xmlroutesdefinitionloader":
         case "XMLRoutesDefinitionLoader": return org.apache.camel.spi.XMLRoutesDefinitionLoader.class;
         default: return null;
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
index b5c5dff..531584e 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
@@ -149,10 +149,10 @@ import org.apache.camel.spi.UriFactoryResolver;
 import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spi.Validator;
 import org.apache.camel.spi.ValidatorRegistry;
-import org.apache.camel.spi.VaultConfiguration;
 import org.apache.camel.spi.XMLRoutesDefinitionLoader;
 import org.apache.camel.support.DefaultRegistry;
 import org.apache.camel.support.jsse.SSLContextParameters;
+import org.apache.camel.vault.VaultConfiguration;
 
 @Experimental
 public class LightweightCamelContext implements ExtendedCamelContext, CatalogCamelContext, ModelCamelContext {
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
index e344bc5..1bc5b25 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
@@ -144,7 +144,6 @@ import org.apache.camel.spi.UriFactoryResolver;
 import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spi.Validator;
 import org.apache.camel.spi.ValidatorRegistry;
-import org.apache.camel.spi.VaultConfiguration;
 import org.apache.camel.spi.XMLRoutesDefinitionLoader;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.NormalizedUri;
@@ -154,6 +153,7 @@ import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.TimeUtils;
 import org.apache.camel.util.URISupport;
+import org.apache.camel.vault.VaultConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
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
new file mode 100644
index 0000000..8ef2142
--- /dev/null
+++ b/core/camel-main/src/generated/java/org/apache/camel/main/AwsVaultConfigurationPropertiesConfigurer.java
@@ -0,0 +1,61 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.main;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+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;
+
+/**
+ * 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 {
+
+    @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;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "accesskey":
+        case "AccessKey": target.setAccessKey(property(camelContext, java.lang.String.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;
+        default: return false;
+        }
+    }
+
+    @Override
+    public Class<?> getOptionType(String name, boolean ignoreCase) {
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "accesskey":
+        case "AccessKey": return java.lang.String.class;
+        case "region":
+        case "Region": return java.lang.String.class;
+        case "secretkey":
+        case "SecretKey": 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;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "accesskey":
+        case "AccessKey": return target.getAccessKey();
+        case "region":
+        case "Region": return target.getRegion();
+        case "secretkey":
+        case "SecretKey": return target.getSecretKey();
+        default: return null;
+        }
+    }
+}
+
diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/VaultConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/VaultConfigurationPropertiesConfigurer.java
deleted file mode 100644
index ba2c389..0000000
--- a/core/camel-main/src/generated/java/org/apache/camel/main/VaultConfigurationPropertiesConfigurer.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Generated by camel build tools - do NOT edit this file! */
-package org.apache.camel.main;
-
-import java.util.Map;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
-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.VaultConfigurationProperties;
-
-/**
- * Generated by camel build tools - do NOT edit this file!
- */
-@SuppressWarnings("unchecked")
-public class VaultConfigurationPropertiesConfigurer 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.VaultConfigurationProperties target = (org.apache.camel.main.VaultConfigurationProperties) obj;
-        switch (ignoreCase ? name.toLowerCase() : name) {
-        case "awsaccesskey":
-        case "AwsAccessKey": target.setAwsAccessKey(property(camelContext, java.lang.String.class, value)); return true;
-        case "awsregion":
-        case "AwsRegion": target.setAwsRegion(property(camelContext, java.lang.String.class, value)); return true;
-        case "awssecretkey":
-        case "AwsSecretKey": target.setAwsSecretKey(property(camelContext, java.lang.String.class, value)); return true;
-        default: return false;
-        }
-    }
-
-    @Override
-    public Class<?> getOptionType(String name, boolean ignoreCase) {
-        switch (ignoreCase ? name.toLowerCase() : name) {
-        case "awsaccesskey":
-        case "AwsAccessKey": return java.lang.String.class;
-        case "awsregion":
-        case "AwsRegion": return java.lang.String.class;
-        case "awssecretkey":
-        case "AwsSecretKey": return java.lang.String.class;
-        default: return null;
-        }
-    }
-
-    @Override
-    public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
-        org.apache.camel.main.VaultConfigurationProperties target = (org.apache.camel.main.VaultConfigurationProperties) obj;
-        switch (ignoreCase ? name.toLowerCase() : name) {
-        case "awsaccesskey":
-        case "AwsAccessKey": return target.getAwsAccessKey();
-        case "awsregion":
-        case "AwsRegion": return target.getAwsRegion();
-        case "awssecretkey":
-        case "AwsSecretKey": return target.getAwsSecretKey();
-        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 5404d48..c5bd162 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
@@ -4,7 +4,7 @@
     { "name": "camel.threadpool", "description": "Camel Thread Pool configurations", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties" },
     { "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", "description": "Camel Vault configurations", "sourceType": "org.apache.camel.spi.VaultConfiguration" },
+    { "name": "camel.vault.aws", "description": "Camel AWS Vault configurations", "sourceType": "org.apache.camel.vault.AwsVaultConfiguration" },
     { "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,8 +229,8 @@
     { "name": "camel.threadpool.poolSize", "description": "Sets the default core pool size (threads to keep minimum in pool)", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "integer", "javaType": "java.lang.Integer" },
     { "name": "camel.threadpool.rejectedPolicy", "description": "Sets the default handler for tasks which cannot be executed by the thread pool.", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy", "enum": [ "Abort", "CallerRuns", "DiscardOldest", "Discard" ] },
     { "name": "camel.threadpool.timeUnit", "description": "Sets the default time unit used for keep alive time", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "java.util.concurrent.TimeUnit" },
-    { "name": "camel.vault.awsAccessKey", "description": "The AWS access key", "sourceType": "org.apache.camel.spi.VaultConfiguration", "type": "string", "javaType": "java.lang.String" },
-    { "name": "camel.vault.awsRegion", "description": "The AWS region", "sourceType": "org.apache.camel.spi.VaultConfiguration", "type": "string", "javaType": "java.lang.String" },
-    { "name": "camel.vault.awsSecretKey", "description": "The AWS secret key", "sourceType": "org.apache.camel.spi.VaultConfiguration", "type": "string", "javaType": "java.lang.String" }
+    { "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.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" }
   ]
 }
diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.AwsVaultConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.AwsVaultConfigurationProperties
new file mode 100644
index 0000000..9334aae
--- /dev/null
+++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.AwsVaultConfigurationProperties
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.main.AwsVaultConfigurationPropertiesConfigurer
diff --git a/core/camel-main/src/main/docs/main.adoc b/core/camel-main/src/main/docs/main.adoc
index 8621ec1..2553118 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -200,15 +200,15 @@ The camel.rest supports 28 options, which are listed below.
 | *camel.rest.xmlDataFormat* | Sets a custom xml data format to be used. Important: This option is only for setting a custom name of the data format, not to refer to an existing data format instance. |  | String
 |===
 
-=== Camel Vault configurations
-The camel.vault supports 3 options, which are listed below.
+=== Camel AWS Vault configurations
+The camel.vault.aws supports 3 options, which are listed below.
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *camel.vault.awsAccessKey* | The AWS access key |  | String
-| *camel.vault.awsRegion* | The AWS region |  | String
-| *camel.vault.awsSecretKey* | The AWS secret key |  | String
+| *camel.vault.aws.accessKey* | The AWS access key |  | String
+| *camel.vault.aws.region* | The AWS region |  | String
+| *camel.vault.aws.secretKey* | The AWS secret key |  | String
 |===
 
 === Fault Tolerance EIP Circuit Breaker configurations
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/AwsVaultConfigurationProperties.java
similarity index 72%
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/AwsVaultConfigurationProperties.java
index 7901a29..5bd4b1d 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/AwsVaultConfigurationProperties.java
@@ -18,17 +18,17 @@ package org.apache.camel.main;
 
 import org.apache.camel.spi.BootstrapCloseable;
 import org.apache.camel.spi.Configurer;
-import org.apache.camel.spi.VaultConfiguration;
+import org.apache.camel.vault.AwsVaultConfiguration;
 
 /**
- * Global configuration for accessing secrets in vaults.
+ * Configuration for access to AWS Secret.
  */
 @Configurer(bootstrap = true)
-public class VaultConfigurationProperties extends VaultConfiguration implements BootstrapCloseable {
+public class AwsVaultConfigurationProperties extends AwsVaultConfiguration implements BootstrapCloseable {
 
     private MainConfigurationProperties parent;
 
-    public VaultConfigurationProperties(MainConfigurationProperties parent) {
+    public AwsVaultConfigurationProperties(MainConfigurationProperties parent) {
         this.parent = parent;
     }
 
@@ -52,24 +52,24 @@ public class VaultConfigurationProperties extends VaultConfiguration implements
     /**
      * The AWS access key
      */
-    public VaultConfigurationProperties withAwsAccessKey(String awsAccessKey) {
-        setAwsAccessKey(awsAccessKey);
+    public AwsVaultConfigurationProperties withAccessKey(String accessKey) {
+        setAccessKey(accessKey);
         return this;
     }
 
     /**
      * The AWS secret key
      */
-    public VaultConfigurationProperties withAwsSecretKey(String awsSecretKey) {
-        setAwsSecretKey(awsSecretKey);
+    public AwsVaultConfigurationProperties withSecretKey(String secretKey) {
+        setSecretKey(secretKey);
         return this;
     }
 
     /**
      * The AWS region
      */
-    public VaultConfigurationProperties withAwsRegion(String awsRegion) {
-        setAwsRegion(awsRegion);
+    public AwsVaultConfigurationProperties withRegion(String region) {
+        setRegion(region);
         return this;
     }
 
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 8639020..af84a12 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
@@ -67,6 +67,7 @@ import org.apache.camel.util.OrderedProperties;
 import org.apache.camel.util.PropertiesHelper;
 import org.apache.camel.util.SensitiveUtils;
 import org.apache.camel.util.StringHelper;
+import org.apache.camel.vault.VaultConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -876,11 +877,9 @@ public abstract class BaseMainSupport extends BaseService {
         }
 
         if (!vaultProperties.isEmpty() || mainConfigurationProperties.hasVaultConfiguration()) {
-            VaultConfigurationProperties vault = mainConfigurationProperties.vault();
             LOG.debug("Auto-configuring Vault from loaded properties: {}", vaultProperties.size());
-            setPropertiesOnTarget(camelContext, vault, vaultProperties, "camel.vault.",
-                    mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
-            camelContext.setVaultConfiguration(vault);
+            setVaultProperties(camelContext, vaultProperties, mainConfigurationProperties.isAutoConfigurationFailFast(),
+                    autoConfiguredProperties);
         }
 
         if (!threadPoolProperties.isEmpty() || mainConfigurationProperties.hasThreadPoolConfiguration()) {
@@ -1104,6 +1103,32 @@ public abstract class BaseMainSupport extends BaseService {
         }
     }
 
+    private void setVaultProperties(
+            CamelContext camelContext, Map<String, Object> properties,
+            boolean failIfNotSet, Map<String, String> autoConfiguredProperties)
+            throws Exception {
+
+        if (mainConfigurationProperties.hasVaultConfiguration()) {
+            camelContext.setVaultConfiguration(mainConfigurationProperties.vault());
+        }
+        VaultConfiguration target = camelContext.getVaultConfiguration();
+
+        // make defensive copy as we mutate the map
+        Set<String> keys = new LinkedHashSet<>(properties.keySet());
+        // set properties per different vault component
+        for (String key : keys) {
+            String name = StringHelper.before(key, ".");
+            if ("aws".equalsIgnoreCase(name)) {
+                // TODO: add more vault providers here
+                target = target.aws();
+            }
+            // 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,
+                    autoConfiguredProperties);
+        }
+    }
+
     private void bindBeansToRegistry(
             CamelContext camelContext, Map<String, Object> properties,
             String optionPrefix, boolean failIfNotSet, boolean logSummary, boolean ignoreCase,
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
index b4aefb2..59b1cd4 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
@@ -226,7 +226,7 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties<
     }
 
     /**
-     * To configure access to vaults
+     * To configure access to AWS vaults
      */
     public VaultConfigurationProperties vault() {
         if (vaultConfigurationProperties == null) {
@@ -236,7 +236,7 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties<
     }
 
     /**
-     * Whether there has been any rest configuration specified
+     * Whether there has been any vault configuration specified
      */
     public boolean hasVaultConfiguration() {
         return vaultConfigurationProperties != null;
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 7901a29..2bb2693 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
@@ -1,32 +1,12 @@
-/*
- * 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.main;
 
 import org.apache.camel.spi.BootstrapCloseable;
-import org.apache.camel.spi.Configurer;
-import org.apache.camel.spi.VaultConfiguration;
+import org.apache.camel.vault.VaultConfiguration;
 
-/**
- * Global configuration for accessing secrets in vaults.
- */
-@Configurer(bootstrap = true)
 public class VaultConfigurationProperties extends VaultConfiguration implements BootstrapCloseable {
 
     private MainConfigurationProperties parent;
+    private AwsVaultConfigurationProperties aws;
 
     public VaultConfigurationProperties(MainConfigurationProperties parent) {
         this.parent = parent;
@@ -39,6 +19,9 @@ public class VaultConfigurationProperties extends VaultConfiguration implements
     @Override
     public void close() {
         parent = null;
+        if (aws != null) {
+            aws.close();
+        }
     }
 
     // getter and setters
@@ -49,28 +32,12 @@ public class VaultConfigurationProperties extends VaultConfiguration implements
     // fluent builders
     // --------------------------------------------------------------
 
-    /**
-     * The AWS access key
-     */
-    public VaultConfigurationProperties withAwsAccessKey(String awsAccessKey) {
-        setAwsAccessKey(awsAccessKey);
-        return this;
-    }
-
-    /**
-     * The AWS secret key
-     */
-    public VaultConfigurationProperties withAwsSecretKey(String awsSecretKey) {
-        setAwsSecretKey(awsSecretKey);
-        return this;
-    }
-
-    /**
-     * The AWS region
-     */
-    public VaultConfigurationProperties withAwsRegion(String awsRegion) {
-        setAwsRegion(awsRegion);
-        return this;
+    @Override
+    public AwsVaultConfigurationProperties aws() {
+        if (aws == null) {
+            aws = new AwsVaultConfigurationProperties(parent);
+        }
+        return aws;
     }
 
 }
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 ac7b43e..3b2b44d 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
@@ -17,7 +17,7 @@
 package org.apache.camel.main;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.spi.VaultConfiguration;
+import org.apache.camel.vault.AwsVaultConfiguration;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
@@ -29,21 +29,21 @@ public class MainVaultTest {
     public void testMain() throws Exception {
         Main main = new Main();
 
-        main.addInitialProperty("camel.vault.awsAccessKey", "myKey");
-        main.addInitialProperty("camel.vault.awsSecretKey", "mySecret");
-        main.addInitialProperty("camel.vault.awsRegion", "myRegion");
+        main.addInitialProperty("camel.vault.aws.accessKey", "myKey");
+        main.addInitialProperty("camel.vault.aws.secretKey", "mySecret");
+        main.addInitialProperty("camel.vault.aws.region", "myRegion");
 
         main.start();
 
         CamelContext context = main.getCamelContext();
         assertNotNull(context);
 
-        VaultConfiguration cfg = context.getVaultConfiguration();
+        AwsVaultConfiguration cfg = context.getVaultConfiguration().aws();
         assertNotNull(cfg);
 
-        Assertions.assertEquals("myKey", cfg.getAwsAccessKey());
-        Assertions.assertEquals("mySecret", cfg.getAwsSecretKey());
-        Assertions.assertEquals("myRegion", cfg.getAwsRegion());
+        Assertions.assertEquals("myKey", cfg.getAccessKey());
+        Assertions.assertEquals("mySecret", cfg.getSecretKey());
+        Assertions.assertEquals("myRegion", cfg.getRegion());
 
         main.stop();
     }
@@ -51,10 +51,10 @@ public class MainVaultTest {
     @Test
     public void testMainFluent() throws Exception {
         Main main = new Main();
-        main.configure().vault()
-                .withAwsAccessKey("myKey")
-                .withAwsSecretKey("mySecret")
-                .withAwsRegion("myRegion")
+        main.configure().vault().aws()
+                .withAccessKey("myKey")
+                .withSecretKey("mySecret")
+                .withRegion("myRegion")
                 .end();
 
         main.start();
@@ -62,12 +62,12 @@ public class MainVaultTest {
         CamelContext context = main.getCamelContext();
         assertNotNull(context);
 
-        VaultConfiguration cfg = context.getVaultConfiguration();
+        AwsVaultConfiguration cfg = context.getVaultConfiguration().aws();
         assertNotNull(cfg);
 
-        Assertions.assertEquals("myKey", cfg.getAwsAccessKey());
-        Assertions.assertEquals("mySecret", cfg.getAwsSecretKey());
-        Assertions.assertEquals("myRegion", cfg.getAwsRegion());
+        Assertions.assertEquals("myKey", cfg.getAccessKey());
+        Assertions.assertEquals("mySecret", cfg.getSecretKey());
+        Assertions.assertEquals("myRegion", cfg.getRegion());
 
         main.stop();
     }
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 a405f4f..843fd6e 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
@@ -195,8 +195,9 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo {
                     prefix = "camel.faulttolerance.";
                 } else if (file.getName().contains("Rest")) {
                     prefix = "camel.rest.";
-                } else if (file.getName().contains("Vault")) {
-                    prefix = "camel.vault.";
+                } else if (file.getName().contains("AwsVault")) {
+                    prefix = "camel.vault.aws.";
+                    // TODO: add more vault providers here
                 } else if (file.getName().contains("Health")) {
                     prefix = "camel.health.";
                 } else if (file.getName().contains("Lra")) {
@@ -228,10 +229,11 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo {
             throw new MojoFailureException("Error parsing file " + restConfig + " due " + e.getMessage(), e);
         }
         // include additional vault configuration from camel-api
-        File vaultConfig = new File(camelApiDir, "src/main/java/org/apache/camel/spi/VaultConfiguration.java");
+        // TODO: add more vault providers here
+        File vaultConfig = new File(camelApiDir, "src/main/java/org/apache/camel/vault/AwsVaultConfiguration.java");
         try {
             List<MainModel.MainOptionModel> model = parseConfigurationSource(vaultConfig);
-            model.forEach(m -> m.setName("camel.vault." + m.getName()));
+            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);
@@ -265,7 +267,9 @@ public class PrepareCamelMainMojo extends AbstractGeneratorMojo {
                             "camel.rest", "Camel Rest-DSL configurations", "org.apache.camel.spi.RestConfiguration"));
             model.getGroups().add(
                     new MainGroupModel(
-                            "camel.vault", "Camel Vault configurations", "org.apache.camel.spi.VaultConfiguration"));
+                            "camel.vault.aws", "Camel AWS Vault configurations",
+                            "org.apache.camel.vault.AwsVaultConfiguration"));
+            // TODO: add more vault providers here
             model.getGroups()
                     .add(new MainGroupModel(
                             "camel.faulttolerance", "Fault Tolerance EIP Circuit Breaker configurations",

[camel] 08/09: CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws 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 9b11b18a95c248c200da7084a0ade813c5bd5f1f
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Sat Feb 19 14:09:15 2022 +0100

    CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws secrets manager
---
 .../component/aws/secretsmanager/SecretsManagerPropertiesFunction.java   | 1 -
 1 file changed, 1 deletion(-)

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 a195fb5..dda616c 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
@@ -17,7 +17,6 @@
 package org.apache.camel.component.aws.secretsmanager;
 
 import java.util.Base64;
-import java.util.Optional;
 import java.util.Properties;
 
 import com.fasterxml.jackson.core.JsonProcessingException;

[camel] 09/09: CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws 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 e5463a55b59d4d728effa1d73305b0faaf42f162
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Sat Feb 19 14:11:06 2022 +0100

    CAMEL-17644 - Support ability to load properties from Vault/Secrets cloud services - aws secrets manager
---
 .../aws/secretsmanager/SecretsManagerPropertiesFunction.java   | 10 ++++++++++
 1 file changed, 10 insertions(+)

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 dda616c..2144be8 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
@@ -49,6 +49,16 @@ import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRespon
  * <li><tt>CAMEL_VAULT_AWS_REGION</tt></li>
  * </ul>
  * <p/>
+ *
+ * Otherwise it is possible to specify the credentials as properties:
+ *
+ * <ul>
+ * <li><tt>camel.vault.aws.accessKey</tt></li>
+ * <li><tt>camel.vault.aws.secretKey</tt></li>
+ * <li><tt>camel.vault.aws.region</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>aws:</tt>. For example asking for <tt>aws:token</tt>, will return the
  * secret value associated the secret named token on AWS Secrets Manager

[camel] 06/09: CAMEL-17644: camel-core - Add VaultConfiguration SPI

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 3c5ae5fe609c2a2116c18f6e6e10bba06ae51d03
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Feb 19 13:08:55 2022 +0100

    CAMEL-17644: camel-core - Add VaultConfiguration SPI
---
 docs/user-manual/modules/ROOT/pages/security.adoc | 69 ++++++++++++++++++++++-
 1 file changed, 68 insertions(+), 1 deletion(-)

diff --git a/docs/user-manual/modules/ROOT/pages/security.adoc b/docs/user-manual/modules/ROOT/pages/security.adoc
index 3a49be9..c136648 100644
--- a/docs/user-manual/modules/ROOT/pages/security.adoc
+++ b/docs/user-manual/modules/ROOT/pages/security.adoc
@@ -13,7 +13,7 @@ services at the payload level
 * _Endpoint Security_ - Security offered by components that can be
 utilized by endpointUri associated with the component
 * _Configuration Security_ - Security offered by encrypting sensitive
-information from configuration files
+information from configuration files or external Secured Vault systems.
 
 Camel offers the xref:camel-configuration-utilities.adoc[JSSE Utility]
 for configuring SSL/TLS related aspects of a number of Camel components.
@@ -57,3 +57,70 @@ Those values can be encrypted and automatic decrypted by Camel using:
 
 * xref:components:others:jasypt.adoc[Jasypt]
 
+Camel also support accessing the secured configuration from an external vault systems.
+
+=== Configuration Security using Vaults
+
+The following _Vaults_ are supported by Camel:
+
+* xref:components::aws-secrets-manager-component.adoc[AWS Secrets Manager]
+
+==== Using AWS Vault
+
+To use AWS Secrets Manager you need to provide _accessKey_, _secretKey_ and the _region_.
+This can be done using environmental variables before starting the application:
+
+[source,bash]
+----
+export $CAMEL_VAULT_AWS_ACCESS_KEY=accessKey
+export $CAMEL_VAULT_AWS_SECRET_KEY=secretKey
+export $CAMEL_VAULT_AWS_REGION=region
+----
+
+At this point you'll be able to reference a property in the following way:
+
+[source,xml]
+----
+<camelContext>
+    <route>
+        <from uri="direct:start"/>
+        <to uri="{{aws:route}}"/>
+    </route>
+</camelContext>
+----
+
+Where route will be the name of the secret stored in the AWS Secrets Manager Service.
+
+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]
+----
+{
+  "username": "admin",
+  "password": "password123",
+  "engine": "postgres",
+  "host": "127.0.0.1",
+  "port": "3128",
+  "dbname": "db"
+}
+----
+
+You're able to do get single secret value in your route, like for example:
+
+[source,xml]
+----
+<camelContext>
+    <route>
+        <from uri="direct:start"/>
+        <log message="Username is {{aws:database:username}}"/>
+    </route>
+</camelContext>
+----
+
+Or re-use the property as part of an endpoint.
+
+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.
+
+

[camel] 04/09: CAMEL-17644: camel-core - Add VaultConfiguration SPI

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 889472143fead07eebf87f1c864457c4cd63951c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Feb 19 11:07:49 2022 +0100

    CAMEL-17644: camel-core - Add VaultConfiguration SPI
---
 .../camel/catalog/main/camel-main-configuration-metadata.json       | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

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 a3fef16..c5bd162 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
@@ -4,6 +4,7 @@
     { "name": "camel.threadpool", "description": "Camel Thread Pool configurations", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties" },
     { "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.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" },
@@ -227,6 +228,9 @@
     { "name": "camel.threadpool.maxQueueSize", "description": "Sets the default maximum number of tasks in the work queue. Use -1 or an unbounded queue", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "integer", "javaType": "java.lang.Integer" },
     { "name": "camel.threadpool.poolSize", "description": "Sets the default core pool size (threads to keep minimum in pool)", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "integer", "javaType": "java.lang.Integer" },
     { "name": "camel.threadpool.rejectedPolicy", "description": "Sets the default handler for tasks which cannot be executed by the thread pool.", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy", "enum": [ "Abort", "CallerRuns", "DiscardOldest", "Discard" ] },
-    { "name": "camel.threadpool.timeUnit", "description": "Sets the default time unit used for keep alive time", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "java.util.concurrent.TimeUnit" }
+    { "name": "camel.threadpool.timeUnit", "description": "Sets the default time unit used for keep alive time", "sourceType": "org.apache.camel.main.ThreadPoolConfigurationProperties", "type": "object", "javaType": "java.util.concurrent.TimeUnit" },
+    { "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.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" }
   ]
 }

[camel] 01/09: CAMEL-17644: camel-core - Add VaultConfiguration SPI

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 c34805b8c0c3f21c918d8d4a3e5667e51d53cd4f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Feb 19 08:33:14 2022 +0100

    CAMEL-17644: camel-core - Add VaultConfiguration SPI
---
 .../main/java/org/apache/camel/CamelContext.java   | 15 +++++
 .../org/apache/camel/spi/VaultConfiguration.java   | 64 ++++++++++++++++++
 .../camel/impl/engine/AbstractCamelContext.java    | 12 ++++
 .../camel/impl/ExtendedCamelContextConfigurer.java |  6 ++
 .../camel/impl/lw/LightweightCamelContext.java     | 11 ++++
 .../impl/lw/LightweightRuntimeCamelContext.java    | 11 ++++
 .../VaultConfigurationPropertiesConfigurer.java    | 61 +++++++++++++++++
 ....apache.camel.main.VaultConfigurationProperties |  2 +
 .../org/apache/camel/main/BaseMainSupport.java     | 20 ++++++
 .../camel/main/MainConfigurationProperties.java    | 22 +++++++
 .../camel/main/VaultConfigurationProperties.java   | 76 ++++++++++++++++++++++
 11 files changed, 300 insertions(+)

diff --git a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
index bedcd7d..669b56c 100644
--- a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
+++ b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
@@ -52,6 +52,7 @@ import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spi.Validator;
 import org.apache.camel.spi.ValidatorRegistry;
+import org.apache.camel.spi.VaultConfiguration;
 import org.apache.camel.support.jsse.SSLContextParameters;
 
 /**
@@ -673,6 +674,20 @@ public interface CamelContext extends CamelContextLifecycle, RuntimeConfiguratio
     RestConfiguration getRestConfiguration();
 
     /**
+     * Sets a custom {@link org.apache.camel.spi.VaultConfiguration}
+     *
+     * @param vaultConfiguration the vault configuration
+     */
+    void setVaultConfiguration(VaultConfiguration vaultConfiguration);
+
+    /**
+     * Gets the vault configuration
+     *
+     * @return the configuration, or <tt>null</tt> if none has been configured.
+     */
+    VaultConfiguration getVaultConfiguration();
+
+    /**
      * Gets the {@link org.apache.camel.spi.RestRegistry} to use
      */
     RestRegistry getRestRegistry();
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java b/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java
new file mode 100644
index 0000000..b50ee0c
--- /dev/null
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/VaultConfiguration.java
@@ -0,0 +1,64 @@
+/*
+ * 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.spi;
+
+/**
+ * Configuration for access to Vaults.
+ */
+public class VaultConfiguration {
+
+    @Metadata(secret = true)
+    private String awsAccessKey;
+    @Metadata(secret = true)
+    private String awsSecretKey;
+    @Metadata
+    private String awsRegion;
+
+    public String getAwsAccessKey() {
+        return awsAccessKey;
+    }
+
+    /**
+     * The AWS access key
+     */
+    public void setAwsAccessKey(String awsAccessKey) {
+        this.awsAccessKey = awsAccessKey;
+    }
+
+    public String getAwsSecretKey() {
+        return awsSecretKey;
+    }
+
+    /**
+     * The AWS secret key
+     */
+    public void setAwsSecretKey(String awsSecretKey) {
+        this.awsSecretKey = awsSecretKey;
+    }
+
+    public String getAwsRegion() {
+        return awsRegion;
+    }
+
+    /**
+     * The AWS region
+     */
+    public void setAwsRegion(String awsRegion) {
+        this.awsRegion = awsRegion;
+    }
+
+}
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 6524e76..9ebd16c 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -169,6 +169,7 @@ import org.apache.camel.spi.UriFactoryResolver;
 import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spi.Validator;
 import org.apache.camel.spi.ValidatorRegistry;
+import org.apache.camel.spi.VaultConfiguration;
 import org.apache.camel.spi.XMLRoutesDefinitionLoader;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.EndpointHelper;
@@ -245,6 +246,7 @@ public abstract class AbstractCamelContext extends BaseService
     private ClassLoader applicationContextClassLoader;
     private boolean autoCreateComponents = true;
     private volatile RestConfiguration restConfiguration;
+    private volatile VaultConfiguration vaultConfiguration = new VaultConfiguration();
     private List<InterceptStrategy> interceptStrategies = new ArrayList<>();
     private List<RoutePolicyFactory> routePolicyFactories = new ArrayList<>();
     // special flags to control the first startup which can are special
@@ -2158,6 +2160,16 @@ public abstract class AbstractCamelContext extends BaseService
     }
 
     @Override
+    public VaultConfiguration getVaultConfiguration() {
+        return vaultConfiguration;
+    }
+
+    @Override
+    public void setVaultConfiguration(VaultConfiguration vaultConfiguration) {
+        this.vaultConfiguration = vaultConfiguration;
+    }
+
+    @Override
     public List<InterceptStrategy> getInterceptStrategies() {
         return interceptStrategies;
     }
diff --git a/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java b/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java
index 5189be9..8eeef0d 100644
--- a/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java
+++ b/core/camel-core-engine/src/generated/java/org/apache/camel/impl/ExtendedCamelContextConfigurer.java
@@ -211,6 +211,8 @@ public class ExtendedCamelContextConfigurer extends org.apache.camel.support.com
         case "UseMDCLogging": target.setUseMDCLogging(property(camelContext, java.lang.Boolean.class, value)); return true;
         case "uuidgenerator":
         case "UuidGenerator": target.setUuidGenerator(property(camelContext, org.apache.camel.spi.UuidGenerator.class, value)); return true;
+        case "vaultconfiguration":
+        case "VaultConfiguration": target.setVaultConfiguration(property(camelContext, org.apache.camel.spi.VaultConfiguration.class, value)); return true;
         case "xmlroutesdefinitionloader":
         case "XMLRoutesDefinitionLoader": target.setXMLRoutesDefinitionLoader(property(camelContext, org.apache.camel.spi.XMLRoutesDefinitionLoader.class, value)); return true;
         default: return false;
@@ -410,6 +412,8 @@ public class ExtendedCamelContextConfigurer extends org.apache.camel.support.com
         case "UseMDCLogging": return java.lang.Boolean.class;
         case "uuidgenerator":
         case "UuidGenerator": return org.apache.camel.spi.UuidGenerator.class;
+        case "vaultconfiguration":
+        case "VaultConfiguration": return org.apache.camel.spi.VaultConfiguration.class;
         case "xmlroutesdefinitionloader":
         case "XMLRoutesDefinitionLoader": return org.apache.camel.spi.XMLRoutesDefinitionLoader.class;
         default: return null;
@@ -610,6 +614,8 @@ public class ExtendedCamelContextConfigurer extends org.apache.camel.support.com
         case "UseMDCLogging": return target.isUseMDCLogging();
         case "uuidgenerator":
         case "UuidGenerator": return target.getUuidGenerator();
+        case "vaultconfiguration":
+        case "VaultConfiguration": return target.getVaultConfiguration();
         case "xmlroutesdefinitionloader":
         case "XMLRoutesDefinitionLoader": return target.getXMLRoutesDefinitionLoader();
         default: return null;
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
index bcccc6a..b5c5dff 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
@@ -149,6 +149,7 @@ import org.apache.camel.spi.UriFactoryResolver;
 import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spi.Validator;
 import org.apache.camel.spi.ValidatorRegistry;
+import org.apache.camel.spi.VaultConfiguration;
 import org.apache.camel.spi.XMLRoutesDefinitionLoader;
 import org.apache.camel.support.DefaultRegistry;
 import org.apache.camel.support.jsse.SSLContextParameters;
@@ -589,6 +590,16 @@ public class LightweightCamelContext implements ExtendedCamelContext, CatalogCam
     }
 
     @Override
+    public void setVaultConfiguration(VaultConfiguration vaultConfiguration) {
+        delegate.setVaultConfiguration(vaultConfiguration);
+    }
+
+    @Override
+    public VaultConfiguration getVaultConfiguration() {
+        return delegate.getVaultConfiguration();
+    }
+
+    @Override
     public RestRegistry getRestRegistry() {
         return delegate.getRestRegistry();
     }
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
index 0e3c9ad..e344bc5 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
@@ -144,6 +144,7 @@ import org.apache.camel.spi.UriFactoryResolver;
 import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spi.Validator;
 import org.apache.camel.spi.ValidatorRegistry;
+import org.apache.camel.spi.VaultConfiguration;
 import org.apache.camel.spi.XMLRoutesDefinitionLoader;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.NormalizedUri;
@@ -898,6 +899,16 @@ public class LightweightRuntimeCamelContext implements ExtendedCamelContext, Cat
     }
 
     @Override
+    public void setVaultConfiguration(VaultConfiguration vaultConfiguration) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public VaultConfiguration getVaultConfiguration() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
     public RestRegistry getRestRegistry() {
         throw new UnsupportedOperationException();
     }
diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/VaultConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/VaultConfigurationPropertiesConfigurer.java
new file mode 100644
index 0000000..ba2c389
--- /dev/null
+++ b/core/camel-main/src/generated/java/org/apache/camel/main/VaultConfigurationPropertiesConfigurer.java
@@ -0,0 +1,61 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.main;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.ExtendedPropertyConfigurerGetter;
+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.VaultConfigurationProperties;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+public class VaultConfigurationPropertiesConfigurer 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.VaultConfigurationProperties target = (org.apache.camel.main.VaultConfigurationProperties) obj;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "awsaccesskey":
+        case "AwsAccessKey": target.setAwsAccessKey(property(camelContext, java.lang.String.class, value)); return true;
+        case "awsregion":
+        case "AwsRegion": target.setAwsRegion(property(camelContext, java.lang.String.class, value)); return true;
+        case "awssecretkey":
+        case "AwsSecretKey": target.setAwsSecretKey(property(camelContext, java.lang.String.class, value)); return true;
+        default: return false;
+        }
+    }
+
+    @Override
+    public Class<?> getOptionType(String name, boolean ignoreCase) {
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "awsaccesskey":
+        case "AwsAccessKey": return java.lang.String.class;
+        case "awsregion":
+        case "AwsRegion": return java.lang.String.class;
+        case "awssecretkey":
+        case "AwsSecretKey": return java.lang.String.class;
+        default: return null;
+        }
+    }
+
+    @Override
+    public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
+        org.apache.camel.main.VaultConfigurationProperties target = (org.apache.camel.main.VaultConfigurationProperties) obj;
+        switch (ignoreCase ? name.toLowerCase() : name) {
+        case "awsaccesskey":
+        case "AwsAccessKey": return target.getAwsAccessKey();
+        case "awsregion":
+        case "AwsRegion": return target.getAwsRegion();
+        case "awssecretkey":
+        case "AwsSecretKey": return target.getAwsSecretKey();
+        default: return null;
+        }
+    }
+}
+
diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.VaultConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.VaultConfigurationProperties
new file mode 100644
index 0000000..42521d4
--- /dev/null
+++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/org.apache.camel.main.VaultConfigurationProperties
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.main.VaultConfigurationPropertiesConfigurer
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 48822f1..8639020 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
@@ -760,6 +760,7 @@ public abstract class BaseMainSupport extends BaseService {
         Map<String, Object> resilience4jProperties = new LinkedHashMap<>();
         Map<String, Object> faultToleranceProperties = new LinkedHashMap<>();
         Map<String, Object> restProperties = new LinkedHashMap<>();
+        Map<String, Object> vaultProperties = new LinkedHashMap<>();
         Map<String, Object> threadPoolProperties = new LinkedHashMap<>();
         Map<String, Object> healthProperties = new LinkedHashMap<>();
         Map<String, Object> lraProperties = new LinkedHashMap<>();
@@ -798,6 +799,12 @@ public abstract class BaseMainSupport extends BaseService {
                 String option = key.substring(11);
                 validateOptionAndValue(key, option, value);
                 restProperties.put(optionKey(option), value);
+            } else if (key.startsWith("camel.vault.")) {
+                // grab the value
+                String value = prop.getProperty(key);
+                String option = key.substring(12);
+                validateOptionAndValue(key, option, value);
+                vaultProperties.put(optionKey(option), value);
             } else if (key.startsWith("camel.threadpool.")) {
                 // grab the value
                 String value = prop.getProperty(key);
@@ -868,6 +875,14 @@ public abstract class BaseMainSupport extends BaseService {
             camelContext.setRestConfiguration(rest);
         }
 
+        if (!vaultProperties.isEmpty() || mainConfigurationProperties.hasVaultConfiguration()) {
+            VaultConfigurationProperties vault = mainConfigurationProperties.vault();
+            LOG.debug("Auto-configuring Vault from loaded properties: {}", vaultProperties.size());
+            setPropertiesOnTarget(camelContext, vault, vaultProperties, "camel.vault.",
+                    mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
+            camelContext.setVaultConfiguration(vault);
+        }
+
         if (!threadPoolProperties.isEmpty() || mainConfigurationProperties.hasThreadPoolConfiguration()) {
             LOG.debug("Auto-configuring Thread Pool from loaded properties: {}", threadPoolProperties.size());
             MainSupportModelConfigurer.setThreadPoolProperties(camelContext, mainConfigurationProperties, threadPoolProperties,
@@ -932,6 +947,11 @@ public abstract class BaseMainSupport extends BaseService {
                 LOG.warn("Property not auto-configured: camel.rest.{}={}", k, v);
             });
         }
+        if (!vaultProperties.isEmpty()) {
+            vaultProperties.forEach((k, v) -> {
+                LOG.warn("Property not auto-configured: camel.vault.{}={}", k, v);
+            });
+        }
         if (!threadPoolProperties.isEmpty()) {
             threadPoolProperties.forEach((k, v) -> {
                 LOG.warn("Property not auto-configured: camel.threadpool.{}={}", k, v);
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
index 8138bef..b4aefb2 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
@@ -56,6 +56,7 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties<
     private Resilience4jConfigurationProperties resilience4jConfigurationProperties;
     private FaultToleranceConfigurationProperties faultToleranceConfigurationProperties;
     private RestConfigurationProperties restConfigurationProperties;
+    private VaultConfigurationProperties vaultConfigurationProperties;
 
     @Override
     public void close() {
@@ -87,6 +88,10 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties<
             restConfigurationProperties.close();
             restConfigurationProperties = null;
         }
+        if (vaultConfigurationProperties != null) {
+            vaultConfigurationProperties.close();
+            vaultConfigurationProperties = null;
+        }
         if (routesBuilders != null) {
             routesBuilders.clear();
             routesBuilders = null;
@@ -220,6 +225,23 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties<
         return restConfigurationProperties != null;
     }
 
+    /**
+     * To configure access to vaults
+     */
+    public VaultConfigurationProperties vault() {
+        if (vaultConfigurationProperties == null) {
+            vaultConfigurationProperties = new VaultConfigurationProperties(this);
+        }
+        return vaultConfigurationProperties;
+    }
+
+    /**
+     * Whether there has been any rest configuration specified
+     */
+    public boolean hasVaultConfiguration() {
+        return vaultConfigurationProperties != null;
+    }
+
     // getter and setters
     // --------------------------------------------------------------
 
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
new file mode 100644
index 0000000..7901a29
--- /dev/null
+++ b/core/camel-main/src/main/java/org/apache/camel/main/VaultConfigurationProperties.java
@@ -0,0 +1,76 @@
+/*
+ * 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.main;
+
+import org.apache.camel.spi.BootstrapCloseable;
+import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.VaultConfiguration;
+
+/**
+ * Global configuration for accessing secrets in vaults.
+ */
+@Configurer(bootstrap = true)
+public class VaultConfigurationProperties extends VaultConfiguration implements BootstrapCloseable {
+
+    private MainConfigurationProperties parent;
+
+    public VaultConfigurationProperties(MainConfigurationProperties parent) {
+        this.parent = parent;
+    }
+
+    public MainConfigurationProperties end() {
+        return parent;
+    }
+
+    @Override
+    public void close() {
+        parent = null;
+    }
+
+    // getter and setters
+    // --------------------------------------------------------------
+
+    // these are inherited from the parent class
+
+    // fluent builders
+    // --------------------------------------------------------------
+
+    /**
+     * The AWS access key
+     */
+    public VaultConfigurationProperties withAwsAccessKey(String awsAccessKey) {
+        setAwsAccessKey(awsAccessKey);
+        return this;
+    }
+
+    /**
+     * The AWS secret key
+     */
+    public VaultConfigurationProperties withAwsSecretKey(String awsSecretKey) {
+        setAwsSecretKey(awsSecretKey);
+        return this;
+    }
+
+    /**
+     * The AWS region
+     */
+    public VaultConfigurationProperties withAwsRegion(String awsRegion) {
+        setAwsRegion(awsRegion);
+        return this;
+    }
+
+}

[camel] 05/09: CAMEL-17644: camel-core - Add VaultConfiguration SPI

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 1c54076b5e5e2b11baaa03871a565e716859e73e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Feb 19 12:40:40 2022 +0100

    CAMEL-17644: camel-core - Add VaultConfiguration SPI
---
 .../apache/camel/main/VaultConfigurationProperties.java  | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

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 2bb2693..0002430 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
@@ -1,3 +1,19 @@
+/*
+ * 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.main;
 
 import org.apache.camel.spi.BootstrapCloseable;