diff --git a/command/kv_get.go b/command/kv_get.go index 80f272ddde25..fc7356f7b99e 100644 --- a/command/kv_get.go +++ b/command/kv_get.go @@ -116,6 +116,9 @@ func (c *KVGetCommand) Run(args []string) int { secret, err := kvReadRequest(client, path, versionParam) if err != nil { c.UI.Error(fmt.Sprintf("Error reading %s: %s", path, err)) + if secret != nil { + OutputSecret(c.UI, secret) + } return 2 } if secret == nil { @@ -142,6 +145,11 @@ func (c *KVGetCommand) Run(args []string) int { return OutputSecret(c.UI, secret) } + if len(secret.Warnings) > 0 { + tf := TableFormatter{} + tf.printWarnings(c.UI, secret) + } + if metadata, ok := secret.Data["metadata"]; ok && metadata != nil { c.UI.Info(getHeaderForMap("Metadata", metadata.(map[string]interface{}))) OutputData(c.UI, metadata) diff --git a/command/kv_helpers.go b/command/kv_helpers.go index dd8e41c7b759..b0e984783595 100644 --- a/command/kv_helpers.go +++ b/command/kv_helpers.go @@ -47,6 +47,12 @@ func kvPreflightVersionRequest(client *api.Client, path string) (string, int, er defer resp.Body.Close() } if err != nil { + // If we get a 404 we are using an older version of vault, default to + // version 1 + if resp != nil && resp.StatusCode == 404 { + return "", 1, nil + } + return "", 0, err } diff --git a/command/kv_put.go b/command/kv_put.go index a4524f9c8944..b4ba76aafa17 100644 --- a/command/kv_put.go +++ b/command/kv_put.go @@ -142,6 +142,9 @@ func (c *KVPutCommand) Run(args []string) int { secret, err := client.Logical().Write(path, data) if err != nil { c.UI.Error(fmt.Sprintf("Error writing data to %s: %s", path, err)) + if secret != nil { + OutputSecret(c.UI, secret) + } return 2 } if secret == nil {