mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 02:02:43 +00:00
Allow to output secrets in YAML format
This can be done with https://github.com/ghodss/yaml, which reuses existing JSON struct tags for YAML.
This commit is contained in:
@@ -5,7 +5,9 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/ghodss/yaml"
|
||||||
"github.com/hashicorp/vault/api"
|
"github.com/hashicorp/vault/api"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
"github.com/ryanuber/columnize"
|
"github.com/ryanuber/columnize"
|
||||||
@@ -15,6 +17,8 @@ func OutputSecret(ui cli.Ui, format string, secret *api.Secret) int {
|
|||||||
switch format {
|
switch format {
|
||||||
case "json":
|
case "json":
|
||||||
return outputFormatJSON(ui, secret)
|
return outputFormatJSON(ui, secret)
|
||||||
|
case "yaml":
|
||||||
|
return outputFormatYAML(ui, secret)
|
||||||
case "table":
|
case "table":
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
@@ -36,6 +40,18 @@ func outputFormatJSON(ui cli.Ui, s *api.Secret) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func outputFormatYAML(ui cli.Ui, s *api.Secret) int {
|
||||||
|
b, err := yaml.Marshal(s)
|
||||||
|
if err != nil {
|
||||||
|
ui.Error(fmt.Sprintf(
|
||||||
|
"Error formatting secret: %s", err))
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.Output(strings.TrimSpace(string(b)))
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func outputFormatTable(ui cli.Ui, s *api.Secret, whitespace bool) int {
|
func outputFormatTable(ui cli.Ui, s *api.Secret, whitespace bool) int {
|
||||||
config := columnize.DefaultConfig()
|
config := columnize.DefaultConfig()
|
||||||
config.Delim = "♨"
|
config.Delim = "♨"
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ General Options:
|
|||||||
Read Options:
|
Read Options:
|
||||||
|
|
||||||
-format=table The format for output. By default it is a whitespace-
|
-format=table The format for output. By default it is a whitespace-
|
||||||
delimited table. This can also be json.
|
delimited table. This can also be json or yaml.
|
||||||
|
|
||||||
-field=field If included, the raw value of the specified field
|
-field=field If included, the raw value of the specified field
|
||||||
will be output raw to stdout.
|
will be output raw to stdout.
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ General Options:
|
|||||||
Renew Options:
|
Renew Options:
|
||||||
|
|
||||||
-format=table The format for output. By default it is a whitespace-
|
-format=table The format for output. By default it is a whitespace-
|
||||||
delimited table. This can also be json.
|
delimited table. This can also be json or yaml.
|
||||||
`
|
`
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ Token Options:
|
|||||||
it is automatically revoked.
|
it is automatically revoked.
|
||||||
|
|
||||||
-format=table The format for output. By default it is a whitespace-
|
-format=table The format for output. By default it is a whitespace-
|
||||||
delimited table. This can also be json.
|
delimited table. This can also be json or yaml.
|
||||||
|
|
||||||
`
|
`
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ General Options:
|
|||||||
Token Renew Options:
|
Token Renew Options:
|
||||||
|
|
||||||
-format=table The format for output. By default it is a whitespace-
|
-format=table The format for output. By default it is a whitespace-
|
||||||
delimited table. This can also be json.
|
delimited table. This can also be json or yaml.
|
||||||
|
|
||||||
`
|
`
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
|
|||||||
Reference in New Issue
Block a user