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

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

commit db103040bd90bb3a8c249931ebb0c3f779f1577d
Author: Claus Ibsen <claus.ib...@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;
+    }
+
+}

Reply via email to