You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2024/01/17 03:12:47 UTC
(james-project) 02/02: [DOC] Documentation fallback value capability for environment variable configuration
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 651364a19ee81b8f10a29c5ee408734d84f8a57f
Author: Quan Tran <hq...@linagora.com>
AuthorDate: Tue Jan 16 16:00:47 2024 +0700
[DOC] Documentation fallback value capability for environment variable configuration
---
.../org/apache/james/utils/FileConfigurationProviderTest.java | 11 ++++++++++-
server/container/guice/common/src/test/resources/test.xml | 1 +
src/site/xdoc/server/config.xml | 3 ++-
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/server/container/guice/common/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java b/server/container/guice/common/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java
index 003313b1eb..a0a7a2c697 100644
--- a/server/container/guice/common/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java
+++ b/server/container/guice/common/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java
@@ -41,10 +41,12 @@ class FileConfigurationProviderTest {
private static final String CONFIG_KEY_ENV = "env";
private static final String CONFIG_KEY_ENV_WITH_COMMA = "envWithComma";
private static final String CONFIG_KEY_NOT_ENV = "notEnv";
+ private static final String CONFIG_KEY_ENV_WITH_FALLBACK_VALUE = "envWithFallbackValue";
private static final String VALUE_1 = "0";
private static final String VALUE_2 = "awesome";
private static final String VALUE_3 = "james";
private static final String VALUE_NOT_ENV = "${env:MY_NOT_IN_ENV_VAR}";
+ private static final String FALLBACK_VALUE = "fallbackValue";
private static final String ENVIRONMENT_SET_VALUE = "testvalue";
private static final String ENVIRONMENT_WITH_COMMA = "testvalue,testvalue2,testvalue3";
private static final String FAKE_CONFIG_KEY = "fake";
@@ -95,7 +97,8 @@ class FileConfigurationProviderTest {
.containsOnly(CONFIG_KEY_1,
String.join(CONFIG_SEPARATOR, CONFIG_KEY_4, CONFIG_KEY_2),
String.join(CONFIG_SEPARATOR, CONFIG_KEY_4, CONFIG_KEY_5, CONFIG_KEY_2),
- CONFIG_KEY_ENV, CONFIG_KEY_ENV_WITH_COMMA, CONFIG_KEY_NOT_ENV);
+ CONFIG_KEY_ENV, CONFIG_KEY_ENV_WITH_COMMA, CONFIG_KEY_NOT_ENV,
+ CONFIG_KEY_ENV_WITH_FALLBACK_VALUE);
assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_1)).isEqualTo(VALUE_1);
}
@@ -165,4 +168,10 @@ class FileConfigurationProviderTest {
assertThat(hierarchicalConfiguration.getString(CONFIG_KEY_ENV_WITH_COMMA)).isEqualTo(ENVIRONMENT_WITH_COMMA);
});
}
+
+ @Test
+ void getEnvironmentVariableShouldDefaultToFallbackValueIfSet() throws Exception {
+ HierarchicalConfiguration<ImmutableNode> hierarchicalConfiguration = configurationProvider.getConfiguration(ROOT_CONFIG_KEY);
+ assertThat(hierarchicalConfiguration.getString(CONFIG_KEY_ENV_WITH_FALLBACK_VALUE)).isEqualTo(FALLBACK_VALUE);
+ }
}
diff --git a/server/container/guice/common/src/test/resources/test.xml b/server/container/guice/common/src/test/resources/test.xml
index 771a0cc4b2..5c8606456d 100644
--- a/server/container/guice/common/src/test/resources/test.xml
+++ b/server/container/guice/common/src/test/resources/test.xml
@@ -28,4 +28,5 @@
<env>${env:MY_ENV_VAR}</env>
<envWithComma>${env:MY_ENV_VAR_WITH_COMMA}</envWithComma>
<notEnv>${env:MY_NOT_IN_ENV_VAR}</notEnv>
+ <envWithFallbackValue>${env:MY_NOT_IN_ENV_VAR:-fallbackValue}</envWithFallbackValue>
</test>
diff --git a/src/site/xdoc/server/config.xml b/src/site/xdoc/server/config.xml
index f144694ac6..7e0328e5e4 100644
--- a/src/site/xdoc/server/config.xml
+++ b/src/site/xdoc/server/config.xml
@@ -41,7 +41,8 @@
<p>In every configuration files, you can use the following notation to use an environment variable: <code>${env:MY_VAR}</code>.
If <code>MY_VAR</code> exists, it will be replaced by the matching environment variable.
- If it does not, <code>${env:MY_VAR}</code> will be kept as is.</p>
+ If it does not, <code>${env:MY_VAR}</code> will be kept as is.
+ If you want to configure a fallback value for the environment variable, you can use <code>${env:MY_VAR:-fallbackValue}</code>.</p>
<p>You can/must configure James for the following:</p>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org