fix(config): use underscores for config keys/env vars, hyphens for flags - #24
Merged
Conversation
A conflict in Viper naming schemas was causing a bug where a config file
using underscore-separated config keys (which is correct according to
the documentation) would get overridden by the default values, which use
hyphen-separated keys. This could be fixed by using hyphen-separated
keys in the config file, but this is neither idiomatic for YAML keys nor
consistent with the config documentation.
This is due to ambiguity in the way Viper config key aliases are used.
The config struct uses underscores for mapstructure tags and flags use
hyphens. Flags are aliased to config keys via
viper.RegisterAlias("config_key", "config-key"), but this causes the
unintentional side effect of hyphen-separated values being able to
override underscore-separated values in an ambiguous way, such as the
default values not being overridden by config file values.
The intended behavior is strictly that:
- CLI flags only use hyphen separation
- config file and environment variable keys use underscore separation
Therefore, this change removes the viper alias registration and adds a
bindFlagsWithUnderscoreKeys() helper that dynamically binds
hyphen-separated flags to underscore-separated config values. This
ensures the rules stated above.
Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
4 tasks
seantronsen
approved these changes
Jul 20, 2026
seantronsen
left a comment
There was a problem hiding this comment.
LGTM
Note
Reviewed code changes and tested by booting a compute vm. Had to change from --tokensmith_url to --tokensmith-url, though that was already expected.
[rocky@head boot-service.container.d]$ cat 10-override.conf
[Container]
Image=ghcr.io/openchami/boot-service:pr-24
Exec=serve --enable-legacy-api=false --enable-auth=true --tokensmith-url=http://tokensmith:8080 --hsm-url=http://smd:27779 --tokensmith-target-service smd --port 8081
Contributor
Author
|
@seantronsen Can you verify that a basic config file using underscores works? enable_legacy_api: false
enable_auth: true
tokensmith_url: http://tokensmith:8080
hsm_url: http://smd:27779
tokensmith_target_service: smd
port: 8081You can remove the entire |
Works. |
seantronsen
self-requested a review
July 20, 2026 20:41
seantronsen
approved these changes
Jul 20, 2026
seantronsen
left a comment
There was a problem hiding this comment.
Underscore config file tested successfully. Approved.
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.
Description
A conflict in Viper naming schemas was causing a bug where a config file
using underscore-separated config keys (which is correct according to
the documentation) would get overridden by the default values, which use
hyphen-separated keys. This could be fixed by using hyphen-separated
keys in the config file, but this is neither idiomatic for YAML keys nor
consistent with the config documentation.
This is due to ambiguity in the way Viper config key aliases are used.
The config struct uses underscores for mapstructure tags and flags use
hyphens. Flags are aliased to config keys via
viper.RegisterAlias("config_key", "config-key"), but this causes theunintentional side effect of hyphen-separated values being able to
override underscore-separated values in an ambiguous way, such as the
default values not being overridden by config file values.
The intended behavior is strictly that:
Therefore, this change removes the viper alias registration and adds a
bindFlagsWithUnderscoreKeys()helper that dynamically bindshyphen-separated flags to underscore-separated config values. This
ensures the rules stated above.
Implements OpenCHAMI/fabrica#75
Checklist
make test(or equivalent) locally and all tests passgit commit -s) with my real name and email<filename>.licensesidecarLICENSES/directoryType of Change
For more info, see Contributing Guidelines.