davechallis / ocypod

Ocypod is a Redis-backed service for orchestrating background jobs. Clients/workers can be written in any language, using HTTP/JSON to queue/fetch jobs, store results, etc.
Apache License 2.0
193 stars 13 forks source link

Configuration Env Variable Interpolation #20

Closed lamoni closed 2 years ago

lamoni commented 3 years ago

Is it possible to add reading from environmental variables for the ocypod config TOML file? This would be particularly useful for the docker container, so one doesn't need to: templatize the TOML file -> "manually" interpolate the password -> save file -> add to docker container/image -> delete TOML file to protect sensitive information (or some other hacky variation of that).

This same concept can be found in Grafana's TOML configuration files using "${ENV_VAR_NAME_HERE}" syntax: https://grafana.com/docs/grafana/latest/auth/ldap/

Using environment variables
You can interpolate variables in the TOML configuration from environment variables. For instance, you could externalize your bind_password that way:

bind_password = "${LDAP_ADMIN_PASSWORD}"

Thanks!

davechallis commented 3 years ago

That would definitely be useful! I'll have a think about how to add it, I'm mostly considering whether to add them as overrides to the TOML config (which would also allow configuration to be done without a TOML config file at all), or whether (as you suggested) add them as interpolated values to a config file.

The former would be simpler, though a bit less flexible, and maybe not suitable for complex/nested fields.

The latter would be more flexible, but a bit more work to add (i.e. the template interpolation would have to be done before processing the file, instead of processing the file, then overwriting with any found environment variable values).