From b3899d2ce9e5536bcbccadb64bd96636e5b605bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20N=C3=A4gele?= Date: Wed, 9 Sep 2020 21:26:06 +0200 Subject: [PATCH] Add flag for disabling config printing (#269) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, ct prints the config on startup. This can be problematic because it may contain senstivie data when helm-repo-extra-args contains passwords. The new flag enables turning off config printing and disables it by default. Signed-off-by: Reinhard Nägele --- ct/cmd/install.go | 6 +++++- ct/cmd/lint.go | 6 +++++- ct/cmd/root.go | 7 +++++-- pkg/config/config.go | 4 +--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ct/cmd/install.go b/ct/cmd/install.go index f9c5978..2396878 100644 --- a/ct/cmd/install.go +++ b/ct/cmd/install.go @@ -82,7 +82,11 @@ func addInstallFlags(flags *flag.FlagSet) { func install(cmd *cobra.Command, args []string) error { fmt.Println("Installing charts...") - configuration, err := config.LoadConfiguration(cfgFile, cmd, true) + printConfig, err := cmd.Flags().GetBool("print-config") + if err != nil { + return err + } + configuration, err := config.LoadConfiguration(cfgFile, cmd, printConfig) if err != nil { return fmt.Errorf("Error loading configuration: %s", err) } diff --git a/ct/cmd/lint.go b/ct/cmd/lint.go index b8828fe..cc32142 100644 --- a/ct/cmd/lint.go +++ b/ct/cmd/lint.go @@ -74,7 +74,11 @@ func addLintFlags(flags *flag.FlagSet) { func lint(cmd *cobra.Command, args []string) error { fmt.Println("Linting charts...") - configuration, err := config.LoadConfiguration(cfgFile, cmd, true) + printConfig, err := cmd.Flags().GetBool("print-config") + if err != nil { + return err + } + configuration, err := config.LoadConfiguration(cfgFile, cmd, printConfig) if err != nil { return fmt.Errorf("Error loading configuration: %s", err) } diff --git a/ct/cmd/root.go b/ct/cmd/root.go index 0de5331..bd9a3b5 100644 --- a/ct/cmd/root.go +++ b/ct/cmd/root.go @@ -92,6 +92,9 @@ func addCommonLintAndInstallFlags(flags *pflag.FlagSet) { (e.g. 'myrepo=--username test --password secret'). May be specified multiple times or separate values with commas`)) flags.Bool("debug", false, heredoc.Doc(` - Print CLI calls of external tools to stdout (Note: depending on helm-extra-args - passed, this may reveal sensitive data)`)) + Print CLI calls of external tools to stdout (caution: setting this may + expose sensitive data when helm-repo-extra-args contains passwords)`)) + flags.Bool("print-config", false, heredoc.Doc(` + Prints the configuration to stdout (caution: setting this may + expose sensitive data when helm-repo-extra-args contains passwords)`)) } diff --git a/pkg/config/config.go b/pkg/config/config.go index ae87c9a..59045f6 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -96,9 +96,7 @@ func LoadConfiguration(cfgFile string, cmd *cobra.Command, printConfig bool) (*C return nil, errors.Wrap(err, "Error loading config file") } } else { - if printConfig { - fmt.Println("Using config file: ", v.ConfigFileUsed()) - } + fmt.Println("Using config file:", v.ConfigFileUsed()) } isLint := strings.Contains(cmd.Use, "lint")