I don't think so no, it needs to match case or you...
# hoplite
s
I don't think so no, it needs to match case or your var be all lowercase
🤕 1
d
One of the main reasons I'm using Hoplite is to be able to override any setting using env vars in a k8s deployment... it's a pity that not all configs can be mapped to env vars...
s
In general you can, it just gets more complicated if you haveAVariableLikeThis
d
Which is the standard name format in kotlin
It wouldn't be nice to have data classes with fields like this_setting
s
right, but if you have ENVVAR should that map to envVar or enVvAr or enVvar or eNvvar like the combinations are endless
I'm checking the code to see what we support one sec
d
How do you store these properties after having resolved them from any of the various property sources?
s
it's a single big tree
d
And the names?
s
everything gets merged so we support the cascading lookups
d
Are they lowercased?
s
no, when a field is looked up, param mappers are applied first, which generate "alt" names so you could add your own param mapper
which would just map accessKey to ACCESS_KEY
a bunch of this stuff is built in, I'll let you know in a sec
intellij is indexing so give me 4 hours 😂
😁 1
🙈 1
Copy code
SOME_CAMEL_SETTING
will be automatically applied to someCamelSetting
which is probably what you want
d
There's no such param mapper already existing?
s
you just need to add
Copy code
EnvironmentVariablesPropertySource(true,true)
as a property source
and I think what you want will work
d
I'm trying this in a Kotlin Notebook... but I'm not sure how to provide it with the env var... and setting a system property probably doesn't work the same way?
I need to make sure this works before putting out my service... 🕵🏼‍♂️
s
system properties are another different property service
you could just set the env on your local computer and reload intellij and then the notebook should pick it up
on linux that's easy, but I don't use a mac so no idea how a mac would do it
d
I'm on linux, how would you do it? Just running intellij from the command line with the env var before it?
s
or do
export FOO=BAR
in a shell and then running intellijj from the same shell
export will make the env var available to all processes forked from where you run the export
👍🏼 1
d
Copy code
S3_CONFIGS__ACCESS_TOKEN
doesn't work
Even though
System.getEnv()
returns it
I have this:
Copy code
val configs = ConfigLoaderBuilder.default().apply {
    addResourceSource("/application.yaml")
    val envs = listOf("local")
    envs.forEach {
        addResourceSource("/application-$it.yaml", optional = true)
    }
    addEnvironmentSource()
}.build().loadConfigOrThrow<Settings>()
And it just takes all my configs from
application.yaml
and
application-local.yaml
This:
Copy code
object MyUppercaseParamMapper : ParameterMapper {
  override fun map(param: KParameter, constructor: KFunction<Any>, kclass: KClass<*>): Set<String> =
    setOfNotNull(param.name?.fold("") { acc, c -> if (c.isUpperCase()) acc + "_" + c.uppercaseChar() else acc + c.uppercaseChar() })
}
Copy code
"s3Configs.accessToken".fold("") { acc, c -> if (c.isUpperCase()) acc + "_" + c.uppercaseChar() else acc + c.uppercaseChar() }
gives me:
Copy code
S3_CONFIGS.ACCESS_TOKEN
but it still doesn't work... do I also need to convert the
.
to
__
?
s
add EnvironmentVariablesPropertySource(true,true) explicitly rather than via addEnvironmentSource
d
Why should that help?
Copy code
fun ConfigLoaderBuilder.addEnvironmentSource(
  useUnderscoresAsSeparator: Boolean = true,
  allowUppercaseNames: Boolean = true,
) = addPropertySource(
  EnvironmentVariablesPropertySource(useUnderscoresAsSeparator, allowUppercaseNames)
)
with no params the default IS
true, true
Ok... my bad... I thought the sources had to be ordered from least priority to top priority like in Micronaut... but in Hoplite it's the opposite! For some reason, just addEnvironmentSource() works, even though I don't see how it adds the _ between where the capital letters are... it just uppercases everthing... (unless it's a combo of snake case + that...?). Thanks for all the help! As usual, you always answer our (sometimes stupid...) questions so warmly, and keep updating all your great libraries ❤️!
🎉 1