Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token-only. #2971

Merged
merged 2 commits into from
Jul 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions command/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ type AuthCommand struct {

func (c *AuthCommand) Run(args []string) int {
var method, authPath string
var methods, methodHelp, noVerify, noStore bool
var methods, methodHelp, noVerify, noStore, tokenOnly bool
flags := c.Meta.FlagSet("auth", meta.FlagSetDefault)
flags.BoolVar(&methods, "methods", false, "")
flags.BoolVar(&methodHelp, "method-help", false, "")
flags.BoolVar(&noVerify, "no-verify", false, "")
flags.BoolVar(&noStore, "no-store", false, "")
flags.BoolVar(&tokenOnly, "token-only", false, "")
flags.StringVar(&method, "method", "", "method")
flags.StringVar(&authPath, "path", "", "")
flags.Usage = func() { c.Ui.Error(c.Help()) }
Expand Down Expand Up @@ -128,8 +129,8 @@ func (c *AuthCommand) Run(args []string) int {
}

// Warn if the VAULT_TOKEN environment variable is set, as that will take
// precedence
if os.Getenv("VAULT_TOKEN") != "" {
// precedence. Don't output on token-only since we're likely piping output.
if os.Getenv("VAULT_TOKEN") != "" && !tokenOnly {
c.Ui.Output("==> WARNING: VAULT_TOKEN environment variable set!\n")
c.Ui.Output(" The environment variable takes precedence over the value")
c.Ui.Output(" set by the auth command. Either update the value of the")
Expand Down Expand Up @@ -178,6 +179,11 @@ func (c *AuthCommand) Run(args []string) int {
return 1
}

if tokenOnly {
c.Ui.Output(token)
return 0
}

// Store the token!
if !noStore {
if err := tokenHelper.Store(token); err != nil {
Expand Down Expand Up @@ -393,6 +399,9 @@ Auth Options:
-no-store Do not store the token after creation; it will only be
displayed in the command output.

-token-only Output only the token to stdout. This implies -no-verify
and -no-store.

-path The path at which the auth backend is enabled. If an auth
backend is mounted at multiple paths, this option can be
used to authenticate against specific paths.
Expand Down