mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 03:58:01 +00:00
command/path-help: rename command, better error if sealed. Fixes #234
This commit is contained in:
@@ -74,8 +74,8 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {
|
|||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
|
|
||||||
"help": func() (cli.Command, error) {
|
"path-help": func() (cli.Command, error) {
|
||||||
return &command.HelpCommand{
|
return &command.PathHelpCommand{
|
||||||
Meta: meta,
|
Meta: meta,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HelpCommand is a Command that lists the mounts.
|
// PathHelpCommand is a Command that lists the mounts.
|
||||||
type HelpCommand struct {
|
type PathHelpCommand struct {
|
||||||
Meta
|
Meta
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HelpCommand) Run(args []string) int {
|
func (c *PathHelpCommand) Run(args []string) int {
|
||||||
flags := c.Meta.FlagSet("help", FlagSetDefault)
|
flags := c.Meta.FlagSet("help", FlagSetDefault)
|
||||||
flags.Usage = func() { c.Ui.Error(c.Help()) }
|
flags.Usage = func() { c.Ui.Error(c.Help()) }
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
@@ -35,8 +35,15 @@ func (c *HelpCommand) Run(args []string) int {
|
|||||||
|
|
||||||
help, err := client.Help(path)
|
help, err := client.Help(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf(
|
if strings.Contains(err.Error(), "Vault is sealed") {
|
||||||
"Error reading help: %s", err))
|
c.Ui.Error(`Error: Vault is sealed.
|
||||||
|
|
||||||
|
The path-help command requires the Vault to be unsealed so that
|
||||||
|
mount points of secret backends are known.`)
|
||||||
|
} else {
|
||||||
|
c.Ui.Error(fmt.Sprintf(
|
||||||
|
"Error reading help: %s", err))
|
||||||
|
}
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,13 +51,13 @@ func (c *HelpCommand) Run(args []string) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HelpCommand) Synopsis() string {
|
func (c *PathHelpCommand) Synopsis() string {
|
||||||
return "Look up the help for a path"
|
return "Look up the help for a path"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HelpCommand) Help() string {
|
func (c *PathHelpCommand) Help() string {
|
||||||
helpText := `
|
helpText := `
|
||||||
Usage: vault help [options] path
|
Usage: vault path-help [options] path
|
||||||
|
|
||||||
Look up the help for a path.
|
Look up the help for a path.
|
||||||
|
|
||||||
@@ -58,6 +65,9 @@ Usage: vault help [options] path
|
|||||||
providers provide built-in help. This command looks up and outputs that
|
providers provide built-in help. This command looks up and outputs that
|
||||||
help.
|
help.
|
||||||
|
|
||||||
|
The command requires that the Vault be unsealed, because otherwise
|
||||||
|
the mount points of the backends are unknown.
|
||||||
|
|
||||||
General Options:
|
General Options:
|
||||||
|
|
||||||
-address=addr The address of the Vault server.
|
-address=addr The address of the Vault server.
|
||||||
@@ -14,7 +14,7 @@ func TestHelp(t *testing.T) {
|
|||||||
defer ln.Close()
|
defer ln.Close()
|
||||||
|
|
||||||
ui := new(cli.MockUi)
|
ui := new(cli.MockUi)
|
||||||
c := &HelpCommand{
|
c := &PathHelpCommand{
|
||||||
Meta: Meta{
|
Meta: Meta{
|
||||||
ClientToken: token,
|
ClientToken: token,
|
||||||
Ui: ui,
|
Ui: ui,
|
||||||
Reference in New Issue
Block a user