jjmark15 / quiz-app

MIT License
0 stars 0 forks source link

Allow config values to be set from system environment values #48

Closed jjmark15 closed 4 years ago

jjmark15 commented 4 years ago

Background

Currently all config values are defined in yaml config files. Therefore, all these values are in plaintext in version control. This would be inappropriate for sensitive values such as api secret keys which need to remain hidden.

Requirements

Add the ability to fill config values from specified environment variables.

TBD

Describe the solution you'd like

yaml configs should dictate the name of the environment variable to read from in the format:

field: ${SECRET_ENV_VAR}

Then, in code we could have a type:

#[derive(Debug, serde::Deserialize)]
pub(crate) struct EnvironmentReadValue<T: serde::de::DeserializeOwned> {
    #[serde(flatten)]
    environment_variable_string: String,
    #[serde(skip)]
    value: Option<T>,
}

EnvironmentReadValue should be able to deserialize from a string such as "${SECRET_ENV_VAR}" and then return it's value of type T.

ToDos

jjmark15 commented 4 years ago

https://serde.rs/string-or-struct.html may be useful