-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
print_token.go
53 lines (40 loc) · 1012 Bytes
/
print_token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package command
import (
"strings"
"github.com/mitchellh/cli"
"github.com/posener/complete"
)
var (
_ cli.Command = (*PrintTokenCommand)(nil)
_ cli.CommandAutocomplete = (*PrintTokenCommand)(nil)
)
type PrintTokenCommand struct {
*BaseCommand
}
func (c *PrintTokenCommand) Synopsis() string {
return "Prints the vault token currently in use"
}
func (c *PrintTokenCommand) Help() string {
helpText := `
Usage: vault print token
Prints the value of the Vault token that will be used for commands, after
taking into account the configured token-helper and the environment.
$ vault print token
`
return strings.TrimSpace(helpText)
}
func (c *PrintTokenCommand) AutocompleteArgs() complete.Predictor {
return nil
}
func (c *PrintTokenCommand) AutocompleteFlags() complete.Flags {
return nil
}
func (c *PrintTokenCommand) Run(args []string) int {
client, err := c.Client()
if err != nil {
c.UI.Error(err.Error())
return 2
}
c.UI.Output(client.Token())
return 0
}