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
commit 4c412ddbf27a707cf04192143768617b02ee2816 Author: Claus Ibsen <[email protected]> AuthorDate: Fri Jul 14 11:11:44 2023 +0200 CAMEL-19603: camel-core - configureVault should be done general so its also done for Spring Boot and Quarkus and not only camel-main/camel-jbang. --- .../org/apache/camel/main/BaseMainSupport.java | 24 -------- .../camel/main/DefaultConfigurationConfigurer.java | 72 ++++++++++++++++++++++ 2 files changed, 72 insertions(+), 24 deletions(-) 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 300d10a29a4..79b4804d40f 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 @@ -384,28 +384,6 @@ public abstract class BaseMainSupport extends BaseService { protected void configureLifecycle(CamelContext camelContext) throws Exception { } - /** - * Configures security vaults such as AWS, Azure, Google and Hashicorp. - */ - protected void configureVault(CamelContext camelContext) throws Exception { - VaultConfiguration vc = camelContext.getVaultConfiguration(); - if (vc == null) { - return; - } - - if (vc.aws().isRefreshEnabled()) { - scheduleRefresh(camelContext, "aws-secret-refresh", vc.aws().getRefreshPeriod()); - } - - if (vc.gcp().isRefreshEnabled()) { - scheduleRefresh(camelContext, "gcp-secret-refresh", vc.gcp().getRefreshPeriod()); - } - - if (vc.azure().isRefreshEnabled()) { - scheduleRefresh(camelContext, "azure-secret-refresh", vc.azure().getRefreshPeriod()); - } - } - private void scheduleRefresh(CamelContext camelContext, String key, long period) throws Exception { final Optional<Runnable> task = PluginHelper.getPeriodTaskResolver(camelContext) .newInstance(key, Runnable.class); @@ -643,8 +621,6 @@ public abstract class BaseMainSupport extends BaseService { configureLifecycle(camelContext); - configureVault(camelContext); - if (standalone) { step = recorder.beginStep(BaseMainSupport.class, "configureRoutes", "Collect Routes"); configureRoutes(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 753971d76c8..d8fc0d5f117 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 @@ -19,6 +19,7 @@ package org.apache.camel.main; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.function.Consumer; import java.util.function.Predicate; @@ -62,6 +63,7 @@ import org.apache.camel.spi.ManagementStrategy; import org.apache.camel.spi.MessageHistoryFactory; import org.apache.camel.spi.ModelJAXBContextFactory; import org.apache.camel.spi.NodeIdFactory; +import org.apache.camel.spi.PeriodTaskScheduler; import org.apache.camel.spi.ProcessorFactory; import org.apache.camel.spi.PropertiesComponent; import org.apache.camel.spi.ReactiveExecutor; @@ -88,6 +90,7 @@ import org.apache.camel.support.SimpleUuidGenerator; import org.apache.camel.support.jsse.GlobalSSLContextParametersSupplier; import org.apache.camel.support.startup.LoggingStartupStepRecorder; import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.TimeUtils; import org.apache.camel.vault.AwsVaultConfiguration; import org.apache.camel.vault.AzureVaultConfiguration; import org.apache.camel.vault.GcpVaultConfiguration; @@ -598,10 +601,79 @@ public final class DefaultConfigurationConfigurer { VaultConfiguration vault = camelContext.getVaultConfiguration(); vault.setHashicorpVaultConfiguration(hashicorp); } + configureVault(camelContext); + // set the default thread pool profile if defined initThreadPoolProfiles(registry, camelContext); } + /** + * Configures security vaults such as AWS, Azure, Google and Hashicorp. + */ + protected static void configureVault(CamelContext camelContext) throws Exception { + VaultConfiguration vc = camelContext.getVaultConfiguration(); + if (vc == null) { + return; + } + + if (vc.aws().isRefreshEnabled()) { + Optional<Runnable> task = PluginHelper.getPeriodTaskResolver(camelContext) + .newInstance("aws-secret-refresh", Runnable.class); + if (task.isPresent()) { + long period = vc.aws().getRefreshPeriod(); + Runnable r = task.get(); + if (LOG.isDebugEnabled()) { + LOG.debug("Scheduling: {} (period: {})", r, TimeUtils.printDuration(period, false)); + } + if (camelContext.hasService(ContextReloadStrategy.class) == null) { + // refresh is enabled then we need to automatically enable context-reload as well + ContextReloadStrategy reloader = new DefaultContextReloadStrategy(); + camelContext.addService(reloader); + } + PeriodTaskScheduler scheduler = PluginHelper.getPeriodTaskScheduler(camelContext); + scheduler.schedulePeriodTask(r, period); + } + } + + if (vc.gcp().isRefreshEnabled()) { + Optional<Runnable> task = PluginHelper.getPeriodTaskResolver(camelContext) + .newInstance("gcp-secret-refresh", Runnable.class); + if (task.isPresent()) { + long period = vc.gcp().getRefreshPeriod(); + Runnable r = task.get(); + if (LOG.isDebugEnabled()) { + LOG.debug("Scheduling: {} (period: {})", r, TimeUtils.printDuration(period, false)); + } + if (camelContext.hasService(ContextReloadStrategy.class) == null) { + // refresh is enabled then we need to automatically enable context-reload as well + ContextReloadStrategy reloader = new DefaultContextReloadStrategy(); + camelContext.addService(reloader); + } + PeriodTaskScheduler scheduler = PluginHelper.getPeriodTaskScheduler(camelContext); + scheduler.schedulePeriodTask(r, period); + } + } + + if (vc.azure().isRefreshEnabled()) { + Optional<Runnable> task = PluginHelper.getPeriodTaskResolver(camelContext) + .newInstance("azure-secret-refresh", Runnable.class); + if (task.isPresent()) { + long period = vc.azure().getRefreshPeriod(); + Runnable r = task.get(); + if (LOG.isDebugEnabled()) { + LOG.debug("Scheduling: {} (period: {})", r, TimeUtils.printDuration(period, false)); + } + if (camelContext.hasService(ContextReloadStrategy.class) == null) { + // refresh is enabled then we need to automatically enable context-reload as well + ContextReloadStrategy reloader = new DefaultContextReloadStrategy(); + camelContext.addService(reloader); + } + PeriodTaskScheduler scheduler = PluginHelper.getPeriodTaskScheduler(camelContext); + scheduler.schedulePeriodTask(r, period); + } + } + } + public static void afterPropertiesSet(final CamelContext camelContext) throws Exception { // additional configuration }
