Skip to content

Commit e8d1f9c

Browse files
committed
PR comments
1 parent 1250946 commit e8d1f9c

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

pkg/config/config_helpers.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,24 +1362,22 @@ func sopsDecryptFileImpl(ctx context.Context, pctx *ParsingContext, l log.Logger
13621362
locks.EnvLock.Lock()
13631363
defer locks.EnvLock.Unlock()
13641364

1365-
// Set environment variables from the TerragruntOptions.Env map.
1366-
// This is especially useful for integrations with things like the `auth-provider` flag,
1367-
// which can set environment variables that are used for decryption.
1365+
// Save original process env values for keys we'll override, set opts.Env
1366+
// for SOPS auth, and restore originals on exit.
13681367
env := pctx.TerragruntOptions.Env
1368+
origEnv := make(map[string]string, len(env))
13691369

1370-
var setKeys []string
1370+
for k := range env {
1371+
origEnv[k] = os.Getenv(k)
1372+
}
13711373

13721374
for k, v := range env {
1373-
if os.Getenv(k) == "" {
1374-
os.Setenv(k, v) //nolint:errcheck
1375-
1376-
setKeys = append(setKeys, k)
1377-
}
1375+
os.Setenv(k, v) //nolint:errcheck
13781376
}
13791377

13801378
defer func() {
1381-
for _, k := range setKeys {
1382-
os.Unsetenv(k) //nolint:errcheck
1379+
for k, v := range origEnv {
1380+
os.Setenv(k, v) //nolint:errcheck
13831381
}
13841382
}()
13851383

0 commit comments

Comments
 (0)