diff --git a/.gitignore b/.gitignore index c3bd7b97..5c83a02e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .*.swp .*.swo mctl +*.json diff --git a/.golangci.yml b/.golangci.yml index e43d44b8..6adafc9a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,6 +6,7 @@ service: linters-settings: govet: auto-fix: true + shadow: true settings: printf: funcs: @@ -13,8 +14,6 @@ linters-settings: - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - revive: - min-confidence: 0 gocyclo: min-complexity: 15 dupl: @@ -62,9 +61,8 @@ linters: # additional linters - bodyclose - gocritic - - goerr113 + - err113 - goimports - - revive - misspell - noctx - stylecheck @@ -77,7 +75,6 @@ linters: - nilerr - reassign - whitespace - - exportloopref enable-all: false disable-all: true diff --git a/cmd/validate_firmware.go b/cmd/validate_firmware.go new file mode 100644 index 00000000..7d41b6b1 --- /dev/null +++ b/cmd/validate_firmware.go @@ -0,0 +1,65 @@ +package cmd + +import ( + "log" + + "github.com/google/uuid" + "github.com/metal-toolbox/conditionorc/pkg/api/v1/conditions/types" + "github.com/spf13/cobra" + + "github.com/metal-toolbox/mctl/internal/app" +) + +type validationFlags struct { + srvIDStr, fwSetIDStr, output string +} + +var ( + // incoming command line parameters + fwvFlags = &validationFlags{} +) + +var validateFirmwareCmd = &cobra.Command{ + Use: "validate-firmware", + Short: "validate a firmware set", + Run: func(c *cobra.Command, _ []string) { + theApp := MustCreateApp(c.Context()) + + client, err := app.NewConditionsClient(c.Context(), theApp.Config.Conditions, theApp.Reauth) + if err != nil { + log.Fatalf("creating app structure: %s", err.Error()) + } + + srvID, err := uuid.Parse(fwvFlags.srvIDStr) + if err != nil { + log.Fatalf("parsing server id: %s", err.Error()) + } + + fwSetID, err := uuid.Parse(fwvFlags.fwSetIDStr) + if err != nil { + log.Fatalf("parsing firmware set id: %s", err.Error()) + } + + fvr := &types.FirmwareValidationRequest{ + ServerID: srvID, + FirmwareSetID: fwSetID, + } + + resp, err := client.ValidateFirmwareSet(c.Context(), fvr) + if err != nil { + log.Fatalf("making validate firmware call: %s", err.Error()) + } + + PrintResults(fwvFlags.output, resp) + }, +} + +func init() { + RootCmd.AddCommand(validateFirmwareCmd) + + AddOutputFlag(validateFirmwareCmd, &fwvFlags.output) + AddFirmwareSetFlag(validateFirmwareCmd, &fwvFlags.fwSetIDStr) + AddServerFlag(validateFirmwareCmd, &fwvFlags.srvIDStr) + RequireFlag(validateFirmwareCmd, ServerFlag) + RequireFlag(validateFirmwareCmd, FirmwareSetFlag) +} diff --git a/docs/mctl.md b/docs/mctl.md index 1cec5504..3a1f1e8b 100644 --- a/docs/mctl.md +++ b/docs/mctl.md @@ -26,5 +26,6 @@ mctl is a CLI utility to interact with metal toolbox services * [mctl install](mctl_install.md) - Install actions * [mctl list](mctl_list.md) - List resources * [mctl power](mctl_power.md) - Execute server/bmc power, set next-boot commands: [on|off|cycle|reset|soft|status|bmc-reset|boot-pxe-persistent] +* [mctl validate-firmware](mctl_validate-firmware.md) - validate a firmware set * [mctl version](mctl_version.md) - Print mctl version diff --git a/docs/mctl_validate-firmware.md b/docs/mctl_validate-firmware.md new file mode 100644 index 00000000..6961fc0a --- /dev/null +++ b/docs/mctl_validate-firmware.md @@ -0,0 +1,30 @@ +[Auto generated by spf13/cobra]: <> + +## mctl validate-firmware + +validate a firmware set + +``` +mctl validate-firmware -s SERVER --set-id SETID [flags] +``` + +### Options + +``` + -h, --help help for validate-firmware + -o, --output outputType {json|text} (default json) + -s, --server string [required] ID of the server + --set-id string [required] ID of the firmware set +``` + +### Options inherited from parent commands + +``` + -c, --config string config file (default is $XDG_CONFIG_HOME/mctl/config.yml) + --reauth re-authenticate with oauth services +``` + +### SEE ALSO + +* [mctl](mctl.md) - mctl is a CLI utility to interact with metal toolbox services + diff --git a/go.mod b/go.mod index b030babb..5d59950b 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/dustin/go-humanize v1.0.1 github.com/google/uuid v1.6.0 github.com/metal-toolbox/bomservice v0.1.6 - github.com/metal-toolbox/conditionorc v1.1.11 + github.com/metal-toolbox/conditionorc v1.11.2 github.com/metal-toolbox/fleetdb v1.19.5 github.com/metal-toolbox/rivets v1.3.10 github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c @@ -30,7 +30,7 @@ require ( require ( github.com/KyleBanks/depth v1.2.1 // indirect - github.com/alessio/shellescape v1.4.1 // indirect + github.com/alessio/shellescape v1.4.2 // indirect github.com/banzaicloud/logrus-runtime-formatter v0.0.0-20190729070250-5ae5475bae5e // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bytedance/sonic v1.12.1 // indirect @@ -42,7 +42,7 @@ require ( github.com/cockroachdb/cockroach-go/v2 v2.3.8 // indirect github.com/coreos/go-oidc v2.2.1+incompatible // indirect github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect - github.com/danieljoos/wincred v1.2.0 // indirect + github.com/danieljoos/wincred v1.2.1 // indirect github.com/equinix-labs/otel-init-go v0.0.9 // indirect github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect @@ -158,7 +158,6 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect google.golang.org/grpc v1.65.0 // indirect google.golang.org/protobuf v1.34.2 // indirect - gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index b0e8386e..8772206b 100644 --- a/go.sum +++ b/go.sum @@ -90,8 +90,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= -github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= +github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0= +github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apmckinlay/gsuneido v0.0.0-20190404155041-0b6cd442a18f/go.mod h1:JU2DOj5Fc6rol0yaT79Csr47QR0vONGwJtBNGRD7jmc= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= @@ -156,8 +156,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lV github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= -github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= +github.com/danieljoos/wincred v1.2.1 h1:dl9cBrupW8+r5250DYkYxocLeZ1Y4vB1kxgtjxw8GQs= +github.com/danieljoos/wincred v1.2.1/go.mod h1:uGaFL9fDn3OLTvzCGulzE+SzjEe5NGlh5FdCcyfPwps= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= @@ -559,10 +559,10 @@ github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxU github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/metal-toolbox/bomservice v0.1.6 h1:pmb0HXk/js27DEsT697sJkdBneEhPse13nM7Bj97tOM= github.com/metal-toolbox/bomservice v0.1.6/go.mod h1:FaBgXqh5ad0bCxVJoUNYKQ1ABL/y1+844W9mZ/4Dfyw= -github.com/metal-toolbox/conditionorc v1.1.10 h1:7ypIknFu6QJ6xlF4i9URJMZiMtQZ/fc5CkYH7N2ZoaM= -github.com/metal-toolbox/conditionorc v1.1.10/go.mod h1:22nZqSkAp6WBUYApCRtNoVaWupOKqyxihZe7l66rMwk= github.com/metal-toolbox/conditionorc v1.1.11 h1:ukHCQvOJh+z4C3Y18VjXizxnlM1rPIqh9pbEFaoiKwQ= github.com/metal-toolbox/conditionorc v1.1.11/go.mod h1:COiaJSl8GOoIfpaSscTfCzAKjp2VDjCUjm5iw9KEm/E= +github.com/metal-toolbox/conditionorc v1.11.2 h1:92KeJ2oALrpL3T/6GeqW1CiBTh7BsgJxtJETDLHCJOc= +github.com/metal-toolbox/conditionorc v1.11.2/go.mod h1:COiaJSl8GOoIfpaSscTfCzAKjp2VDjCUjm5iw9KEm/E= github.com/metal-toolbox/fleetdb v1.19.5 h1:ERgdFAUtWnT/AeVhCGclsENmwPhU88JUcgOZAdxWKYI= github.com/metal-toolbox/fleetdb v1.19.5/go.mod h1:k9MZXQsJX4NfBoANst6g1468papSs0tzsSyzN3gGWuQ= github.com/metal-toolbox/rivets v1.3.10 h1:UgYQSx/QJF6Yuzf+YSRF/t9soL6QjMY8sLugf/aMmII=