hi <@U12AGS8JG> - running into an interesting situ...
# hoplite
p
hi @sam - running into an interesting situation, is this the expected behaviour?
given
Copy code
redis {
  host = ${MY_REDIS_HOST}
  port = ${MY_REDIS_PORT}
}
if the following is in the environment:
MY_REDIS_PORT=6378 redis.port=6379
using
Copy code
data class RedisConfig(host: String, port: Int)
i’ll end up with
RedisConfig("..", 6379)
i was expecting to end up with
RedisConfig("..", 6378)
s
that's an interesting one
it's because it's using the env as a property source (for all values)
I guess the preprocessor one should override it
hmm it's tricky to fix
the env var property source like "overlays" on the files
you could disable that
p
i have no idea why
redis.port
in the environment is taking precedence over
MY_REDIS_PORT
in the environment if i specified
MY_REDIS_PORT
in my HOCON config file?
s
because the env vars form like a "hidden" file
that's applied over the top
p
by why does
redis.port
even apply to set the value in HOCON? i know that syntax is supported for reading values from the parsed HOCON configuration
s
its not related to hocon
you have an env var called 'redis.port' right
p
right
s
so that forms a "file" which is like { redis { port : 1234 } }
which then is the first match when the decoder says "give me a value for redis.port"
p
ahhh
s
if I'm right, it's not even getting to your hocon file, and therefore the hocon override, because it's already present in the env
The 
EnvironmentVariablesPropertySource
SystemPropertiesPropertySource
 and 
UserSettingsPropertySource
 sources are automatically registered, with precedence in that order
EnvironmentVariablesPropertySource The 
EnvironmentVariablesPropertySource
 reads config from environment variables. It does not map cases so 
HOSTNAME
 does not provide a value for a field with the name 
hostname
. For nested config, use a period to seperate keys, for example 
topic.name
 would override 
name
 located in a 
topic
 parent. Alternatively, in some environments a 
.
 is not supported in ENV names, so you can also use double underscore 
__
. Eg 
topic__name
 would override name in a Topic object. Optionally you can also create a 
EnvironmentVariablesPropertySource
 with 
allowUppercaseNames
 set to 
true
 to allows for uppercase-only names.
what you can do is create your config loader without the default sources, then it won't use that EnvironmentVariablesPropertySource
withDefaultSources(false) on the builder
p
will it still substitute
host = ${MY_REDIS_HOST}
?
with the value of
MY_REDIS_HOST
s
yes because that is an override that is applied by the envvar preprocessor
so its another path
now I think about it the EnvironmentVariablesPropertySource might not make a ton of sense
it's just useful if you want to set ENV vars without putting them in files
p
gotcha - i understand now
s
like you could do
redis.port
an env
and you wouldn't need to put it in the hocon at all
which is exactly how you found this to start with
p
EnvironmentVariablesPropertySource
vs
EnvVarPreprocessor
… i missed the distinction there initially 😅
s
hope that helps
p
thanks much!
👍🏻 1