Skip to content

Commit

Permalink
fix: [BACKPORT 2.4] Unset REGISTRY_ prefixed env vars (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson committed Jun 5, 2023
1 parent f38365a commit ecff339
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/mindthegap/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package root
import (
"io"
"os"
"strings"

"github.com/spf13/cobra"

Expand All @@ -21,6 +22,24 @@ import (
func NewCommand(in io.Reader, out, errOut io.Writer) (*cobra.Command, output.Output) {
rootCmd, rootOpts := root.NewCommand(out, errOut)

originalPreRun := rootCmd.PersistentPreRunE
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
if err := originalPreRun(cmd, args); err != nil {
return err
}

for _, env := range os.Environ() {
envKey, _, _ := strings.Cut(env, "=")
if strings.HasPrefix(envKey, "REGISTRY_") {
if err := os.Unsetenv(envKey); err != nil {
return err
}
}
}

return nil
}

rootCmd.AddCommand(create.NewCommand(rootOpts.Output))
rootCmd.AddCommand(push.NewCommand(rootOpts.Output))
rootCmd.AddCommand(serve.NewCommand(rootOpts.Output))
Expand Down

0 comments on commit ecff339

Please sign in to comment.