Refactor environment variable handling into new Sources::EnvSource#299
Merged
cjlarose merged 5 commits intorubyconfig:masterfrom Feb 25, 2021
Merged
Refactor environment variable handling into new Sources::EnvSource#299cjlarose merged 5 commits intorubyconfig:masterfrom
cjlarose merged 5 commits intorubyconfig:masterfrom
Conversation
cjlarose
commented
Jan 13, 2021
| merge!(hash) | ||
| end | ||
|
|
||
| alias :load_env! :reload_env! |
Member
Author
There was a problem hiding this comment.
@pkuczynski Config::Options#load_env! and Config::Options#reload_env! are not documented at all, but are technically public methods.
As such, depending on whether or not we consider all visible methods to be part of the public API of this gem, this could be considered a breaking change and warrants a major version bump, so I added this under Breaking Changes in the changelog.
The change for users that use #load_env! or #reload_env! is simple: they should just replace those usages with #reload!, which is documented.
814a26f to
1750953
Compare
By default, EnvSource will use "global" settings specified like `Config.env_prefix`, `Config.env_separator`, `Config.env_separator`, and `Config.env_parse_values`. Those configurations will be used when parsing the ENV hash. But when using EnvSource to load settings from some unrelated flat string-keyed Hash source, we want to allow folks to override the settings.
Member
Author
|
@pkuczynski let me know if you have any concerns |
Member
Author
|
Ended up speaking to @pkuczynski about this in another channel. He's cool with merging and releasing. This change was released in 3.0.0. |
Closed
ippachi
pushed a commit
to ippachi/config-1
that referenced
this pull request
Oct 3, 2021
…ubyconfig#299) * Extract env var handling to new EnvSource class * Allow overriding settings for parsing env sources By default, EnvSource will use "global" settings specified like `Config.env_prefix`, `Config.env_separator`, `Config.env_separator`, and `Config.env_parse_values`. Those configurations will be used when parsing the ENV hash. But when using EnvSource to load settings from some unrelated flat string-keyed Hash source, we want to allow folks to override the settings. * Update CHANGELOG * Add AWS Secrets Manager usage to README
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In principle, loading settings from environment variables isn't much different from loading them from a
YAMLSourceor aHashSource. This change unifies the handling of environment variables into the existing "sources" abstraction.My own personal motivation for this change is essentially the same as #271. I want to load settings into
configthat I got from AWS Secrets Manager. Although AWS Secrets Manager's API technically allows you to store arbitrary string values, the AWS Console UI and the AWS Secrets Manager API encourages you to store your application's secret configuration as as single Secret resource that is a flat, JSON-encoded key-value mapping. This maps very nicely to how one might use environment variables to configure an application.Editing secrets in the AWS console
Actual plaintext
The problem is that while
configoffers the ability to parse nested settings fromENV, it doesn't allow you to do the same for settings you got from another source, like AWS Secrets Manager. As a result, users are forced into an awkward workaround: export all secrets from AWS Secrets Manager intoENV, then askconfigto load theENVagain. My proposedEnvSourceallows users to skip the loading-into-ENV step and just hand the flatHashover toconfigdirectly.For example,