`vault delete` should allow the same output options as `vault write`,… (#11992)

* `vault delete` and `vault kv delete` should allow the same output options as `vault write`, as delete operations can similarly return data.  This is needed if you want to use control groups with deletion.
This commit is contained in:
Nick Cabatoff 2021-07-06 16:36:07 +02:00 committed by GitHub
parent 1da8bb0a25
commit a2dcb131ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 7 deletions

3
changelog/11992.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
cli: vault delete and vault kv delete should support the same output options (e.g. -format) as vault write.
```

View File

@ -53,7 +53,7 @@ Usage: vault delete [options] PATH
}
func (c *DeleteCommand) Flags() *FlagSets {
return c.flagSet(FlagSetHTTP)
return c.flagSet(FlagSetHTTP | FlagSetOutputField | FlagSetOutputFormat)
}
func (c *DeleteCommand) AutocompleteArgs() complete.Predictor {
@ -95,7 +95,7 @@ func (c *DeleteCommand) Run(args []string) int {
data, err := parseArgsDataStringLists(stdin, args[1:])
if err != nil {
c.UI.Error(fmt.Sprintf("Failed to parse K=V data: %s", err))
c.UI.Error(fmt.Sprintf("Failed to parse string list data: %s", err))
return 1
}
@ -108,6 +108,18 @@ func (c *DeleteCommand) Run(args []string) int {
return 2
}
c.UI.Info(fmt.Sprintf("Success! Data deleted (if it existed) at: %s", path))
return 0
if secret == nil {
// Don't output anything unless using the "table" format
if Format(c.UI) == "table" {
c.UI.Info(fmt.Sprintf("Success! Data deleted (if it existed) at: %s", path))
}
return 0
}
// Handle single field output
if c.flagField != "" {
return PrintRawField(c.UI, secret, c.flagField)
}
return OutputSecret(c.UI, secret)
}

View File

@ -50,7 +50,7 @@ Usage: vault kv delete [options] PATH
}
func (c *KVDeleteCommand) Flags() *FlagSets {
set := c.flagSet(FlagSetHTTP)
set := c.flagSet(FlagSetHTTP | FlagSetOutputField | FlagSetOutputFormat)
// Common Options
f := set.NewFlagSet("Common Options")
@ -118,8 +118,19 @@ func (c *KVDeleteCommand) Run(args []string) int {
return 2
}
c.UI.Info(fmt.Sprintf("Success! Data deleted (if it existed) at: %s", path))
return 0
if secret == nil {
// Don't output anything unless using the "table" format
if Format(c.UI) == "table" {
c.UI.Info(fmt.Sprintf("Success! Data deleted (if it existed) at: %s", path))
}
return 0
}
if c.flagField != "" {
return PrintRawField(c.UI, secret, c.flagField)
}
return OutputSecret(c.UI, secret)
}
func (c *KVDeleteCommand) deleteV2(path, mountPath string, client *api.Client) (*api.Secret, error) {