mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 11:38:02 +00:00
Update path-help command
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/posener/complete"
|
"github.com/posener/complete"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ensure we are implementing the right interfaces.
|
|
||||||
var _ cli.Command = (*PathHelpCommand)(nil)
|
var _ cli.Command = (*PathHelpCommand)(nil)
|
||||||
var _ cli.CommandAutocomplete = (*PathHelpCommand)(nil)
|
var _ cli.CommandAutocomplete = (*PathHelpCommand)(nil)
|
||||||
|
|
||||||
@@ -16,37 +15,34 @@ var pathHelpVaultSealedMessage = strings.TrimSpace(`
|
|||||||
Error: Vault is sealed.
|
Error: Vault is sealed.
|
||||||
|
|
||||||
The "path-help" command requires the Vault to be unsealed so that the mount
|
The "path-help" command requires the Vault to be unsealed so that the mount
|
||||||
points of the secret backends are known.
|
points of the secret engines are known.
|
||||||
`)
|
`)
|
||||||
|
|
||||||
// PathHelpCommand is a Command that lists the mounts.
|
|
||||||
type PathHelpCommand struct {
|
type PathHelpCommand struct {
|
||||||
*BaseCommand
|
*BaseCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PathHelpCommand) Synopsis() string {
|
func (c *PathHelpCommand) Synopsis() string {
|
||||||
return "Retrieves API help for paths"
|
return "Retrieve API help for paths"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *PathHelpCommand) Help() string {
|
func (c *PathHelpCommand) Help() string {
|
||||||
helpText := `
|
helpText := `
|
||||||
Usage: vault path-help [options] path
|
Usage: vault path-help [options] PATH
|
||||||
|
|
||||||
Retrieves API help for paths. All endpoints in Vault provide built-in help
|
Retrieves API help for paths. All endpoints in Vault provide built-in help
|
||||||
in markdown format. This includes system paths, secret paths, and credential
|
in markdown format. This includes system paths, secret engines, and auth
|
||||||
providers.
|
methods.
|
||||||
|
|
||||||
A backend must be mounted before help is available:
|
Get help for the thing mounted at database/:
|
||||||
|
|
||||||
$ vault mount database
|
|
||||||
$ vault path-help database/
|
$ vault path-help database/
|
||||||
|
|
||||||
The response object will return additional paths to retrieve help:
|
The response object will return additional paths to retrieve help:
|
||||||
|
|
||||||
$ vault path-help database/roles/
|
$ vault path-help database/roles/
|
||||||
|
|
||||||
Each backend produces different help output. For additional information,
|
Each secret engine produces different help output.
|
||||||
please view the online documentation.
|
|
||||||
|
|
||||||
` + c.Flags().Help()
|
` + c.Flags().Help()
|
||||||
|
|
||||||
@@ -74,13 +70,11 @@ func (c *PathHelpCommand) Run(args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
args = f.Args()
|
args = f.Args()
|
||||||
path, kvs, err := extractPath(args)
|
switch {
|
||||||
if err != nil {
|
case len(args) < 1:
|
||||||
c.UI.Error(err.Error())
|
c.UI.Error(fmt.Sprintf("Not enough arguments (expected 1, got %d)", len(args)))
|
||||||
return 1
|
return 1
|
||||||
}
|
case len(args) > 1:
|
||||||
|
|
||||||
if len(kvs) > 0 {
|
|
||||||
c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args)))
|
c.UI.Error(fmt.Sprintf("Too many arguments (expected 1, got %d)", len(args)))
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@@ -91,6 +85,8 @@ func (c *PathHelpCommand) Run(args []string) int {
|
|||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path := sanitizePath(args[0])
|
||||||
|
|
||||||
help, err := client.Help(path)
|
help, err := client.Help(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "Vault is sealed") {
|
if strings.Contains(err.Error(), "Vault is sealed") {
|
||||||
|
|||||||
@@ -28,15 +28,15 @@ func TestPathHelpCommand_Run(t *testing.T) {
|
|||||||
code int
|
code int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"empty",
|
"not_enough_args",
|
||||||
nil,
|
[]string{},
|
||||||
"Missing PATH!",
|
"Not enough arguments",
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"slash",
|
"too_many_args",
|
||||||
[]string{"/"},
|
[]string{"foo", "bar"},
|
||||||
"Missing PATH!",
|
"Too many arguments",
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user