From 5f6823fe0b5ad8488a703f7d96f6ae418ccdd5bd Mon Sep 17 00:00:00 2001 From: "Luis (LT) Carbonell" Date: Tue, 29 Nov 2022 16:45:09 -0600 Subject: [PATCH 1/5] Skip formatting for a nil secret data --- command/kv_patch.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/command/kv_patch.go b/command/kv_patch.go index 3d0f3456c2b3..d05f8328f8ed 100644 --- a/command/kv_patch.go +++ b/command/kv_patch.go @@ -255,9 +255,11 @@ func (c *KVPatchCommand) Run(args []string) int { if Format(c.UI) == "table" { outputPath(c.UI, fullPath, "Secret Path") - metadata := secret.Data - c.UI.Info(getHeaderForMap("Metadata", metadata)) - return OutputData(c.UI, metadata) + if secret != nil { + metadata := secret.Data + c.UI.Info(getHeaderForMap("Metadata", metadata)) + return OutputData(c.UI, metadata) + } } return OutputSecret(c.UI, secret) From f5e743dde3e30cd5faaeef0c57947b8bdddaf3d6 Mon Sep 17 00:00:00 2001 From: "Luis (LT) Carbonell" Date: Wed, 30 Nov 2022 09:05:33 -0600 Subject: [PATCH 2/5] Same change for put --- command/kv_put.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/command/kv_put.go b/command/kv_put.go index 5cc7b6fbc67b..fd718993a282 100644 --- a/command/kv_put.go +++ b/command/kv_put.go @@ -218,9 +218,11 @@ func (c *KVPutCommand) Run(args []string) int { if Format(c.UI) == "table" { outputPath(c.UI, fullPath, "Secret Path") - metadata := secret.Data - c.UI.Info(getHeaderForMap("Metadata", metadata)) - return OutputData(c.UI, metadata) + if secret != nil { + metadata := secret.Data + c.UI.Info(getHeaderForMap("Metadata", metadata)) + return OutputData(c.UI, metadata) + } } return OutputSecret(c.UI, secret) From 411d7325abfe174e64a7d6ec0c65ab81a1d01ee7 Mon Sep 17 00:00:00 2001 From: "Luis (LT) Carbonell" Date: Wed, 30 Nov 2022 09:38:07 -0600 Subject: [PATCH 3/5] Add changelog --- changelog/18163.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/18163.txt diff --git a/changelog/18163.txt b/changelog/18163.txt new file mode 100644 index 000000000000..4f48d2ae6e3d --- /dev/null +++ b/changelog/18163.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli/kv: skip formatting of nil secrets +``` \ No newline at end of file From cbeead0fe705ee0fcd39e3a98f1702e6ff34028e Mon Sep 17 00:00:00 2001 From: "Luis (LT) Carbonell" Date: Wed, 30 Nov 2022 09:40:15 -0600 Subject: [PATCH 4/5] update changelog --- changelog/18163.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/18163.txt b/changelog/18163.txt index 4f48d2ae6e3d..f98c751bdd68 100644 --- a/changelog/18163.txt +++ b/changelog/18163.txt @@ -1,3 +1,3 @@ ```release-note:bug -cli/kv: skip formatting of nil secrets +cli/kv: skip formatting of nil secrets for patch and put with field parameter set ``` \ No newline at end of file From 85089f19a6cd9ec6fce99172876311ef31fb52e9 Mon Sep 17 00:00:00 2001 From: "Luis (LT) Carbonell" Date: Thu, 1 Dec 2022 09:43:16 -0600 Subject: [PATCH 5/5] modify filtered output --- command/kv_patch.go | 16 +++++++++++----- command/kv_put.go | 8 +++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/command/kv_patch.go b/command/kv_patch.go index d05f8328f8ed..8313ec33487c 100644 --- a/command/kv_patch.go +++ b/command/kv_patch.go @@ -252,14 +252,20 @@ func (c *KVPatchCommand) Run(args []string) int { if code != 0 { return code } + if secret == nil { + // Don't output anything if there's no secret + return 0 + } + + if c.flagField != "" { + return PrintRawField(c.UI, secret, c.flagField) + } if Format(c.UI) == "table" { outputPath(c.UI, fullPath, "Secret Path") - if secret != nil { - metadata := secret.Data - c.UI.Info(getHeaderForMap("Metadata", metadata)) - return OutputData(c.UI, metadata) - } + metadata := secret.Data + c.UI.Info(getHeaderForMap("Metadata", metadata)) + return OutputData(c.UI, metadata) } return OutputSecret(c.UI, secret) diff --git a/command/kv_put.go b/command/kv_put.go index fd718993a282..5cc7b6fbc67b 100644 --- a/command/kv_put.go +++ b/command/kv_put.go @@ -218,11 +218,9 @@ func (c *KVPutCommand) Run(args []string) int { if Format(c.UI) == "table" { outputPath(c.UI, fullPath, "Secret Path") - if secret != nil { - metadata := secret.Data - c.UI.Info(getHeaderForMap("Metadata", metadata)) - return OutputData(c.UI, metadata) - } + metadata := secret.Data + c.UI.Info(getHeaderForMap("Metadata", metadata)) + return OutputData(c.UI, metadata) } return OutputSecret(c.UI, secret)