mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-08 07:37:01 +02:00
command/token-create: provide more useful output. Fixes #337
This commit is contained in:
parent
81df0d6e49
commit
d19b74f78f
@ -53,6 +53,16 @@ func outputFormatTable(ui cli.Ui, s *api.Secret, whitespace bool) int {
|
|||||||
"lease_renewable %s %s", config.Delim, strconv.FormatBool(s.Renewable)))
|
"lease_renewable %s %s", config.Delim, strconv.FormatBool(s.Renewable)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.Auth != nil {
|
||||||
|
input = append(input, fmt.Sprintf("token %s %s", config.Delim, s.Auth.ClientToken))
|
||||||
|
input = append(input, fmt.Sprintf("token_duration %s %d", config.Delim, s.Auth.LeaseDuration))
|
||||||
|
input = append(input, fmt.Sprintf("token_renewable %s %v", config.Delim, s.Auth.Renewable))
|
||||||
|
input = append(input, fmt.Sprintf("token_policies %s %v", config.Delim, s.Auth.Policies))
|
||||||
|
for k, v := range s.Auth.Metadata {
|
||||||
|
input = append(input, fmt.Sprintf("token_meta_%s %s %#v", k, config.Delim, v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for k, v := range s.Data {
|
for k, v := range s.Data {
|
||||||
input = append(input, fmt.Sprintf("%s %s %v", k, config.Delim, v))
|
input = append(input, fmt.Sprintf("%s %s %v", k, config.Delim, v))
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,14 @@ type TokenCreateCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *TokenCreateCommand) Run(args []string) int {
|
func (c *TokenCreateCommand) Run(args []string) int {
|
||||||
|
var format string
|
||||||
var displayName, lease string
|
var displayName, lease string
|
||||||
var orphan bool
|
var orphan bool
|
||||||
var metadata map[string]string
|
var metadata map[string]string
|
||||||
var numUses int
|
var numUses int
|
||||||
var policies []string
|
var policies []string
|
||||||
flags := c.Meta.FlagSet("mount", FlagSetDefault)
|
flags := c.Meta.FlagSet("mount", FlagSetDefault)
|
||||||
|
flags.StringVar(&format, "format", "table", "")
|
||||||
flags.StringVar(&displayName, "display-name", "", "")
|
flags.StringVar(&displayName, "display-name", "", "")
|
||||||
flags.StringVar(&lease, "lease", "", "")
|
flags.StringVar(&lease, "lease", "", "")
|
||||||
flags.BoolVar(&orphan, "orphan", false, "")
|
flags.BoolVar(&orphan, "orphan", false, "")
|
||||||
@ -61,8 +63,7 @@ func (c *TokenCreateCommand) Run(args []string) int {
|
|||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Ui.Output(secret.Auth.ClientToken)
|
return OutputSecret(c.Ui, format, secret)
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TokenCreateCommand) Synopsis() string {
|
func (c *TokenCreateCommand) Synopsis() string {
|
||||||
@ -121,6 +122,10 @@ Token Options:
|
|||||||
|
|
||||||
-use-limit=5 The number of times this token can be used until
|
-use-limit=5 The number of times this token can be used until
|
||||||
it is automatically revoked.
|
it is automatically revoked.
|
||||||
|
|
||||||
|
-format=table The format for output. By default it is a whitespace-
|
||||||
|
delimited table. This can also be json.
|
||||||
|
|
||||||
`
|
`
|
||||||
return strings.TrimSpace(helpText)
|
return strings.TrimSpace(helpText)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/vault/http"
|
"github.com/hashicorp/vault/http"
|
||||||
@ -27,4 +28,10 @@ func TestTokenCreate(t *testing.T) {
|
|||||||
if code := c.Run(args); code != 0 {
|
if code := c.Run(args); code != 0 {
|
||||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure we get lease info
|
||||||
|
output := ui.OutputWriter.String()
|
||||||
|
if !strings.Contains(output, "token_duration") {
|
||||||
|
t.Fatalf("bad: %#v", output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user