Define a mapping rule from config property name to environment variable
See original GitHub issue@Emily-Jiang commented on Wed Nov 15 2017
As the name of environment variable can only use alphabets and _ , it is difficult to override some config properties as environment variables.
e.g. com.acme.me=“blah”
This property cannot be specified as environment variable. How about to directly translate . to _ for the corresponding environment variables.
com.acme.me -> com_acme_me In this way, this property can be defined or override in environment variable.
@struberg commented on Wed Nov 15 2017
+1 to add it explicitly!
been there, done that 2 years ago 😉
https://issues.apache.org/jira/browse/DELTASPIKE-1090 https://github.com/apache/deltaspike/blame/master/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/config/EnvironmentPropertyConfigSource.java#L55
@kazumura commented on Wed Nov 15 2017
That means you cannot use ‘_’ as a property key.
e.g.
foo._bar
foo_.bar
foo..bar
foo__bar
Are all these same ?
I prefer to add a flag to specify auto converting or not.
@struberg commented on Wed Nov 15 2017
yes, you could not distinguish those in the EnvironmentConfigSource, but everywhere else. In practice it’s not really an issue.
We first catched this issue when integrating Docker where ENV=… can also not contain any dots via scripts.
@kazumura commented on Wed Nov 15 2017
I agree the auto converting as the default behavior.
But there are some people who already use ‘’ as the keys. My point is, should we provide them an option to use this feature or not? I don’t know how many people already use '’. May not major.
@TFaga commented on Wed Nov 15 2017
+1 for .
-> _
as well. We’re also doing this in KumuluzEE.
Another question though. How about other common characters that are used but not typically found or allowed in environemnt variable key names (like -
, [
, ]
, …)? While there’s not much that can be done about those examples, perhaps at least a note somewhere that certain characters may be problematic to use from the environment or that it’s up to the implementation how it’s additionally handled?
@Emily-Jiang commented on Thu Nov 16 2017
Yes, I think we should just pick the commonly used one like “.” for the reason of @kazumura brought up, which will create overlapping. We can clearly document this as you said@TFaga !
@lilian-benoit commented on Wed Nov 29 2017
+1 for . -> _ as well. Usually, we use _ for environment variable.
is property name case-sensitive ? In fact, we have COM_ACME_ME as environment variable.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top GitHub Comments
I suggest to require that environment variables with underscores are mapped to multiple keys. It should be a problem if e.g. a variable
COM_ACME_ME
represents all of these keys:COM_ACME_ME
com_acme_me
com.acme.me
All of them with the same value. There’s almost no chance that an application would want to distinguish between these keys and would expect that there are different values under those keys.
Dashes in Java property names are something else the mapping rule will have to consider (and are somewhat common in Java property names). I’ve created https://github.com/eclipse/ConfigJSR/issues/53 since the microprofile-config team seems to be aligning this specification with the broader specification.