Fallback to version 1 if the vault server is too old to have the kv preflight endpoint (#4445)
This commit is contained in:
parent
f61ea271d7
commit
817f816eb2
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue