Skip to content

Enable placeholders on configuration files #345

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

Open
Tracked by #376
FaveroFerreira opened this issue Jun 7, 2022 · 4 comments
Open
Tracked by #376

Enable placeholders on configuration files #345

FaveroFerreira opened this issue Jun 7, 2022 · 4 comments

Comments

@FaveroFerreira
Copy link

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
@matthiasbeyer
Copy link
Member

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!

@FaveroFerreira
Copy link
Author

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.

@matthiasbeyer
Copy link
Member

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 matthiasbeyer mentioned this issue Sep 17, 2022
15 tasks
@holmofy
Copy link

holmofy commented Jun 14, 2024

I also have a background in Java+Spring. Spring has a very good configuration mechanism.

https://docs.spring.io/spring-boot/how-to/properties-and-configuration.html

Recently, I saw that the Rust ecosystem has a loco.rs project, which also supports placeholder configuration.

The implementation of loco.rs is a good reference.

https://loco.rs/docs/getting-started/config/

@epage epage removed the re-think label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants