This repository was archived by the owner on Oct 3, 2025. It is now read-only.
Allow overriding config settings from env vars using Viper#43
Open
farrago wants to merge 3 commits intoamborle:masterfrom
Open
Allow overriding config settings from env vars using Viper#43farrago wants to merge 3 commits intoamborle:masterfrom
farrago wants to merge 3 commits intoamborle:masterfrom
Conversation
This replaces the manual file loading and parsing with [viper](https://github.com/spf13/viper). In this commit, the functionality is identical, but using viper will allow additional configuration options in the future. # Tests - Test loading from existing conf.json works and loads correct values - Test missing file is correctly reported as an error - Test default value for SMTPPort works when it's not in the conf.json
This adds the ability to override config settings with an environment variable in the form "FEATMAP_<uppercase setting name>". e.g. `FEATMAP_PORT=8080` would override the `port` value in `conf.json`. Due to the way Viper works, this cannot load from *only* env vars, so the config file is still needed and the env vars can override it. See spf13/viper#584 To help protect users from this issue, this change also adds verification that essential config settings have been configured. # Tests - Test that configuration is still loaded from the config file - Test that environment variables override the values in the config file - Test that missing settings correctly report an error
Update to only check if any configuration is missing if conf.json was loaded. If it wasn't loaded, leave the failure to load as the reported error. # Tests - Test loading without `conf.json` and check the correct error is reported - Test loading with `conf.json` but missing some entries and check errors - Test loading with complete config and check it loads correctly
f1b1320 to
434b639
Compare
Owner
|
Thanks for submitting the PR! I really don't like that you need to have a configuration file even though all variables are supplied as envs. Found this: https://github.com/joho/godotenv. Any obvious downsides going with this instead? |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This initially replaces the manual conf.json file loading and parsing with viper. The same file is still loaded from the same location and fills the same configuration struct, so there are no backwards compatibility issues.
Using viper then adds the ability to override config settings with an environment variable in the form
"FEATMAP_<uppercase setting name>". e.g.FEATMAP_PORT=8080would override theportvalue inconf.json.Due to the way Viper works, this cannot load from only env vars, so the config file is still needed and the env vars can only override it. See spf13/viper#584
To help protect users from this issue, this change also adds verification that essential config settings have been configured.
Tests