-
Notifications
You must be signed in to change notification settings - Fork 61
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
Allow setting configuration using environment variables #21
Comments
Yes, I think we can have it under a feature flag. However, it's unclear to me how that would interact with configuration coming from a config file. Should it be a separate |
You are right in pointing that question out. See e.g. clap-rs/clap#2763 for Clap's discussion about it. I would have said that the configs should be merged and one has preference (I'd say environment variables). I don't quiet get what the example What do you think? |
I feel hesitant about implicit merging of configuration - there are way too many ways how things can get wrong with it. I would rather not allow that conceptually as a practice. For my example: I meant that config file and configuration via env vars is mutually exclusive, you either start service with So, for separate field overrides via env variables - I believe we should not have this. Too many risks of things going wrong and it's extremely hard to debug such a setup. It's desirable for configuration to come from a single source that you can refer to in case of any trouble and observe the whole picture. |
Ah. I see. That's fine for me as well and easier as well.
I think I still did not make myself clear. Taking your input above in consideration, I propose the following. When the app is invoked as struct MySettings {
a: String,
b: String,
c: SubSettings
}
struct SubSettings {
a: String
} would be configured using the following environment variables.
|
So, argument provided with |
I think that sounds right. I would prefer if it would default to pick up an env var prefix (so it's possible to just start it as |
Would like to avoid implicit fallbacks, thus the option. sgtm, PRs are welcome |
fwiw .. mix of environment & config file is super important. In a majority of systems I frequently want a config file with 99.9% of the settings under version control, but often there is a use case for setting one or more exceptional variable using an environment .. (frequently containing a secret, or some type of localized dynamic content) .. this is absurdly common in k8s. .. the last thing I want is a need to generate a new config file with the dynamic content, then write it someplace, then run the program. You are correct in that is easy to get messy .. your best bet is to use a standardized mechanism for collapsing any config file path into environment variables. If environment variables are set then always have the environment variables win. Introduce a debug log level which indicates which (if any) config settings were overloaded by an environment variable (not necessarily with the value, which again might contain a secret) I'm super new to this and currently in evaluation stage, just looking at issues before I dive in. |
It would be great to allow setting (at least some) configuration using environment variables. This is established practice in many environments (see twelve factor apps, most containers).
This might be possible with
serde-env
. Would you consider a PR that implements it using serde-env?The text was updated successfully, but these errors were encountered: