Repository navigation
config: substitute with Hoplite's resolvers, not preprocessors - #74
Open
rocketraman wants to merge 1 commit into
Open
rocketraman wants to merge 1 commit into
rocketraman wants to merge 1 commit into
Conversation
Hoplite has deprecated preprocessors in favour of resolvers since
2023. Resolvers resolve a value only when it is bound, so `${...}` in
exported shell variables such as PS1 no longer fails loading, and the
isKnownNonConfigEnvVar filter is removed.
- `${{ env:name }}` reads the environment that hopliteConfigBinder's
environmentVariables supplies, rather than System.getenv as
Hoplite's EnvVarContextResolver does.
- Test resolvers, HOCON's own substitutions, and pin down that
resolvers leave `${{ ... }}` in map values unresolved.
- Document the syntax change and its gaps in the CHANGELOG and the
module README.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hopliteConfigBindersubstituted config values with Hoplite's preprocessors, which Hoplite has deprecated in favour of resolvers since 2023, and which its maintainer has confirmed are the intended default. Preprocessors expand${...}across the whole loaded tree and then fail on any that's left, so an exported shell variable such asPS1broke loading (sksamuel/hoplite#602), which Bootable worked around by filtering such variables out of the environment source.Resolvers resolve a value only when it's bound, so the filter is no longer needed.
Changes
hopliteConfigBinderadds Hoplite's default resolvers instead of its default preprocessors.${{ env:name }}reads the environment thathopliteConfigBinder'senvironmentVariablessupplies, as the environment variables source does, rather thanSystem.getenvas Hoplite's ownEnvVarContextResolverdoes.isKnownNonConfigEnvVarand its environment filter are removed.withConfigStageNhooks.addResolverused to throw, because Bootable had added preprocessors.Breaking: config substitution syntax
The syntax changes from
${VAR}/{{key}}to${{ env:VAR }},${{ env:VAR:-default }},${{ sysprop:name }},${{ ref:key }}, and${{ random:int }}. The old syntax isn't an error: it's left in the value as literal text. That includes${VAR}inside a quoted HOCON string, which preprocessors used to expand.HOCON's own substitutions (unquoted
${VAR},${?VAR},${a.b}) are unaffected, since HOCON resolves them when it parses the file. They're the recommended way to reference environment variables.See the "Config substitutions use Hoplite's resolvers" section of
CHANGELOG.adocunder 3.1.0 for the full mapping table and migration notes. Bootable's own.conffiles use no substitutions, so nothing in the repo needed migrating.Known gaps
${{ ... }}inside a map, list, or set (dataSourceProperties, Flyway'splaceholders/locations/schemas, telemetry'sotlp.headers/resourceAttributes) is left as literal text; use HOCON's${?VAR}there.${ssm:key}/paramstore://. Module prefixes change too:awssm://becomesaws-secrets-manager://,azurekeyvault://becomesazure-key-vault://, andgcpsm://becomesgcp-secrets-manager://.:-fallback.${{ env:DB_HOST }}), not the value it resolves to.Docs
boot-config-hoplite/README.adochas a new Substitutions section.README.adoc's Hoplite section points to it.Tests
HopliteConfigBinderTestcovers:PS1andBASH_FUNC_ml%%with${...}in their values don't fail binding (the gh-602 case).${{ env:X }}resolves into a string field, anIntfield, and aMaskedfield. Unset, it fails the bind, and with:-fallbackit gives the fallback.${{ ref:key }}resolves.${X}in a quoted string is left as literal text.${a.b},${PATH}, and${?UNSET}resolve, in strings and in aMap<String, String>.${{ env:X }}in a map value is passed through literally. The test fails if Hoplite starts resolving it.Put back on preprocessors, 6 of the new tests fail.
./gradlew testpasses across the build, including the MySQL and PostgreSQL Testcontainers suites.