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

Allow ignoring specified environment variables #889

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tmatilai
Copy link
Contributor

Add [env] / ignore_keys configuration to ignore the listed environment variables, in addition to the default ones.

Fixes #401

Add `[env] / ignore_keys` configuration to ignore the listed environment
variables, in addition to the default ones.

Fixes direnv#401
Copy link
Contributor Author

@tmatilai tmatilai left a 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, ",")
Copy link
Contributor Author

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.

Copy link
Member

@zimbatm zimbatm left a 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.

Comment on lines +129 to +131
if env[DIRENV_IGNORE_KEYS] != "" {
config.EnvIgnoreKeys = strings.Split(env[DIRENV_IGNORE_KEYS], ",")
} else {
Copy link
Member

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)
Copy link
Member

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 {
Copy link
Member

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.

@tmatilai
Copy link
Contributor Author

Thanks for the review!

I think we should only use the config unless there is a compelling argument.

My use case was actually to dynamically ignore some environment variables (with known prefix) during the .envrc evaluation, so the DIRENV_IGNORE_KEYS was handy.

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. 🙂

@zimbatm
Copy link
Member

zimbatm commented Apr 21, 2022

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)

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

Successfully merging this pull request may close these issues.

Feature: ability to specify a list of ignored environment variables
2 participants