From a706a38cb94f05e994a9754698960219682d1fdc Mon Sep 17 00:00:00 2001 From: Vishal Nayak Date: Thu, 9 Apr 2020 06:42:18 -0400 Subject: [PATCH 1/2] Support unwrapping tokens that does not contain data --- command/unwrap.go | 6 ++++-- vault/logical_system.go | 15 ++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/command/unwrap.go b/command/unwrap.go index dbb8b46d17a9c..c5c02284b65d2 100644 --- a/command/unwrap.go +++ b/command/unwrap.go @@ -89,8 +89,10 @@ func (c *UnwrapCommand) Run(args []string) int { return 2 } if secret == nil { - c.UI.Error("Could not find wrapped response") - return 2 + if Format(c.UI) == "table" { + c.UI.Info("Successfully unwrapped. There was no data in the wrapped token.") + } + return 0 } // Handle single field output diff --git a/vault/logical_system.go b/vault/logical_system.go index fc58ec6d84340..e98dfae91f94d 100644 --- a/vault/logical_system.go +++ b/vault/logical_system.go @@ -2404,6 +2404,11 @@ func (b *SystemBackend) handleWrappingUnwrap(ctx context.Context, req *logical.R Data: map[string]interface{}{}, } + if len(response) == 0 { + resp.Data[logical.HTTPStatusCode] = 204 + return resp, nil + } + // Most of the time we want to just send over the marshalled HTTP bytes. // However there is a sad separate case: if the original response was using // bare values we need to use those or else what comes back is garbled. @@ -2449,13 +2454,9 @@ func (b *SystemBackend) handleWrappingUnwrap(ctx context.Context, req *logical.R return resp, nil } - if len(response) == 0 { - resp.Data[logical.HTTPStatusCode] = 204 - } else { - resp.Data[logical.HTTPStatusCode] = 200 - resp.Data[logical.HTTPRawBody] = []byte(response) - resp.Data[logical.HTTPContentType] = "application/json" - } + resp.Data[logical.HTTPStatusCode] = 200 + resp.Data[logical.HTTPRawBody] = []byte(response) + resp.Data[logical.HTTPContentType] = "application/json" return resp, nil } From 4482571ae1ae8440bc11a4996d6cf96fcd321dcf Mon Sep 17 00:00:00 2001 From: Vishal Nayak Date: Thu, 9 Apr 2020 09:54:34 -0400 Subject: [PATCH 2/2] s/token/secret --- command/unwrap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/unwrap.go b/command/unwrap.go index c5c02284b65d2..62184e6b7155c 100644 --- a/command/unwrap.go +++ b/command/unwrap.go @@ -90,7 +90,7 @@ func (c *UnwrapCommand) Run(args []string) int { } if secret == nil { if Format(c.UI) == "table" { - c.UI.Info("Successfully unwrapped. There was no data in the wrapped token.") + c.UI.Info("Successfully unwrapped. There was no data in the wrapped secret.") } return 0 }