Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration utils: EnvironmentConfiguration extension to support UPPER_SNAKE_CASE for environment variables #54

Closed
wajda opened this issue Jan 27, 2021 · 0 comments · Fixed by #55
Assignees
Labels
enhancement New feature or request

Comments

@wajda
Copy link
Contributor

wajda commented Jan 27, 2021

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.

@wajda wajda self-assigned this Jan 27, 2021
@wajda wajda added the enhancement New feature or request label Jan 27, 2021
wajda added a commit that referenced this issue Jan 27, 2021
…o support UPPER_SNAKE_CASE for environment variables
@wajda wajda closed this as completed in #55 Jan 29, 2021
wajda added a commit that referenced this issue Jan 29, 2021
…o support UPPER_SNAKE_CASE for environment variables
@wajda wajda mentioned this issue Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant