I've been using the environment variable substitution feature in Typesafe config:
foo = "foo"
foo = ${?FOO}
This results in a "default" value of "foo" if there is no environment variable named FOO. In this case, the second value declaration (foo = ${?FOO} is simply discarded). However, if a variable named FOO exists, the library will "substitute" the value of FOO and assign it to foo.
I would like similar behavior with arrays, but unfortunately, this does not work as expected:
foo = [ "1", "2" ]
foo = [ ${?f1}, ${?f2} ]
In the case where f1 and f2 are not defined, this simply results in foo being an empty array. My goal is to have a similar effect as above (discard the second foo if no environment variables f1 and f2 are defined). Any ideas/suggestions are appreciated. Thanks.
I found that using a = ${?VARNAME} in the HOCON config file with the Scala code expecting a List, and using -DVARNAME.0=something (or simply VARNAME.0=something) will result in the correct ["something"] value. (Tested with Play 2.6.13 and the AllowedHosts filter.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With