config-rs icon indicating copy to clipboard operation
config-rs copied to clipboard

Enable placeholders on configuration files

Open FaveroFerreira opened this issue 2 years ago • 4 comments

Feature description

Ability to declare placeholder values in our configuration files that will be taken from the environment variables.

Use Case

Sometimes we do not decide how our environment variables will be named, so we don't get to define them with prefixes like APP__

It would be nice if we could declare placeholders in our configuration files where the values should be taken from our environment variables.

Example:

application_port: ${PORT} #value taken from PORT environment variable
database:
  host: "127.0.0.1"
  port: 5432
  username: "postgres"
  password: "${DB_PASS}" #value taken from DB_PASS environment variable
  database_name: "${DB_HOST}" #value taken from DB_HOST environment variable
  require_ssl: false

FaveroFerreira avatar Jun 07 '22 02:06 FaveroFerreira

Sounds like something for the "re-thinking" ideas list, thus I added it to the project. I guess we could add (optional) support for templating engines, which would easily resolve this feature request. Adding own logic that does such replacements would be overkill and out of scope for this crate, IMO, but I like the idea of exposing enough interfaces so that a user can easily add templating to the loading/parsing logic of config-rs!

matthiasbeyer avatar Jun 19 '22 15:06 matthiasbeyer

Nice to hear that!

Comming from an Java + Spring background, maybe I am kinda biased towards using placeholders the way I pointed out on the issue description.

Just out of curiosity, do you have a different approach in mind? Maybe I can try and implement it.

FaveroFerreira avatar Jun 25 '22 01:06 FaveroFerreira

I do not yet have anything specific in mind, no. If you like to experiment (emphasis on "experiment"), have a look at the rethinking issues. There's a branch linked somewhere where I am exploring my ideas.

matthiasbeyer avatar Jun 25 '22 10:06 matthiasbeyer