mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 18:17:55 +00:00
Add aliases for field flag to allow printing auth results.
Also fix the write command to use the shared function with aliases. Fixes #1566
This commit is contained in:
@@ -31,28 +31,45 @@ func DefaultTokenHelper() (token.TokenHelper, error) {
|
||||
|
||||
func PrintRawField(ui cli.Ui, secret *api.Secret, field string) int {
|
||||
var val interface{}
|
||||
switch {
|
||||
case secret.Auth != nil:
|
||||
switch field {
|
||||
case "token":
|
||||
val = secret.Auth.ClientToken
|
||||
case "token_accessor":
|
||||
val = secret.Auth.Accessor
|
||||
case "token_duration":
|
||||
val = secret.Auth.LeaseDuration
|
||||
case "token_renewable":
|
||||
val = secret.Auth.Renewable
|
||||
case "token_policies":
|
||||
val = secret.Auth.Policies
|
||||
default:
|
||||
val = secret.Data[field]
|
||||
}
|
||||
|
||||
case secret.WrapInfo != nil:
|
||||
switch field {
|
||||
case "wrapping_token":
|
||||
if secret.WrapInfo != nil {
|
||||
val = secret.WrapInfo.Token
|
||||
}
|
||||
case "wrapping_token_ttl":
|
||||
if secret.WrapInfo != nil {
|
||||
val = secret.WrapInfo.TTL
|
||||
}
|
||||
case "wrapping_token_creation_time":
|
||||
if secret.WrapInfo != nil {
|
||||
val = secret.WrapInfo.CreationTime.String()
|
||||
}
|
||||
case "wrapped_accessor":
|
||||
if secret.WrapInfo != nil {
|
||||
val = secret.WrapInfo.WrappedAccessor
|
||||
default:
|
||||
val = secret.Data[field]
|
||||
}
|
||||
|
||||
default:
|
||||
switch field {
|
||||
case "refresh_interval":
|
||||
val = secret.LeaseDuration
|
||||
default:
|
||||
val = secret.Data[field]
|
||||
}
|
||||
}
|
||||
|
||||
if val != nil {
|
||||
// c.Ui.Output() prints a CR character which in this case is
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/vault/helper/kv-builder"
|
||||
@@ -75,23 +74,7 @@ func (c *WriteCommand) Run(args []string) int {
|
||||
|
||||
// Handle single field output
|
||||
if field != "" {
|
||||
if val, ok := secret.Data[field]; ok {
|
||||
// c.Ui.Output() prints a CR character which in this case is
|
||||
// not desired. Since Vault CLI currently only uses BasicUi,
|
||||
// which writes to standard output, os.Stdout is used here to
|
||||
// directly print the message. If mitchellh/cli exposes method
|
||||
// to print without CR, this check needs to be removed.
|
||||
if reflect.TypeOf(c.Ui).String() == "*cli.BasicUi" {
|
||||
fmt.Fprintf(os.Stdout, fmt.Sprintf("%v", val))
|
||||
} else {
|
||||
c.Ui.Output(fmt.Sprintf("%v", val))
|
||||
}
|
||||
return 0
|
||||
} else {
|
||||
c.Ui.Error(fmt.Sprintf(
|
||||
"Field %s not present in secret", field))
|
||||
return 1
|
||||
}
|
||||
return PrintRawField(c.Ui, secret, field)
|
||||
}
|
||||
|
||||
return OutputSecret(c.Ui, format, secret)
|
||||
|
||||
Reference in New Issue
Block a user