2019-02-01 22:13:51 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
2021-04-08 16:43:39 +00:00
|
|
|
var (
|
|
|
|
_ cli.Command = (*PrintTokenCommand)(nil)
|
|
|
|
_ cli.CommandAutocomplete = (*PrintTokenCommand)(nil)
|
|
|
|
)
|
2019-02-01 22:13:51 +00:00
|
|
|
|
|
|
|
type PrintTokenCommand struct {
|
|
|
|
*BaseCommand
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *PrintTokenCommand) Synopsis() string {
|
2020-12-03 17:59:09 +00:00
|
|
|
return "Prints the vault token currently in use"
|
2019-02-01 22:13:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-02-11 19:19:08 +00:00
|
|
|
`
|
2019-02-01 22:13:51 +00:00
|
|
|
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
|
|
|
|
}
|