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

List as a environment variable #369

Closed
mafernandez-stratio opened this issue Jan 25, 2016 · 6 comments
Closed

List as a environment variable #369

mafernandez-stratio opened this issue Jan 25, 2016 · 6 comments

Comments

@mafernandez-stratio
Copy link

Hi,

I'm trying to override a configuration parameter of a typesafe config with a environment variable but I couldn't make it.

These are the steps that I tried:

  • myConfig.conf contains these two lines:
    1. myConfig.nodes = ["127.0.0.1"]
    2. myConfig.nodes = ${?MY_NODES}
  • In the bash shell I write:
    1. export MY_NODES="['0.0.0.0']"
  • I check the result
    1. echo $MY_NODES ==> ['0.0.0.0']
  • When the application using this config files starts, the next error shows up:
    1. java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
      at java.lang.Thread.run(Thread.java:745)
      Caused by: com.typesafe.config.ConfigException$ValidationFailed: env var MY_NODES: MY_NODES: Wrong value type at 'MY_NODES', expecting: list but got: string

Is it possible to use list for environment variables? Am I doing something wrong?

Thanks in advance

@havocp
Copy link
Collaborator

havocp commented Jan 25, 2016

There's no way to do this because it would introduce a need to escape special chars in env vars that were just strings. For system properties you can set foo.0, foo.1 and it will read as a list. For env vars there isn't a solution we've come up with.

@havocp havocp closed this as completed Mar 5, 2016
@linehrr
Copy link

linehrr commented Mar 14, 2019

@havocp what if we define hint for this case, like mylist=@${?ENV_LIST} so even tho ENV_LIST holds a string representation of list like "[1,2,3,4]", since there is a hint @, the lib will treat is as a list and do its best to parse it as list.

@havocp
Copy link
Collaborator

havocp commented Mar 14, 2019

The ".0", ".1" trick does actually work for env vars now IIRC, though many setups make it annoying to set env vars with dots in them.

I think there may be something to that idea - It wouldn't have to be list-specific, perhaps a way to simply say "parse this value as JSON" and you could put any kind of JSON in there.

@linehrr
Copy link

linehrr commented Mar 14, 2019

@havocp now the question is, do we want to make it 'super flexible' so that ppl can inject structure into config from env vars, or we want to limit env injection to only primitives ❓

@mkobit
Copy link

mkobit commented Apr 13, 2019

Is this closed as a "won't do this" as it doesn't fit with the design with the library?

I think something like this could be useful, but I can understand the reluctance to put in a way to process the environment variable as a list.

@havocp
Copy link
Collaborator

havocp commented Apr 13, 2019

I’m not necessarily against some way to specify values should be parsed as HOCON/JSON, but it can’t be done by default for values that are currently interpreted as plain strings.

eg the idea in #582 to have some sort of CONFIG_OVERRIDES variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants