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

Cannot override hocon configuration with env variables #115

Closed
psilos opened this issue Mar 19, 2020 · 12 comments
Closed

Cannot override hocon configuration with env variables #115

psilos opened this issue Mar 19, 2020 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@psilos
Copy link

psilos commented Mar 19, 2020

Hello,

It seems that when I try to override my HOCON configuration with env variables like this:

mongo {
  hostname = "localhost"
  hostname = ${?MONGO_HOSTNAME}
}

and load configuration with:

val config = ConfigLoader().loadConfigOrThrow<Conf>("/application.conf")

hoplite throws the following error:

com.typesafe.config.ConfigException$NotResolved: called valueType() on value with unresolved substitutions, need to Config#resolve() first, see API docs at com.typesafe.config.impl.ConfigDelayedMerge.valueType(ConfigDelayedMerge.java:46) at com.sksamuel.hoplite.hocon.ValueProduction.invoke(HoconParser.kt:51) at com.sksamuel.hoplite.hocon.MapProduction.invoke(HoconParser.kt:41) at com.sksamuel.hoplite.hocon.ValueProduction.invoke(HoconParser.kt:52) at com.sksamuel.hoplite.hocon.MapProduction.invoke(HoconParser.kt:41) at com.sksamuel.hoplite.hocon.HoconParser.load(HoconParser.kt:27) at com.sksamuel.hoplite.ConfigFilePropertySource$node$1.invoke(PropertySource.kt:92) at com.sksamuel.hoplite.ConfigFilePropertySource$node$1.invoke(PropertySource.kt:86) at com.sksamuel.hoplite.arrow.ValidationsKt.ap(validations.kt:23) at com.sksamuel.hoplite.ConfigFilePropertySource.node(PropertySource.kt:91) at com.sksamuel.hoplite.ConfigLoader.loadNode(ConfigLoader.kt:161) at com.sksamuel.hoplite.ConfigLoader.loadConfig(ConfigLoader.kt:149)

This is the default HOCON way of overriding with env variables, is there an alternative syntax to use?

@sksamuel
Copy link
Owner

I guess hoplite should call .resolve on sources coming from hocon to fix that.

@sksamuel
Copy link
Owner

The other way you can do it is using hoplite's format for ENV vars. ${VAR}

@psilos
Copy link
Author

psilos commented Mar 20, 2020

Thanks for the quick response @sksamuel , I believe the first option is preferable to be fully compatible with HOCON, as this syntax means it would override the value only if it's present, does the later convey the same semantics ?

@sksamuel
Copy link
Owner

No you're right, I'll do it the first way.

@sksamuel sksamuel added the bug Something isn't working label Mar 24, 2020
@sksamuel sksamuel self-assigned this Mar 29, 2020
@psilos
Copy link
Author

psilos commented Apr 2, 2020

Hi @sksamuel , do you think that this is an easy fix of calling .resolve() to override default values with env variables? Or are you concerned that this may conflict with hoplites way of overriding values ?

@sksamuel
Copy link
Owner

sksamuel commented Apr 4, 2020

I think calling .resolve() inside the Hocon parser should be sufficient.

@sksamuel
Copy link
Owner

sksamuel commented Apr 4, 2020

This is fixed in 1.2.1.

@sksamuel sksamuel closed this as completed Apr 4, 2020
@psilos
Copy link
Author

psilos commented Apr 6, 2020

thanks for the quick fix @sksamuel , looking forward to 1.2.1 release

@psilos
Copy link
Author

psilos commented Apr 7, 2020

hi @sksamuel sorry to bug you again, was wondering if there is a schedule for this release :)

Really keen to put in good use :P

@sksamuel
Copy link
Owner

sksamuel commented Apr 7, 2020 via email

@sksamuel
Copy link
Owner

sksamuel commented Apr 11, 2020 via email

@psilos
Copy link
Author

psilos commented Apr 12, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants