This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 529d1ccca1f hashicorp vault (#16595) 529d1ccca1f is described below commit 529d1ccca1f0b0e7bf6e7092bbe53d41c342c6a3 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Dec 18 10:09:28 2024 +0100 hashicorp vault (#16595) * CAMEL-21553: Add hikari JDBC as a known JAR to camel-jbang * CAMEL-21553: camel-jbang - Should init vault eager before routes with modeline that has custom beans. --- .../vault/HashicorpVaultPropertiesFunction.java | 3 +- .../org/apache/camel/main/BaseMainSupport.java | 93 +++++++++++++++++----- .../camel/main/DefaultConfigurationConfigurer.java | 6 +- .../camel-main-known-dependencies.properties | 3 +- 4 files changed, 78 insertions(+), 27 deletions(-) diff --git a/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultPropertiesFunction.java b/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultPropertiesFunction.java index d5d41101ea9..d4efea00e33 100644 --- a/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultPropertiesFunction.java +++ b/components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultPropertiesFunction.java @@ -184,7 +184,8 @@ public class HashicorpVaultPropertiesFunction extends ServiceSupport implements try { returnValue = getSecretFromSource(key, subkey, defaultValue, version); } catch (Exception e) { - throw new RuntimeCamelException("Something went wrong while recovering " + key + " from vault"); + throw new RuntimeCamelException( + "Error getting secret from vault using key: " + key + " due to: " + e.getMessage(), e); } } 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 e10ca74ef01..f28e63a4238 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 @@ -520,9 +520,15 @@ public abstract class BaseMainSupport extends BaseService { // configure the profile with pre-configured settings StartupStep step = recorder.beginStep(BaseMainSupport.class, "configureMain", "Profile Configure"); + doInitFileConfigurations(camelContext, mainConfigurationProperties); ProfileConfigurer.configureMain(camelContext, mainConfigurationProperties.getProfile(), mainConfigurationProperties); recorder.endStep(step); + // need to pre-load vault configuration as they are used eager during property placeholder resolutions + step = recorder.beginStep(BaseMainSupport.class, "configureVault", "Configure Vault"); + doConfigureVaultFromMainConfiguration(camelContext, mainConfigurationProperties, autoConfiguredProperties); + recorder.endStep(step); + // need to eager allow to auto-configure properties component if (mainConfigurationProperties.isAutoConfigurationEnabled()) { step = recorder.beginStep(BaseMainSupport.class, "autoConfigurationFailFast", "Auto Configure"); @@ -1083,14 +1089,65 @@ public abstract class BaseMainSupport extends BaseService { } } - /** - * Configures CamelContext from the {@link MainConfigurationProperties} properties. - */ - protected void doConfigureCamelContextFromMainConfiguration( + protected void doConfigureVaultFromMainConfiguration( CamelContext camelContext, MainConfigurationProperties config, OrderedLocationProperties autoConfiguredProperties) throws Exception { + OrderedLocationProperties vaultProperties = new OrderedLocationProperties(); + + // now configure the various camel groups + OrderedLocationProperties prop = (OrderedLocationProperties) camelContext.getPropertiesComponent() + .loadProperties(name -> name.startsWith("camel."), MainHelper::optionKey); + + // load properties from ENV (override existing) + if (mainConfigurationProperties.isAutoConfigurationEnvironmentVariablesEnabled()) { + Properties propENV + = MainHelper.loadEnvironmentVariablesAsProperties(GROUP_PREFIXES); + if (!propENV.isEmpty()) { + prop.putAll("ENV", propENV); + LOG.debug("Properties from OS environment variables:"); + for (String key : propENV.stringPropertyNames()) { + LOG.debug(" {}={}", key, propENV.getProperty(key)); + } + } + } + // load properties from JVM (override existing) + if (mainConfigurationProperties.isAutoConfigurationSystemPropertiesEnabled()) { + Properties propJVM = MainHelper.loadJvmSystemPropertiesAsProperties(GROUP_PREFIXES); + if (!propJVM.isEmpty()) { + prop.putAll("SYS", propJVM); + LOG.debug("Properties from JVM system properties:"); + for (String key : propJVM.stringPropertyNames()) { + LOG.debug(" {}={}", key, propJVM.getProperty(key)); + } + } + } + + for (String key : prop.stringPropertyNames()) { + String loc = prop.getLocation(key); + if (startsWithIgnoreCase(key, "camel.vault.")) { + // grab the value + String value = prop.getProperty(key); + String option = key.substring(12); + validateOptionAndValue(key, option, value); + vaultProperties.put(loc, optionKey(option), value); + } + } + + if (!vaultProperties.isEmpty() || mainConfigurationProperties.hasVaultConfiguration()) { + LOG.debug("Auto-configuring Vault from loaded properties: {}", vaultProperties.size()); + setVaultProperties(camelContext, vaultProperties, mainConfigurationProperties.isAutoConfigurationFailFast(), + autoConfiguredProperties); + } + if (!vaultProperties.isEmpty()) { + vaultProperties.forEach((k, v) -> { + LOG.warn("Property not auto-configured: camel.vault.{}={}", k, v); + }); + } + } + + protected void doInitFileConfigurations(CamelContext camelContext, MainConfigurationProperties config) throws Exception { if (ObjectHelper.isNotEmpty(config.getFileConfigurations())) { String[] locs = config.getFileConfigurations().split(","); for (String loc : locs) { @@ -1119,6 +1176,15 @@ public abstract class BaseMainSupport extends BaseService { } } } + } + + /** + * Configures CamelContext from the {@link MainConfigurationProperties} properties. + */ + protected void doConfigureCamelContextFromMainConfiguration( + CamelContext camelContext, MainConfigurationProperties config, + OrderedLocationProperties autoConfiguredProperties) + throws Exception { // configure the common/default options DefaultConfigurationConfigurer.configure(camelContext, config); @@ -1167,7 +1233,6 @@ public abstract class BaseMainSupport extends BaseService { OrderedLocationProperties resilience4jProperties = new OrderedLocationProperties(); OrderedLocationProperties faultToleranceProperties = new OrderedLocationProperties(); OrderedLocationProperties restProperties = new OrderedLocationProperties(); - OrderedLocationProperties vaultProperties = new OrderedLocationProperties(); OrderedLocationProperties threadPoolProperties = new OrderedLocationProperties(); OrderedLocationProperties healthProperties = new OrderedLocationProperties(); OrderedLocationProperties lraProperties = new OrderedLocationProperties(); @@ -1210,12 +1275,6 @@ public abstract class BaseMainSupport extends BaseService { String option = key.substring(11); validateOptionAndValue(key, option, value); restProperties.put(loc, optionKey(option), value); - } else if (startsWithIgnoreCase(key, "camel.vault.")) { - // grab the value - String value = prop.getProperty(key); - String option = key.substring(12); - validateOptionAndValue(key, option, value); - vaultProperties.put(loc, optionKey(option), value); } else if (startsWithIgnoreCase(key, "camel.threadpool.")) { // grab the value String value = prop.getProperty(key); @@ -1349,11 +1408,6 @@ public abstract class BaseMainSupport extends BaseService { mainConfigurationProperties.isAutoConfigurationFailFast(), autoConfiguredProperties); } - if (!vaultProperties.isEmpty() || mainConfigurationProperties.hasVaultConfiguration()) { - LOG.debug("Auto-configuring Vault from loaded properties: {}", vaultProperties.size()); - setVaultProperties(camelContext, vaultProperties, mainConfigurationProperties.isAutoConfigurationFailFast(), - autoConfiguredProperties); - } if (!threadPoolProperties.isEmpty() || mainConfigurationProperties.hasThreadPoolConfiguration()) { LOG.debug("Auto-configuring Thread Pool from loaded properties: {}", threadPoolProperties.size()); MainSupportModelConfigurer.setThreadPoolProperties(camelContext, mainConfigurationProperties, threadPoolProperties, @@ -1452,11 +1506,6 @@ 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); @@ -1511,7 +1560,7 @@ public abstract class BaseMainSupport extends BaseService { // and call after all properties are set DefaultConfigurationConfigurer.afterPropertiesSet(camelContext); // and configure vault - DefaultConfigurationConfigurer.configureVault(camelContext); + DefaultConfigurationConfigurer.configureVaultRefresh(camelContext); } /** diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java index 307dce149a1..785dd9bba62 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java @@ -629,7 +629,7 @@ public final class DefaultConfigurationConfigurer { VaultConfiguration vault = camelContext.getVaultConfiguration(); vault.setKubernetesConfigMapVaultConfiguration(kubernetesConfigmaps); } - configureVault(camelContext); + configureVaultRefresh(camelContext); // apply custom configurations if any Set<CamelContextCustomizer> customizers = registry.findByType(CamelContextCustomizer.class); @@ -641,9 +641,9 @@ public final class DefaultConfigurationConfigurer { } /** - * Configures security vaults such as AWS, Azure, Google and Hashicorp. + * Configures security vaults refresh such as AWS, Azure, Google. */ - static void configureVault(CamelContext camelContext) throws Exception { + static void configureVaultRefresh(CamelContext camelContext) throws Exception { VaultConfiguration vc = camelContext.getVaultConfiguration(); if (vc == null) { return; diff --git a/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties b/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties index 09056c53362..a9d69e27dea 100644 --- a/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties +++ b/dsl/camel-kamelet-main/src/main/resources/camel-main-known-dependencies.properties @@ -46,4 +46,5 @@ quarkus.datasource.db-kind\=mysql = io.quarkus:quarkus-jdbc-mysql:${quarkus-vers quarkus.datasource.db-kind\=oracle = io.quarkus:quarkus-jdbc-oracle:${quarkus-version} quarkus.datasource.db-kind\=postgresql = io.quarkus:quarkus-jdbc-postgresql:${quarkus-version} org.springframework.jdbc.datasource.SimpleDriverDataSource = camel:sql -oracle.jdbc.driver.OracleDriver = com.oracle.database.jdbc:ojdbc11:23.6.0.24.10 \ No newline at end of file +oracle.jdbc.driver.OracleDriver = com.oracle.database.jdbc:ojdbc11:23.6.0.24.10 +com.zaxxer.hikari.HikariDataSource = com.zaxxer:HikariCP:6.2.1 \ No newline at end of file