mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 12:07:54 +00:00
Update delete command
This commit is contained in:
@@ -8,17 +8,15 @@ import (
|
|||||||
"github.com/posener/complete"
|
"github.com/posener/complete"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ensure we are implementing the right interfaces.
|
|
||||||
var _ cli.Command = (*DeleteCommand)(nil)
|
var _ cli.Command = (*DeleteCommand)(nil)
|
||||||
var _ cli.CommandAutocomplete = (*DeleteCommand)(nil)
|
var _ cli.CommandAutocomplete = (*DeleteCommand)(nil)
|
||||||
|
|
||||||
// DeleteCommand is a Command that puts data into the Vault.
|
|
||||||
type DeleteCommand struct {
|
type DeleteCommand struct {
|
||||||
*BaseCommand
|
*BaseCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *DeleteCommand) Synopsis() string {
|
func (c *DeleteCommand) Synopsis() string {
|
||||||
return "Deletes secrets and configuration"
|
return "Delete secrets and configuration"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *DeleteCommand) Help() string {
|
func (c *DeleteCommand) Help() string {
|
||||||
@@ -69,13 +67,11 @@ func (c *DeleteCommand) 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
|
||||||
}
|
}
|
||||||
@@ -86,6 +82,8 @@ func (c *DeleteCommand) Run(args []string) int {
|
|||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path := sanitizePath(args[0])
|
||||||
|
|
||||||
if _, err := client.Logical().Delete(path); err != nil {
|
if _, err := client.Logical().Delete(path); err != nil {
|
||||||
c.UI.Error(fmt.Sprintf("Error deleting %s: %s", path, err))
|
c.UI.Error(fmt.Sprintf("Error deleting %s: %s", path, err))
|
||||||
return 2
|
return 2
|
||||||
|
|||||||
@@ -28,15 +28,15 @@ func TestDeleteCommand_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