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
Allow ignoring specified environment variables #889
base: master
Are you sure you want to change the base?
Conversation
Add `[env] / ignore_keys` configuration to ignore the listed environment variables, in addition to the default ones. Fixes direnv#401
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not much of a Go programmer, so please guide me if horrible things were made. 🙂
@@ -139,6 +139,7 @@ func (rc *RC) Load(previousEnv Env) (newEnv Env, err error) { | |||
direnv := config.SelfPath | |||
newEnv = previousEnv.Copy() | |||
newEnv[DIRENV_WATCHES] = rc.times.Marshal() | |||
newEnv[DIRENV_IGNORE_KEYS] = strings.Join(config.EnvIgnoreKeys, ",") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing through environment variable avoids the need to read configuration file in at least direnv apply_dump
.
As a (wanted) side effect, it also adds appending to the list in .envrc
for example in some direnv_load ... direnv dump
scenarios. Although I think we can leave that undocumented if this still changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good overall, but I think we should only use the config unless there is a compelling argument.
if env[DIRENV_IGNORE_KEYS] != "" { | ||
config.EnvIgnoreKeys = strings.Split(env[DIRENV_IGNORE_KEYS], ",") | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config option is enough. Historically direnv was configured with env vars but that's more of an artefact now.
@@ -43,13 +49,15 @@ func NewEnvDiff() *EnvDiff { | |||
func BuildEnvDiff(e1, e2 Env) *EnvDiff { | |||
diff := NewEnvDiff() | |||
|
|||
ignoredKeys := NewIgnoredKeys(e2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's pass the IngoredKeys instance as a function argument so it can be passed from the config object instead.
//// IgnoredKeys | ||
|
||
// NewIgnoredKeys creates a NewIgnoredKeys including all keys to ignore | ||
func NewIgnoredKeys(env Env) *IgnoredKeys { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be derived from the config object instead.
Thanks for the review!
My use case was actually to dynamically ignore some environment variables (with known prefix) during the But after all, my use case for the whole feature faded away, so I'm totally fine with the config-only approach. But at the same time, let's see when I have the time and inspiration to make the requested changes. If someone wants to hijack the PR in the meanwhile, please feel free to. 🙂 |
Sounds good. I'm happy to keep the set of features small. So let's wait until somebody else is requesting for it :) (and motivated enough to finish the job) |
Add
[env] / ignore_keys
configuration to ignore the listed environment variables, in addition to the default ones.Fixes #401