-
Notifications
You must be signed in to change notification settings - Fork 967
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
Allow environment vars to be resolved to list #427
Conversation
Thanks! I would really like the "fork in test" fix, regardless of the env var thing, if you are interested in making that its own PR? Re: the env vars, it seems like there are two issues with this. One is that it isn't quite backward compatible, though we could probably fudge it, mostly because I doubt anyone is using dots in env vars due to the second issue - Second issue is that bash and other tools really don't support this. http://unix.stackexchange.com/questions/93532/exporting-a-variable-with-dot-in-it
It looks like libc is maybe ok with it (if you can arrange to call setenv() programmatically), but if bash chokes a bunch of other ops tools like Docker, Ansible, stuff like that probably choke too. (Those are just speculative examples, I haven't gone and tried them.) Anyway, it doesn't seem like a great solution for that reason. I don't know if any of the other issues have discussion of more ideas; I wonder if a special env var that could contain HOCON directly, like |
Env var with I think hacks like |
@havocp Is there a chance to make system properties and env variables interchangeable? As I said using docker there is a easy way to define env variables with dots and it works, using docker-compose also there is a way to define such env vars. |
@havocp is there any chance to merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, I just couldn't immediately decide what to do about it. I guess it can't really hurt to support this.
In a perfect world this PR would be split into separate commits for the fork in Test
fix and the properties-parsing feature, using rebase -i
or add -p
for example.
I'd like to avoid creating a Properties and going through the Parseable code, I think it's a matter of adding a short method to PropertiesParser.java that takes a Map<String,String>
instead of a Properties
. Otherwise I'm afraid of surprises where someone naturally assumes that the ParseableProperties only handles properties and makes changes that should not be applied to env vars.
Thank you for your patience and help.
props.putAll(System.getenv()); | ||
|
||
return (AbstractConfigObject) Parseable.newProperties(props, | ||
ConfigParseOptions.defaults().setOriginDescription("env variables")).parse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a little cleaner I think to add a static method in PropertiesParser.java akin to fromProperties
but instead it would be fromStringMap(Map<String,String>)
, to avoid going through the Parseable indirection and avoid creating a Properties object here.
Thanks for feedback. I will split those changes into two commits and apply your suggestions in few days. |
9b7cc1e
to
13ae0dd
Compare
@havocp I've rebased, split this MR into two commits and applied changes that you suggested. Also I found the reason why build was falling on windows machines (TimeZone.getDefault issue described in a comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for updating the PR, looks good!
def before(): Unit = { | ||
// TimeZone.getDefault internally invokes System.setProperty("user.timezone", <default time zone>) and it may | ||
// cause flaky tests depending on tests order and jvm options. This method is invoked | ||
// eg. by URLConnection.getContentType (it reads headers and gets default time zone). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good find! I imagine that was some work to track down...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it took few hours. I had to use windows OS because on linux I wasn't able to reproduce the issue - it was horrible :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ouch, I know the feeling :-)
Today while trying to use this PR I learned a few things:
I hope this saves future folks some time. |
- lightbend/config#427 added support to the Java version of Hocon for lists of environment variables. For instance, given a Hocon configuration file like: "a": ${testList} And the environment variables: testList.0=0 testList.1=1 Then the Hocon configuration file will resolve to the values: "a": ["0", "1"] - Implement the behavior in the Ruby code and Add specs demonstrating this new behavior
It has been requested few times so far: #320, #168. Is there any contraindication why env vars cannot be treated the same way as system properties (in case of syntax)?