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

System properties are ignored when using Hocon files/strings #419

Open
BernardMarshall opened this issue Oct 14, 2020 · 3 comments
Open
Labels
good first issue Good for newcomers

Comments

@BernardMarshall
Copy link

The parsing of the Hocon files and strings use the ConfigFactory.parseFile and ConfigFactory.parseString methods. Both these methods load the configuration but do not include the system properties. Hence if you have substitutions of the form ${?app.config} in your Hocon file/string then the substitution is not resolved if the value is set in the system properties. To have the system properties loaded a call to ConfigFactory.defaultOverrides is required.

A possible fix (in TypesafeConfigSource.scala) is to change:

def fromHoconFile[A](
    file: File
  ): Task[ConfigSource] =
    IO.effect(ConfigFactory.parseFile(file).resolve)
      .flatMap(typesafeConfig => {

to be:

def fromHoconFile[A](
    file: File
  ): Task[ConfigSource] =
    IO.effect(ConfigFactory.defaultOverrides.withFallback(ConfigFactory.parseFile(file)).resolve)
      .flatMap(typesafeConfig => {

A similar change could be added to the fromHoconString method. The change ensures system properties are resolved correctly in Hocon files/strings.

@afsalthaj
Copy link
Collaborator

Another way of doing it is using orElse combinator in ConfigSource.

descriptor[MyConfig] from source1.orElse(source2)

@BernardMarshall
Copy link
Author

Thanks for the reply. Yes that is possible. It just means moving the ${?app.config} markers out of the Hocon file and into a config descriptor so that the system properties can be used. Not a big deal, but it is nice to have the markers in the Hocon file as it "documents" how a config property can be set.

@afsalthaj
Copy link
Collaborator

afsalthaj commented Nov 26, 2020 via email

@afsalthaj afsalthaj added the good first issue Good for newcomers label Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants