Skip to content
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

Add method GetStringEnv which will interpolate environmental variables #581

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

useafterfree
Copy link

This will interpolate values that look like ${HOME} and assign with $HOME from environment.

…ke environmental variables and return them;
@CLAassistant
Copy link

CLAassistant commented Oct 18, 2018

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ useafterfree
❌ Nathan Trujillo


Nathan Trujillo seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Add method `GetStringEnv` which will interpolate values which look li…
@andrewstuart
Copy link
Collaborator

andrewstuart commented Nov 6, 2018

Hey, thanks for the contribution!

I'm hesitant to bring in a feature like this, for a couple reasons.

  • It's quite specific to environment variables, compared to the rest of viper, which is concerned with aggregating and overlaying multiple configuration sources.
  • This could be easily achieved by simply wrapping with os.ExpandEnv, e.g. os.ExpandEnv(viper.GetString("foo")).

@useafterfree
Copy link
Author

useafterfree commented Nov 6, 2018

The README.md states that Viper supports:
reading from environment variables

Maybe that can read:
reading from specifically formatted unique environment variables

Since,

SECTION:
   CONFIG: '${AMI}'
OTHER_SECTION:
   CONFIG: '${AMI}'

will never work for just $AMI but $SECTION_CONFIG_AMI $OTHER_SECTION_CONFIG_AMI

If I use environment variables in several places in a file, I don't want to make new ones as
my expectation is Environmental variables are to be used as one -> many.

Why would that change if I use Viper?

@sagikazarmark
Copy link
Collaborator

How about some configuration that optionally turns on variable expansion (eg. calls `os.ExpandEnv) for environment variables?

Alternatively variable expansion could be an option for not just env vars, but all configurations.

@astockwell
Copy link

I would like to second the request and add my usecase: configuring multiple environments with the same yaml/toml field structure, but needing different values:

[qa]
host = '${HOSTQA}'

[prod]
host = '${MAINLB}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants