Skip to content

Commit

Permalink
Support unwrapping tokens that does not contain data (#8714)
Browse files Browse the repository at this point in the history
* Support unwrapping tokens that does not contain data

* s/token/secret
  • Loading branch information
vishalnayak authored Apr 9, 2020
1 parent 8487cc7 commit 4ee817b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions command/unwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 secret.")
}
return 0
}

// Handle single field output
Expand Down
15 changes: 8 additions & 7 deletions vault/logical_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 4ee817b

Please sign in to comment.