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

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

commit 5e51568f1ef6e4937d151009b619b24c2dfca5dc
Author: Claus Ibsen <claus.ib...@gmail.com>
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     | 69 ---------------------
 .../camel/main/DefaultConfigurationConfigurer.java | 72 ++++++++++++++++++++++
 2 files changed, 72 insertions(+), 69 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 7d5835683eb..2dccb705cfc 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
@@ -387,73 +387,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()) {
-            Optional<Runnable> task = 
camelContext.adapt(ExtendedCamelContext.class)
-                    .getPeriodTaskResolver().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 = 
getCamelContext().adapt(ExtendedCamelContext.class).getPeriodTaskScheduler();
-                scheduler.schedulePeriodTask(r, period);
-            }
-        }
-
-        if (vc.gcp().isRefreshEnabled()) {
-            Optional<Runnable> task = 
camelContext.adapt(ExtendedCamelContext.class)
-                    .getPeriodTaskResolver().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 = 
getCamelContext().adapt(ExtendedCamelContext.class).getPeriodTaskScheduler();
-                scheduler.schedulePeriodTask(r, period);
-            }
-        }
-
-        if (vc.azure().isRefreshEnabled()) {
-            Optional<Runnable> task = 
camelContext.adapt(ExtendedCamelContext.class)
-                    
.getPeriodTaskResolver().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 = 
getCamelContext().adapt(ExtendedCamelContext.class).getPeriodTaskScheduler();
-                scheduler.schedulePeriodTask(r, period);
-            }
-        }
-    }
-
     protected void autoconfigure(CamelContext camelContext) throws Exception {
         // gathers the properties (key=value) that was auto-configured
         final OrderedLocationProperties autoConfiguredProperties = new 
OrderedLocationProperties();
@@ -696,8 +629,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 3f53dfa2ed3..0e84d35ae6f 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;
@@ -61,6 +62,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;
@@ -86,6 +88,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;
@@ -589,10 +592,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 = 
camelContext.adapt(ExtendedCamelContext.class)
+                    .getPeriodTaskResolver().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 = 
camelContext.adapt(ExtendedCamelContext.class).getPeriodTaskScheduler();
+                scheduler.schedulePeriodTask(r, period);
+            }
+        }
+
+        if (vc.gcp().isRefreshEnabled()) {
+            Optional<Runnable> task = 
camelContext.adapt(ExtendedCamelContext.class)
+                    .getPeriodTaskResolver().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 = 
camelContext.adapt(ExtendedCamelContext.class).getPeriodTaskScheduler();
+                scheduler.schedulePeriodTask(r, period);
+            }
+        }
+
+        if (vc.azure().isRefreshEnabled()) {
+            Optional<Runnable> task = 
camelContext.adapt(ExtendedCamelContext.class)
+                    
.getPeriodTaskResolver().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 = 
camelContext.adapt(ExtendedCamelContext.class).getPeriodTaskScheduler();
+                scheduler.schedulePeriodTask(r, period);
+            }
+        }
+    }
+
     public static void afterPropertiesSet(final CamelContext camelContext) 
throws Exception {
         // additional configuration
     }

Reply via email to