From c08bfadf99fc6de3c176a6a3f55cd0469c8a88dc Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Tue, 6 Jul 2021 09:40:29 -0400 Subject: [PATCH 1/4] `vault delete` should allow the same output options as `vault write`, as delete operations can similarly return data. --- command/delete.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/command/delete.go b/command/delete.go index b22a06df618c..78d786f11756 100644 --- a/command/delete.go +++ b/command/delete.go @@ -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) } From f753cc2372a8f310149172a1eeb02dab878ff0ef Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Tue, 6 Jul 2021 09:43:10 -0400 Subject: [PATCH 2/4] Add CL. --- changelog/11992.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/11992.txt diff --git a/changelog/11992.txt b/changelog/11992.txt new file mode 100644 index 000000000000..6cb8b33f27be --- /dev/null +++ b/changelog/11992.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: vault delete should support the same output options (e.g. -format) as vault write. +``` From 3bda3b9e5d02c252c0f30b899f6607fdfb71c8ee Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Tue, 6 Jul 2021 09:59:10 -0400 Subject: [PATCH 3/4] Add kv delete. --- command/kv_delete.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/command/kv_delete.go b/command/kv_delete.go index 47d66b76917b..73583d171dc4 100644 --- a/command/kv_delete.go +++ b/command/kv_delete.go @@ -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) { From 88917d840bd44417183bea49d721fb2fe17369e5 Mon Sep 17 00:00:00 2001 From: Nick Cabatoff Date: Tue, 6 Jul 2021 10:01:57 -0400 Subject: [PATCH 4/4] Update CL. --- changelog/11992.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/11992.txt b/changelog/11992.txt index 6cb8b33f27be..c9b2c4749dd5 100644 --- a/changelog/11992.txt +++ b/changelog/11992.txt @@ -1,3 +1,3 @@ ```release-note:bug -cli: vault delete should support the same output options (e.g. -format) as vault write. +cli: vault delete and vault kv delete should support the same output options (e.g. -format) as vault write. ```