lightbend / config

configuration library for JVM languages using HOCON files
https://lightbend.github.io/config/
6.17k stars 967 forks source link

Nested configuration from environment variables #559

Closed colltoaction closed 6 years ago

colltoaction commented 6 years ago

I'm trying to allow users to set configuration through environment variables (specially helpful in dockerized environments) but the library doesn't pick up the values I'm setting.

Before, we were using System Properties (e.g. -Drpc.providers.web.http.bind_address=hostname) and it worked just fine.

Then I tried setting the same configuration through environment variables and reading it with the following:

Config config = ConfigFactory.systemProperties()
                .withFallback(ConfigFactory.systemEnvironment())
                .withFallback(baseProperties);

When I call config.getString("rpc.providers.web.http.bind_address") I don't get the value of my environment variable, but the default value I had in baseProperties.The library seems to fail to detect nested properties as seen in the debugger:

image

I'm guessing there might be an assumption that env vars can't have dots in them, but I haven't had the time to check the code yet.

I'm using com.typesafe:config:1.3.1.

Thanks!

havocp commented 6 years ago

Version 1.3.2 has the fix you need I think: https://github.com/lightbend/config/pull/427

colltoaction commented 6 years ago

It works! Sorry for the spam :)