sksamuel / hoplite

A boilerplate-free Kotlin config library for loading configuration files as data classes
Apache License 2.0
923 stars 74 forks source link

How Do I Correctly Add A Preprocessor? #408

Open aedenj opened 8 months ago

aedenj commented 8 months ago

With the line,

    ConfigLoaderBuilder.default().addPreprocessor(AwsSecretsManagerPreprocessor()

I've observed that the AwsSecretsManagerPreprocessor would run after the replacement preprocessor. However, my config looks like,

key = "awssm://services/my-service[api-key]",
secret = "awssm://services/my-service[api-secret]",

myConfigString = "myKey=${key} mySecret=${secret};"

And myConfigString doesn't contain the correct key and secret. Instead it contains the strings for key and secret. The only way around this I've found is to copy the contents of the .default() like this,

            return ConfigLoaderBuilder.empty()
                .addPreprocessor(AwsSecretsManagerPreprocessor())
                .addDefaultPreprocessors()
                .addDefaultDecoders()
                .addDefaultParsers()
                .addDefaultParamMappers()
                .addDefaultPropertySources()
                .addResourceSource("....")
                .build()
                .loadConfigOrThrow<MyConfig>()

This doesn't seem quite right. Is there a better way?

sksamuel commented 7 months ago

Any custom preprocessors will run after the replacement one. What you're doing is the way to define it. Or add the replacement one again after the AwsSecretsManagerPreprocessor