This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 3eca9b4 CAMEL-13690: camel-main - Option to disable using OS environment variables. 3eca9b4 is described below commit 3eca9b45645a3ee9e13121f2c7b6467066f6d1e5 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Jun 27 12:14:48 2019 +0200 CAMEL-13690: camel-main - Option to disable using OS environment variables. --- .../camel/main/MainConfigurationProperties.java | 28 ++++++++++ .../java/org/apache/camel/main/MainSupport.java | 64 ++++++++++++++-------- .../camel-main-configuration-metadata.json | 7 +++ .../META-INF/spring-configuration-metadata.json | 7 +++ .../META-INF/spring-configuration-metadata.json | 7 +++ .../META-INF/spring-configuration-metadata.json | 7 +++ 6 files changed, 98 insertions(+), 22 deletions(-) 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 2925337..fe3aa8d 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 @@ -22,6 +22,7 @@ package org.apache.camel.main; public class MainConfigurationProperties extends DefaultConfigurationProperties<MainConfigurationProperties> { private boolean autoConfigurationEnabled = true; + private boolean autoConfigurationEnvironmentVariablesEnabled = true; private boolean autoConfigurationFailFast = true; private boolean autowireComponentProperties = true; private boolean autowireComponentPropertiesDeep; @@ -81,6 +82,21 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties< this.autoConfigurationEnabled = autoConfigurationEnabled; } + public boolean isAutoConfigurationEnvironmentVariablesEnabled() { + return autoConfigurationEnvironmentVariablesEnabled; + } + + /** + * Whether auto configuration should include OS environment variables as well. When enabled this + * allows to overrule any configuration using an OS environment variable. For example to set + * a shutdown timeout of 5 seconds: CAMEL_MAIN_SHUTDOWNTIMEOUT=5. + * <p/> + * This option is default enabled. + */ + public void setAutoConfigurationEnvironmentVariablesEnabled(boolean autoConfigurationEnvironmentVariablesEnabled) { + this.autoConfigurationEnvironmentVariablesEnabled = autoConfigurationEnvironmentVariablesEnabled; + } + public boolean isAutoConfigurationFailFast() { return autoConfigurationFailFast; } @@ -188,6 +204,18 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties< } /** + * Whether auto configuration should include OS environment variables as well. When enabled this + * allows to overrule any configuration using an OS environment variable. For example to set + * a shutdown timeout of 5 seconds: CAMEL_MAIN_SHUTDOWNTIMEOUT=5. + * <p/> + * This option is default enabled. + */ + public MainConfigurationProperties withAutoConfigurationEnvironmentVariablesEnabled(boolean autoConfigurationEnvironmentVariablesEnabled) { + this.autoConfigurationEnvironmentVariablesEnabled = autoConfigurationEnvironmentVariablesEnabled; + return this; + } + + /** * Whether auto configuration should fail fast when configuring one ore more properties fails for whatever reason * such as a invalid property name, etc. * <p/> diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java index af3787f..57be0f3 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java @@ -776,18 +776,30 @@ public abstract class MainSupport extends ServiceSupport { LOG.debug(" {}={}", key, prop.getProperty(key)); } + // special for environment-variable-enbaled as we need to know this early before we set all the other options + Object envEnabled = prop.remove("camel.main.autoConfigurationEnvironmentVariablesEnabled"); + if (envEnabled == null) { + envEnabled = prop.remove("camel.main.auto-configuration-environment-variables-enabled"); + if (envEnabled != null) { + PropertyBindingSupport.bindMandatoryProperty(camelContext, mainConfigurationProperties, "autoConfigurationEnvironmentVariablesEnabled", envEnabled, true); + } + } + // load properties from ENV (override existing) - Properties propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.main."}); - if (!propENV.isEmpty()) { - prop.putAll(propENV); - LOG.debug("Properties from OS environment variables:"); - for (String key : propENV.stringPropertyNames()) { - LOG.debug(" {}={}", key, propENV.getProperty(key)); + Properties propENV = null; + if (mainConfigurationProperties.isAutoConfigurationEnvironmentVariablesEnabled()) { + propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.main."}); + if (!propENV.isEmpty()) { + prop.putAll(propENV); + LOG.debug("Properties from OS environment variables:"); + for (String key : propENV.stringPropertyNames()) { + LOG.debug(" {}={}", key, propENV.getProperty(key)); + } } } // special for fail-fast as we need to know this early before we set all the other options - Object failFast = propENV.remove("camel.main.autoconfigurationfailfast"); + Object failFast = propENV != null ? propENV.remove("camel.main.autoconfigurationfailfast") : null; if (failFast != null) { PropertyBindingSupport.bindMandatoryProperty(camelContext, mainConfigurationProperties, "autoConfigurationFailFast", failFast, true); } else { @@ -843,12 +855,14 @@ public abstract class MainSupport extends ServiceSupport { Properties prop = camelContext.getPropertiesComponent().loadProperties(); // load properties from ENV (override existing) - Properties propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.component.properties."}); - if (!propENV.isEmpty()) { - prop.putAll(propENV); - LOG.debug("Properties from OS environment variables:"); - for (String key : propENV.stringPropertyNames()) { - LOG.debug(" {}={}", key, propENV.getProperty(key)); + if (mainConfigurationProperties.isAutoConfigurationEnvironmentVariablesEnabled()) { + Properties propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.component.properties."}); + if (!propENV.isEmpty()) { + prop.putAll(propENV); + LOG.debug("Properties from OS environment variables:"); + for (String key : propENV.stringPropertyNames()) { + LOG.debug(" {}={}", key, propENV.getProperty(key)); + } } } @@ -931,9 +945,11 @@ public abstract class MainSupport extends ServiceSupport { Properties prop = camelContext.getPropertiesComponent().loadProperties(); // load properties from ENV (override existing) - Properties propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.component.properties."}); - if (!propENV.isEmpty()) { - prop.putAll(propENV); + if (mainConfigurationProperties.isAutoConfigurationEnvironmentVariablesEnabled()) { + Properties propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.component.properties."}); + if (!propENV.isEmpty()) { + prop.putAll(propENV); + } } Map<String, Object> properties = new LinkedHashMap<>(); @@ -966,9 +982,11 @@ public abstract class MainSupport extends ServiceSupport { Properties prop = camelContext.getPropertiesComponent().loadProperties(); // load properties from ENV (override existing) - Properties propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.main."}); - if (!propENV.isEmpty()) { - prop.putAll(propENV); + if (mainConfigurationProperties.isAutoConfigurationEnvironmentVariablesEnabled()) { + Properties propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.main."}); + if (!propENV.isEmpty()) { + prop.putAll(propENV); + } } Map<String, Object> properties = new LinkedHashMap<>(); @@ -1024,9 +1042,11 @@ public abstract class MainSupport extends ServiceSupport { prop.putAll(propPC); // load properties from ENV (override existing) - Properties propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.component.", "camel.dataformat.", "camel.language."}); - if (!propENV.isEmpty()) { - prop.putAll(propENV); + if (mainConfigurationProperties.isAutoConfigurationEnvironmentVariablesEnabled()) { + Properties propENV = loadEnvironmentVariablesAsProperties(new String[]{"camel.component.", "camel.dataformat.", "camel.language."}); + if (!propENV.isEmpty()) { + prop.putAll(propENV); + } } Map<PropertyOptionKey, Map<String, Object>> properties = new LinkedHashMap<>(); diff --git a/core/camel-main/src/main/resources/META-INF/camel-main-configuration-metadata.json b/core/camel-main/src/main/resources/META-INF/camel-main-configuration-metadata.json index 0327eca..99336ac 100644 --- a/core/camel-main/src/main/resources/META-INF/camel-main-configuration-metadata.json +++ b/core/camel-main/src/main/resources/META-INF/camel-main-configuration-metadata.json @@ -31,6 +31,13 @@ "defaultValue":"true" }, { + "name":"camel.main.auto-configuration-environment-variables-enabled", + "type":"boolean", + "sourceType":"org.apache.camel.main.MainConfigurationProperties", + "description":"Whether auto configuration should include OS environment variables as well. When enabled this allows to overrule any configuration using an OS environment variable. For example to set a shutdown timeout of 5 seconds: CAMEL_MAIN_SHUTDOWNTIMEOUT=5. This option is default enabled.", + "defaultValue":"true" + }, + { "name":"camel.main.auto-configuration-fail-fast", "type":"boolean", "sourceType":"org.apache.camel.main.MainConfigurationProperties", diff --git a/examples/camel-example-main-artemis/src/main/resources/META-INF/spring-configuration-metadata.json b/examples/camel-example-main-artemis/src/main/resources/META-INF/spring-configuration-metadata.json index 364d91c..12d0c0a 100644 --- a/examples/camel-example-main-artemis/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/examples/camel-example-main-artemis/src/main/resources/META-INF/spring-configuration-metadata.json @@ -171,6 +171,13 @@ "defaultValue":"true" }, { + "name":"camel.main.auto-configuration-environment-variables-enabled", + "type":"boolean", + "sourceType":"org.apache.camel.main.MainConfigurationProperties", + "description":"Whether auto configuration should include OS environment variables as well. When enabled this allows to overrule any configuration using an OS environment variable. For example to set a shutdown timeout of 5 seconds: CAMEL_MAIN_SHUTDOWNTIMEOUT=5. This option is default enabled.", + "defaultValue":"true" + }, + { "name":"camel.main.auto-configuration-fail-fast", "type":"boolean", "sourceType":"org.apache.camel.main.MainConfigurationProperties", diff --git a/examples/camel-example-main-tiny/src/main/resources/META-INF/spring-configuration-metadata.json b/examples/camel-example-main-tiny/src/main/resources/META-INF/spring-configuration-metadata.json index 31631c0..c10d80b 100644 --- a/examples/camel-example-main-tiny/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/examples/camel-example-main-tiny/src/main/resources/META-INF/spring-configuration-metadata.json @@ -51,6 +51,13 @@ "defaultValue":"true" }, { + "name":"camel.main.auto-configuration-environment-variables-enabled", + "type":"boolean", + "sourceType":"org.apache.camel.main.MainConfigurationProperties", + "description":"Whether auto configuration should include OS environment variables as well. When enabled this allows to overrule any configuration using an OS environment variable. For example to set a shutdown timeout of 5 seconds: CAMEL_MAIN_SHUTDOWNTIMEOUT=5. This option is default enabled.", + "defaultValue":"true" + }, + { "name":"camel.main.auto-configuration-fail-fast", "type":"boolean", "sourceType":"org.apache.camel.main.MainConfigurationProperties", diff --git a/examples/camel-example-main/src/main/resources/META-INF/spring-configuration-metadata.json b/examples/camel-example-main/src/main/resources/META-INF/spring-configuration-metadata.json index b5bf26c..c1e44b9 100644 --- a/examples/camel-example-main/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/examples/camel-example-main/src/main/resources/META-INF/spring-configuration-metadata.json @@ -161,6 +161,13 @@ "defaultValue":"true" }, { + "name":"camel.main.auto-configuration-environment-variables-enabled", + "type":"boolean", + "sourceType":"org.apache.camel.main.MainConfigurationProperties", + "description":"Whether auto configuration should include OS environment variables as well. When enabled this allows to overrule any configuration using an OS environment variable. For example to set a shutdown timeout of 5 seconds: CAMEL_MAIN_SHUTDOWNTIMEOUT=5. This option is default enabled.", + "defaultValue":"true" + }, + { "name":"camel.main.auto-configuration-fail-fast", "type":"boolean", "sourceType":"org.apache.camel.main.MainConfigurationProperties",