EnvironmentVariablesConfigurationSource replaces _ with .
brock-civitas opened this issue · comments
EnvironmentVariablesConfigurationSource
replaces _
in the environment variable name with .
:
Unless I missed something, this behavior was not documented at: http://www.javadoc.io/doc/org.cfg4j/cfg4j-core/4.4.0
Thoughts:
a) Why do this in the first place?
b) If the property name is going to be mangled, perhaps also converting to lowercase would be more "expected" per typical Java system property standards?
Thanks,
Brock
+1
I think that replacing _ with . is the right thing to do, as it respects the conventions of using _ as a word separator in environment variable names and links that nicely with the existing convention in properties files of using . to express hierarchy. I also agree that converting to lower case would be the right thing to do, and wrote https://github.com/ExpediaDotCom/haystack-pipes/blob/master/commons/src/main/java/com/expedia/www/haystack/pipes/commons/ChangeEnvVarsToLowerCaseConfigurationSource.java. I'm not totally happy with this implementation...it feels like it ought to leverage the Environment class in cfg4j, but that was problematic because trying to do so insisted on file hierarchy existing which isn't a requirement for environment variable based configuration...but the class works for our use case.
Darn, this tripped me up too. Would be nice if in addition to replacing _
in ENV var with .
in property, it also lowercased the property name.
So unless your file-based foo.properties
has the same casing as the ENV-based (which for most people is UPPERCASE_WITH_UNDERSCORE
), when you try and merge, you get 2 sets of properties instead of ENV overwriting file. This forces you to have uppercased properties in foo.properties
which is not ideal/conventional.