From 1a93881a53b9124a6cca873e8ec432727ac7a7d3 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Tue, 6 Feb 2024 10:41:11 +0100 Subject: [PATCH] fix: apply no_log option only to sensitive commands (#4) --- cmd/wp-opentofu/flags.go | 4 ++-- docs/data/data.yaml | 4 ++-- plugin/impl.go | 5 ----- plugin/tofu.go | 25 ++++++++++++++++++++++--- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/cmd/wp-opentofu/flags.go b/cmd/wp-opentofu/flags.go index 2ed8012..166d218 100644 --- a/cmd/wp-opentofu/flags.go +++ b/cmd/wp-opentofu/flags.go @@ -45,14 +45,14 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { }, &cli.BoolFlag{ Name: "no-log", - Usage: "suppress tofu command output", + Usage: "suppress tofu command output for `plan`, `apply` and `destroy` action", EnvVars: []string{"PLUGIN_NO_LOG"}, Destination: &settings.NoLog, Category: category, }, &cli.StringSliceFlag{ Name: "targets", - Usage: "targets to run `apply` or `plan` action on", + Usage: "targets to run `plan` or `apply` action on", EnvVars: []string{"PLUGIN_TARGETS"}, Destination: &settings.Targets, Category: category, diff --git a/docs/data/data.yaml b/docs/data/data.yaml index 499f339..d9f4b51 100644 --- a/docs/data/data.yaml +++ b/docs/data/data.yaml @@ -21,7 +21,7 @@ properties: - name: no_log description: | - Suppress tofu command output. + Suppress tofu command output for `plan`, `apply` and `destroy` action. type: bool defaultValue: false required: false @@ -48,7 +48,7 @@ properties: - name: targets description: | - Targets to run `apply` or `plan` action on. + Targets to run `plan` or `apply` action on. type: list required: false diff --git a/plugin/impl.go b/plugin/impl.go index 5766bae..5b40ecd 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -6,7 +6,6 @@ import ( "fmt" "os" - "github.com/thegeeklab/wp-plugin-go/trace" "golang.org/x/sys/execabs" ) @@ -99,10 +98,6 @@ func (p *Plugin) Execute() error { cmd.Env = os.Environ() - if !p.Settings.NoLog { - trace.Cmd(cmd) - } - if err := cmd.Run(); err != nil { return err } diff --git a/plugin/tofu.go b/plugin/tofu.go index f26846d..33fff8f 100644 --- a/plugin/tofu.go +++ b/plugin/tofu.go @@ -3,6 +3,7 @@ package plugin import ( "fmt" + "github.com/thegeeklab/wp-plugin-go/trace" "golang.org/x/sys/execabs" ) @@ -111,10 +112,16 @@ func (p *Plugin) planCommand(destroy bool) *execabs.Cmd { args = append(args, "-refresh=false") } - return execabs.Command( + cmd := execabs.Command( tofuBin, args..., ) + + if !p.Settings.NoLog { + trace.Cmd(cmd) + } + + return cmd } func (p *Plugin) applyCommand() *execabs.Cmd { @@ -144,10 +151,16 @@ func (p *Plugin) applyCommand() *execabs.Cmd { args = append(args, p.Settings.OutFile) - return execabs.Command( + cmd := execabs.Command( tofuBin, args..., ) + + if !p.Settings.NoLog { + trace.Cmd(cmd) + } + + return cmd } func (p *Plugin) destroyCommand() *execabs.Cmd { @@ -173,8 +186,14 @@ func (p *Plugin) destroyCommand() *execabs.Cmd { args = append(args, "-auto-approve") - return execabs.Command( + cmd := execabs.Command( tofuBin, args..., ) + + if !p.Settings.NoLog { + trace.Cmd(cmd) + } + + return cmd }