0
0
mirror of https://github.com/thegeeklab/wp-opentofu.git synced 2024-11-22 10:40:39 +00:00

fix: apply no_log option only to sensitive commands (#4)

This commit is contained in:
Robert Kaussow 2024-02-06 10:41:11 +01:00 committed by GitHub
parent 88744f2ca2
commit 1a93881a53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 12 deletions

View File

@ -45,14 +45,14 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "no-log", Name: "no-log",
Usage: "suppress tofu command output", Usage: "suppress tofu command output for `plan`, `apply` and `destroy` action",
EnvVars: []string{"PLUGIN_NO_LOG"}, EnvVars: []string{"PLUGIN_NO_LOG"},
Destination: &settings.NoLog, Destination: &settings.NoLog,
Category: category, Category: category,
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "targets", Name: "targets",
Usage: "targets to run `apply` or `plan` action on", Usage: "targets to run `plan` or `apply` action on",
EnvVars: []string{"PLUGIN_TARGETS"}, EnvVars: []string{"PLUGIN_TARGETS"},
Destination: &settings.Targets, Destination: &settings.Targets,
Category: category, Category: category,

View File

@ -21,7 +21,7 @@ properties:
- name: no_log - name: no_log
description: | description: |
Suppress tofu command output. Suppress tofu command output for `plan`, `apply` and `destroy` action.
type: bool type: bool
defaultValue: false defaultValue: false
required: false required: false
@ -48,7 +48,7 @@ properties:
- name: targets - name: targets
description: | description: |
Targets to run `apply` or `plan` action on. Targets to run `plan` or `apply` action on.
type: list type: list
required: false required: false

View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/thegeeklab/wp-plugin-go/trace"
"golang.org/x/sys/execabs" "golang.org/x/sys/execabs"
) )
@ -99,10 +98,6 @@ func (p *Plugin) Execute() error {
cmd.Env = os.Environ() cmd.Env = os.Environ()
if !p.Settings.NoLog {
trace.Cmd(cmd)
}
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
return err return err
} }

View File

@ -3,6 +3,7 @@ package plugin
import ( import (
"fmt" "fmt"
"github.com/thegeeklab/wp-plugin-go/trace"
"golang.org/x/sys/execabs" "golang.org/x/sys/execabs"
) )
@ -111,10 +112,16 @@ func (p *Plugin) planCommand(destroy bool) *execabs.Cmd {
args = append(args, "-refresh=false") args = append(args, "-refresh=false")
} }
return execabs.Command( cmd := execabs.Command(
tofuBin, tofuBin,
args..., args...,
) )
if !p.Settings.NoLog {
trace.Cmd(cmd)
}
return cmd
} }
func (p *Plugin) applyCommand() *execabs.Cmd { func (p *Plugin) applyCommand() *execabs.Cmd {
@ -144,10 +151,16 @@ func (p *Plugin) applyCommand() *execabs.Cmd {
args = append(args, p.Settings.OutFile) args = append(args, p.Settings.OutFile)
return execabs.Command( cmd := execabs.Command(
tofuBin, tofuBin,
args..., args...,
) )
if !p.Settings.NoLog {
trace.Cmd(cmd)
}
return cmd
} }
func (p *Plugin) destroyCommand() *execabs.Cmd { func (p *Plugin) destroyCommand() *execabs.Cmd {
@ -173,8 +186,14 @@ func (p *Plugin) destroyCommand() *execabs.Cmd {
args = append(args, "-auto-approve") args = append(args, "-auto-approve")
return execabs.Command( cmd := execabs.Command(
tofuBin, tofuBin,
args..., args...,
) )
if !p.Settings.NoLog {
trace.Cmd(cmd)
}
return cmd
} }