diff --git a/.goreleaser.yml b/.goreleaser.yml index de4a289..2ab3208 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -4,7 +4,6 @@ env: before: hooks: - - go mod tidy - ./scripts/manpages.sh - ./scripts/completions.sh @@ -38,8 +37,8 @@ nfpms: - vops vendor: FalcoSuessgott homepage: https://github.com/FalcoSuessgott/vops - maintainer: "Tom Morelly " - description: "recursively list secrets from Vaults KV2 engine in various formats" + maintainer: "Tom Morelly " + description: "a HashiCorp Vault cluster management tool" license: GPL-3.0 formats: - apk @@ -73,10 +72,9 @@ dockers: build_flag_templates: - "--pull" - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/FalcoSuessgott/vops/master/README.md" - - "--label=io.artifacthub.package.logo-url=https://raw.githubusercontent.com/FalcoSuessgott/vops/master/www/static/images/logo.png" - "--label=io.artifacthub.package.maintainers=[{\"name\":\"Tom Morelly\",\"email\":\"tommorelly@gmail.com\"}]" - "--label=io.artifacthub.package.license=MIT" - - "--label=org.opencontainers.image.description=the swiss army knife when working with Vault KVv2 engines" + - "--label=org.opencontainers.image.description=a HashiCorp Vault cluster management tool" - "--label=org.opencontainers.image.created={{.Date}}" - "--label=org.opencontainers.image.name={{.ProjectName}}" - "--label=org.opencontainers.image.revision={{.FullCommit}}" @@ -91,10 +89,9 @@ dockers: build_flag_templates: - "--pull" - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/FalcoSuessgott/vops/master/README.md" - - "--label=io.artifacthub.package.logo-url=https://raw.githubusercontent.com/FalcoSuessgott/vops/master/www/static/images/logo.png" - "--label=io.artifacthub.package.maintainers=[{\"name\":\"Tom Morelly\",\"email\":\"tommorelly@gmail.com\"}]" - "--label=io.artifacthub.package.license=MIT" - - "--label=org.opencontainers.image.description=the swiss army knife when working with Vault KVv2 engines" + - "--label=org.opencontainers.image.description=a HashiCorp Vault cluster management tool" - "--label=org.opencontainers.image.created={{.Date}}" - "--label=org.opencontainers.image.name={{.ProjectName}}" - "--label=org.opencontainers.image.revision={{.FullCommit}}" diff --git a/Makefile b/Makefile index 274c9be..d1fbb62 100644 --- a/Makefile +++ b/Makefile @@ -52,5 +52,5 @@ token: ## copies vault token in clipboard buffer .PHONY: clean clean: ## clean the development vault - @rm -rf coverage.out dist/ $(projectname) manpages/ dist/ completions/ assets/raft/* || true + @rm -rf snapshots/ coverage.out dist/ $(projectname) manpages/ dist/ completions/ assets/raft/* || true @kill -9 $(shell pgrep -x vault) 2> /dev/null || true diff --git a/cmd/config/config.go b/cmd/config/config.go index 45a01b7..a04eb5c 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -17,6 +17,9 @@ func NewConfigCmd(cfg string) *cobra.Command { Short: "config", SilenceUsage: true, SilenceErrors: true, + PreRunE: func(cmd *cobra.Command, args []string) error { + return config.ValidateConfig(cfg) + }, RunE: func(cmd *cobra.Command, args []string) error { return cmd.Help() }, diff --git a/cmd/generate_root/generate_root.go b/cmd/generate_root/generate_root.go index eb20a62..ad08f87 100644 --- a/cmd/generate_root/generate_root.go +++ b/cmd/generate_root/generate_root.go @@ -28,6 +28,9 @@ func NewGenerateRootCmd(cfg string) *cobra.Command { Short: "generates a new root token for a single or all cluster", SilenceUsage: true, SilenceErrors: true, + PreRunE: func(cmd *cobra.Command, args []string) error { + return config.ValidateConfig(cfg) + }, RunE: func(cmd *cobra.Command, args []string) error { fmt.Println("[ Generate Root Token ]") fmt.Printf("using %s\n", cfg) diff --git a/cmd/initialize/initialize.go b/cmd/initialize/initialize.go index 3833e60..102dde5 100644 --- a/cmd/initialize/initialize.go +++ b/cmd/initialize/initialize.go @@ -32,6 +32,9 @@ func NewInitCmd(cfg string) *cobra.Command { Short: "initialize a vault cluster", SilenceUsage: true, SilenceErrors: true, + PreRunE: func(cmd *cobra.Command, args []string) error { + return config.ValidateConfig(cfg) + }, RunE: func(cmd *cobra.Command, args []string) error { fmt.Println("[ Intialization ]") fmt.Printf("using %s\n", cfg) diff --git a/cmd/manpage/manpage.go b/cmd/manpage/manpage.go new file mode 100644 index 0000000..4ae629c --- /dev/null +++ b/cmd/manpage/manpage.go @@ -0,0 +1,43 @@ +package manpage + +import ( + "fmt" + "os" + + mcoral "github.com/muesli/mango-cobra" + "github.com/muesli/roff" + "github.com/spf13/cobra" +) + +// ManCmd manpage command. +type ManCmd struct { + Cmd *cobra.Command +} + +// NewManCmd manpage cmd. +func NewManCmd() *ManCmd { + root := &ManCmd{} + + c := &cobra.Command{ + Use: "man", + Short: "Generates GoReleaser's command line manpages", + SilenceUsage: true, + DisableFlagsInUseLine: true, + Hidden: true, + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + manPage, err := mcoral.NewManPage(1, root.Cmd.Root()) + if err != nil { + return err + } + + _, err = fmt.Fprint(os.Stdout, manPage.Build(roff.NewDocument())) + + return err + }, + } + + root.Cmd = c + + return root +} diff --git a/cmd/rekey/rekey.go b/cmd/rekey/rekey.go index e5632dd..b693e44 100644 --- a/cmd/rekey/rekey.go +++ b/cmd/rekey/rekey.go @@ -32,6 +32,9 @@ func NewRekeyCmd(cfg string) *cobra.Command { Short: "rekey a single or all vault cluster", SilenceUsage: true, SilenceErrors: true, + PreRunE: func(cmd *cobra.Command, args []string) error { + return config.ValidateConfig(cfg) + }, RunE: func(cmd *cobra.Command, args []string) error { fmt.Println("[ Rekeying ]") fmt.Printf("using %s\n", cfg) diff --git a/cmd/root.go b/cmd/root.go index d83112e..0b15dbd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,12 +8,12 @@ import ( "github.com/FalcoSuessgott/vops/cmd/config" "github.com/FalcoSuessgott/vops/cmd/generate_root" "github.com/FalcoSuessgott/vops/cmd/initialize" + "github.com/FalcoSuessgott/vops/cmd/manpage" "github.com/FalcoSuessgott/vops/cmd/rekey" "github.com/FalcoSuessgott/vops/cmd/seal" "github.com/FalcoSuessgott/vops/cmd/snapshot" "github.com/FalcoSuessgott/vops/cmd/unseal" "github.com/FalcoSuessgott/vops/cmd/version" - cfg "github.com/FalcoSuessgott/vops/pkg/config" "github.com/spf13/cobra" ) @@ -32,9 +32,6 @@ func NewRootCmd(v string, writer io.Writer) *cobra.Command { Short: "A HashiCorp Vault cluster operations tool", SilenceUsage: true, SilenceErrors: true, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - return cfg.ValidateConfig(cfgFile) - }, RunE: func(cmd *cobra.Command, args []string) error { return cmd.Help() }, @@ -53,6 +50,7 @@ func NewRootCmd(v string, writer io.Writer) *cobra.Command { config.NewConfigCmd(cfgFile), snapshot.NewSnapshotCmd(cfgFile), config.NewConfigCmd(cfgFile), + manpage.NewManCmd().Cmd, ) return cmd diff --git a/cmd/seal/seal.go b/cmd/seal/seal.go index ecc0de0..ef5b3f0 100644 --- a/cmd/seal/seal.go +++ b/cmd/seal/seal.go @@ -29,6 +29,9 @@ func NewSealCmd(cfg string) *cobra.Command { Short: "seals a single or all cluster", SilenceUsage: true, SilenceErrors: true, + PreRunE: func(cmd *cobra.Command, args []string) error { + return config.ValidateConfig(cfg) + }, RunE: func(cmd *cobra.Command, args []string) error { fmt.Println("[ Seal ]") fmt.Printf("using %s\n", cfg) diff --git a/cmd/snapshot/snapshot.go b/cmd/snapshot/snapshot.go index 86fcbb9..1314587 100644 --- a/cmd/snapshot/snapshot.go +++ b/cmd/snapshot/snapshot.go @@ -33,6 +33,9 @@ func NewSnapshotCmd(cfg string) *cobra.Command { Short: "creates or restorees a snapshot from a single or all vault cluster", SilenceUsage: true, SilenceErrors: true, + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + return config.ValidateConfig(cfg) + }, RunE: func(cmd *cobra.Command, args []string) error { return cmd.Help() }, diff --git a/cmd/unseal/unseal.go b/cmd/unseal/unseal.go index b702d31..ef1d00a 100644 --- a/cmd/unseal/unseal.go +++ b/cmd/unseal/unseal.go @@ -33,6 +33,9 @@ func NewUnsealCmd(cfg string) *cobra.Command { Short: "unseal a single node or a single cluster or all cluster", SilenceUsage: true, SilenceErrors: true, + PreRunE: func(cmd *cobra.Command, args []string) error { + return config.ValidateConfig(cfg) + }, RunE: func(cmd *cobra.Command, args []string) error { fmt.Println("[ Unseal ]") fmt.Printf("using %s\n", cfg) diff --git a/go.mod b/go.mod index 167fc50..c762110 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,8 @@ require ( github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/hashicorp/vault/api v1.9.0 github.com/hashicorp/vault/sdk v0.6.1-0.20221010215534-6545e24b6023 + github.com/muesli/mango-cobra v1.2.0 + github.com/muesli/roff v0.1.0 github.com/spf13/cobra v1.6.1 github.com/stretchr/testify v1.8.2-0.20221102114659-1333b5d3bda8 gopkg.in/yaml.v3 v3.0.1 @@ -34,6 +36,8 @@ require ( github.com/mattn/go-isatty v0.0.16 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/muesli/mango v0.1.0 // indirect + github.com/muesli/mango-pflag v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rogpeppe/go-internal v1.8.1 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect diff --git a/go.sum b/go.sum index a577017..85b2a1b 100644 --- a/go.sum +++ b/go.sum @@ -78,6 +78,14 @@ github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUb github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI= +github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4= +github.com/muesli/mango-cobra v1.2.0 h1:DQvjzAM0PMZr85Iv9LIMaYISpTOliMEg+uMFtNbYvWg= +github.com/muesli/mango-cobra v1.2.0/go.mod h1:vMJL54QytZAJhCT13LPVDfkvCUJ5/4jNUKF/8NC2UjA= +github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg= +github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0= +github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8= +github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= diff --git a/scripts/completions.sh b/scripts/completions.sh index 5818ad3..f6cb1ea 100755 --- a/scripts/completions.sh +++ b/scripts/completions.sh @@ -2,6 +2,7 @@ set -e rm -rf completions mkdir completions + for sh in bash zsh fish; do go run main.go completion "$sh" >"completions/vops.$sh" done \ No newline at end of file