Skip to content

Commit

Permalink
fix: apply no_log option only to sensitive commands (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored Feb 6, 2024
1 parent 88744f2 commit 1a93881
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/wp-opentofu/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions docs/data/data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 0 additions & 5 deletions plugin/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"os"

"github.com/thegeeklab/wp-plugin-go/trace"
"golang.org/x/sys/execabs"
)

Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 22 additions & 3 deletions plugin/tofu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plugin
import (
"fmt"

"github.com/thegeeklab/wp-plugin-go/trace"
"golang.org/x/sys/execabs"
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

0 comments on commit 1a93881

Please sign in to comment.