Configuration utils: EnvironmentConfiguration extension to support UPPER_SNAKE_CASE for environment variables
wajda opened this issue · 0 comments
Problem
The existing org.apache.commons.configuration.EnvironmentConfiguration
provides access to the environment variables via an abstract Configuration
API. However the problem is that while the more abstract Configuration
operates with properties (that in turn implies a dot-separated key notation considered a standard in Java world) the EnvironmentConfiguration
preserves original environment variable names which is usually an upper-cased snake notation. This discrepancy spill out the particular class implementational details over its API, and logically couples the caller to the implementation.
One of the use-cases where the issue pops is CompositeConfiguration
. Combining EnvironmentConfiguration
with almost any other Configuration
implementation in one bucket won't work as expected.
Example:
val conf = new CompositeConfiguration(asList(
new EnvironmentConfiguration,
new SystemConfiguration,
new JNDIConfiguration("java:comp/env")
))
conf.getString("java.vm.vendor") should not be null // OK - defined in JVM system properties as "java.vm.vendor"
conf.getString("env.jdbc.datasource") should not be null // OK - defined in JNDI as "java:comp/env/jdbc/datasource"
conf.getString("scala.home") should not be null // FAILS !!!
conf.getString("SCALA_HOME") should not be null // OK - defined in System environment, so I have to use a proper notation
Solution
Create an extension to the EnvironmentConfiguration
that would respect domain naming convention for keys, so that calling
(new EnvironmentConfiguration).getString("scala.home") // would lookup for SCALA_HOME in system environment
Similarly to how it's done in JNDIConfiguration
for instance.