-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify if env variables should take precedence to config provided by param #110
Comments
Hi, thanks for the note. In my view, it really doesn't matter whether the config file is provided by a flag or loaded from some default location, the env variable settings should still take precedence over any config file. This is because env variables are often used for last-minute config overrides. Now, if the flag were |
Also, one pattern we use at my company with the |
A common pattern for the precedence cascade of configuration sources is to
(Larger number wins.) The rationale for this cascade is the ease of change or frequency of change for the source of the parameter. System files usually do not change, user files change as the user see fits but it would be inconvenient to edit a file before every single command run. Environment variables are usually set for a session and command line can change at every … line. There is however a lot of variations and the most important one that I have seen, is when the application should enforce administrators settings and should not allow the user to override the settings in the system files. (example: sudo) For a user tool, most users would be surprised if the cascade were not respected. Some tools (AWS CLI) also have a stage 0, where authorization parameters are pulled from the computational context. (the magic aws private IP) I once wrote a CLI library for OCaml (OCaml and Lisp are great languages!) implementing this cascade in parametrisable way, to have off-the shelf patterns: So, for Unix filters the cascade is to use the Environment and then CLI parameters. No configuration files for filters. A user tool follows the cascade above. https://github.com/foretspaisibles/gasoline/blob/master/application/gasoline_Plain_UserTool.ml#L28 But a secure tool has the cascade modified by pulling the system files at the strongest position of the list — https://github.com/foretspaisibles/gasoline/blob/master/application/gasoline_Plain_SecureTool.ml#L32 For a dæmon or a service the cascade is as above but there is no user configuration. https://github.com/foretspaisibles/gasoline/blob/master/application/gasoline_Plain_Daemon.ml#L73 |
If a config file is provided by param; should env variables take precedence? Env variables overriding discovered local or global config makes sense, but if config is passed in via param it is less clear.
config.yaml:
bash:
export CONFIG_FEATURE_ENABLED=true my-program --config config.yaml
In this case if I had an env variable set then it would invisibly override the config that I am passing in explicitly.
I can also see the opposite argument that env variables should always override config.
The text was updated successfully, but these errors were encountered: