Add in logic for handling a field of 'data' to kv get (#4895)

We do this for normal commands in PrintRawField but it needs some help
for KV v2.
This commit is contained in:
Jeff Mitchell 2018-07-11 15:50:26 -04:00 committed by GitHub
parent a1321d1d9c
commit 229dee1be0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -130,6 +130,16 @@ func (c *KVGetCommand) Run(args []string) int {
if v2 {
// This is a v2, pass in the data field
if data, ok := secret.Data["data"]; ok && data != nil {
// If they requested a literal "data" see if they meant actual
// value or the data block itself
if c.flagField == "data" {
if dataMap, ok := data.(map[string]interface{}); ok {
if _, ok := dataMap["data"]; ok {
return PrintRawField(c.UI, dataMap, c.flagField)
}
}
return PrintRawField(c.UI, secret, c.flagField)
}
return PrintRawField(c.UI, data, c.flagField)
} else {
c.UI.Error(fmt.Sprintf("No data found at %s", path))