mirror of
https://github.com/thegeeklab/wp-opentofu.git
synced 2024-11-21 04:10:39 +00:00
chore: migrate to wp-plugin-go v3 (#48)
This commit is contained in:
parent
5f8c89c973
commit
53be7b2f70
4
go.mod
4
go.mod
@ -6,9 +6,8 @@ require (
|
||||
github.com/Masterminds/semver/v3 v3.2.1
|
||||
github.com/rs/zerolog v1.32.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/thegeeklab/wp-plugin-go/v2 v2.3.1
|
||||
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2
|
||||
github.com/urfave/cli/v2 v2.27.2
|
||||
golang.org/x/sys v0.20.0
|
||||
)
|
||||
|
||||
require (
|
||||
@ -31,5 +30,6 @@ require (
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -47,8 +47,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/thegeeklab/wp-plugin-go/v2 v2.3.1 h1:ARwYgTPZ5iPsmOenmqcCf8TjiEe8wBOHKO7H/Xshe48=
|
||||
github.com/thegeeklab/wp-plugin-go/v2 v2.3.1/go.mod h1:0t8M8txtEFiaB6RqLX8vLrxkqAo5FT5Hx7dztN592D4=
|
||||
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2 h1:Mv5i8S1WY+BUNjTjX6lOnB3p8S9mvM+XwfY4R98gx0g=
|
||||
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2/go.mod h1:ij1iJcAVgzerBTqXnmq0bu1VA+hhVVwzXKqiqfoGjjg=
|
||||
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
|
||||
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/thegeeklab/wp-opentofu/plugin"
|
||||
"github.com/thegeeklab/wp-plugin-go/v2/docs"
|
||||
wp_template "github.com/thegeeklab/wp-plugin-go/v2/template"
|
||||
plugin_docs "github.com/thegeeklab/wp-plugin-go/v3/docs"
|
||||
plugin_template "github.com/thegeeklab/wp-plugin-go/v3/template"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -23,7 +23,7 @@ func main() {
|
||||
|
||||
p := plugin.New(nil)
|
||||
|
||||
out, err := wp_template.Render(context.Background(), client, tmpl, docs.GetTemplateData(p.App))
|
||||
out, err := plugin_template.Render(context.Background(), client, tmpl, plugin_docs.GetTemplateData(p.App))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/thegeeklab/wp-opentofu/tofu"
|
||||
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
||||
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -80,7 +80,7 @@ func (p *Plugin) Validate() error {
|
||||
|
||||
// Execute provides the implementation of the plugin.
|
||||
func (p *Plugin) Execute() error {
|
||||
batchCmd := make([]*types.Cmd, 0)
|
||||
batchCmd := make([]*plugin_exec.Cmd, 0)
|
||||
batchCmd = append(batchCmd, p.Settings.Tofu.Version())
|
||||
|
||||
if p.Settings.TofuVersion != "" {
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/wp-opentofu/tofu"
|
||||
wp "github.com/thegeeklab/wp-plugin-go/v2/plugin"
|
||||
plugin_base "github.com/thegeeklab/wp-plugin-go/v3/plugin"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
|
||||
// Plugin implements provide the plugin.
|
||||
type Plugin struct {
|
||||
*wp.Plugin
|
||||
*plugin_base.Plugin
|
||||
Settings *Settings
|
||||
}
|
||||
|
||||
@ -25,15 +25,15 @@ type Settings struct {
|
||||
Tofu tofu.Tofu
|
||||
}
|
||||
|
||||
func New(e wp.ExecuteFunc, build ...string) *Plugin {
|
||||
func New(e plugin_base.ExecuteFunc, build ...string) *Plugin {
|
||||
p := &Plugin{
|
||||
Settings: &Settings{},
|
||||
}
|
||||
|
||||
options := wp.Options{
|
||||
options := plugin_base.Options{
|
||||
Name: "wp-opentofu",
|
||||
Description: "Manage infrastructure with OpenTofu",
|
||||
Flags: Flags(p.Settings, wp.FlagsPluginCategory),
|
||||
Flags: Flags(p.Settings, plugin_base.FlagsPluginCategory),
|
||||
Execute: p.run,
|
||||
HideWoodpeckerFlags: true,
|
||||
}
|
||||
@ -50,7 +50,7 @@ func New(e wp.ExecuteFunc, build ...string) *Plugin {
|
||||
options.Execute = e
|
||||
}
|
||||
|
||||
p.Plugin = wp.New(options)
|
||||
p.Plugin = plugin_base.New(options)
|
||||
|
||||
return p
|
||||
}
|
||||
|
92
tofu/tofu.go
92
tofu/tofu.go
@ -2,10 +2,10 @@ package tofu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/thegeeklab/wp-plugin-go/v2/types"
|
||||
plugin_exec "github.com/thegeeklab/wp-plugin-go/v3/exec"
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/sys/execabs"
|
||||
)
|
||||
|
||||
const TofuBin = "/usr/local/bin/tofu"
|
||||
@ -36,14 +36,18 @@ type FmtOptions struct {
|
||||
Check *bool `json:"check"`
|
||||
}
|
||||
|
||||
func (t *Tofu) Version() *types.Cmd {
|
||||
return &types.Cmd{
|
||||
Cmd: execabs.Command(TofuBin, "version"),
|
||||
Private: t.NoLog,
|
||||
func (t *Tofu) Version() *plugin_exec.Cmd {
|
||||
cmd := plugin_exec.Command(TofuBin, "version")
|
||||
|
||||
if !t.NoLog {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (t *Tofu) Init() *types.Cmd {
|
||||
func (t *Tofu) Init() *plugin_exec.Cmd {
|
||||
args := []string{
|
||||
"init",
|
||||
}
|
||||
@ -55,24 +59,30 @@ func (t *Tofu) Init() *types.Cmd {
|
||||
// Fail tofu execution on prompt
|
||||
args = append(args, "-input=false")
|
||||
|
||||
return &types.Cmd{
|
||||
Cmd: execabs.Command(TofuBin, args...),
|
||||
}
|
||||
cmd := plugin_exec.Command(TofuBin, args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (t *Tofu) GetModules() *types.Cmd {
|
||||
return &types.Cmd{
|
||||
Cmd: execabs.Command(TofuBin, "get"),
|
||||
}
|
||||
func (t *Tofu) GetModules() *plugin_exec.Cmd {
|
||||
cmd := plugin_exec.Command(TofuBin, "get")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (t *Tofu) Validate() *types.Cmd {
|
||||
return &types.Cmd{
|
||||
Cmd: execabs.Command(TofuBin, "validate"),
|
||||
}
|
||||
func (t *Tofu) Validate() *plugin_exec.Cmd {
|
||||
cmd := plugin_exec.Command(TofuBin, "validate")
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (t *Tofu) Fmt() *types.Cmd {
|
||||
func (t *Tofu) Fmt() *plugin_exec.Cmd {
|
||||
args := []string{
|
||||
"fmt",
|
||||
}
|
||||
@ -93,12 +103,14 @@ func (t *Tofu) Fmt() *types.Cmd {
|
||||
args = append(args, fmt.Sprintf("-check=%t", *t.FmtOptions.Check))
|
||||
}
|
||||
|
||||
return &types.Cmd{
|
||||
Cmd: execabs.Command(TofuBin, args...),
|
||||
}
|
||||
cmd := plugin_exec.Command(TofuBin, args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (t *Tofu) Plan(destroy bool) *types.Cmd {
|
||||
func (t *Tofu) Plan(destroy bool) *plugin_exec.Cmd {
|
||||
args := []string{
|
||||
"plan",
|
||||
}
|
||||
@ -129,13 +141,17 @@ func (t *Tofu) Plan(destroy bool) *types.Cmd {
|
||||
args = append(args, "-refresh=false")
|
||||
}
|
||||
|
||||
return &types.Cmd{
|
||||
Cmd: execabs.Command(TofuBin, args...),
|
||||
Private: t.NoLog,
|
||||
cmd := plugin_exec.Command(TofuBin, args...)
|
||||
|
||||
if !t.NoLog {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (t *Tofu) Apply() *types.Cmd {
|
||||
func (t *Tofu) Apply() *plugin_exec.Cmd {
|
||||
args := []string{
|
||||
"apply",
|
||||
}
|
||||
@ -164,13 +180,17 @@ func (t *Tofu) Apply() *types.Cmd {
|
||||
args = append(args, t.OutFile)
|
||||
}
|
||||
|
||||
return &types.Cmd{
|
||||
Cmd: execabs.Command(TofuBin, args...),
|
||||
Private: t.NoLog,
|
||||
cmd := plugin_exec.Command(TofuBin, args...)
|
||||
|
||||
if !t.NoLog {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (t *Tofu) Destroy() *types.Cmd {
|
||||
func (t *Tofu) Destroy() *plugin_exec.Cmd {
|
||||
args := []string{
|
||||
"destroy",
|
||||
}
|
||||
@ -193,8 +213,12 @@ func (t *Tofu) Destroy() *types.Cmd {
|
||||
|
||||
args = append(args, "-auto-approve")
|
||||
|
||||
return &types.Cmd{
|
||||
Cmd: execabs.Command(TofuBin, args...),
|
||||
Private: t.NoLog,
|
||||
cmd := plugin_exec.Command(TofuBin, args...)
|
||||
|
||||
if !t.NoLog {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@ -449,7 +449,10 @@ func TestTofu_Apply(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.tofu.Apply()
|
||||
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
||||
assert.Equal(t, tt.tofu.NoLog, cmd.Private)
|
||||
|
||||
if tt.tofu.NoLog {
|
||||
assert.Equal(t, cmd.Stdout, nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -538,8 +541,12 @@ func TestTofu_Destroy(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.tofu.Destroy()
|
||||
|
||||
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
||||
assert.Equal(t, tt.tofu.NoLog, cmd.Private)
|
||||
|
||||
if tt.tofu.NoLog {
|
||||
assert.Equal(t, cmd.Stdout, nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user