Skip to content

Commit

Permalink
Add -no-print to 'vault login' (#4454)
Browse files Browse the repository at this point in the history
Trivially manually tested

Closes #2758
  • Loading branch information
jefferai authored Apr 25, 2018
1 parent 669ed87 commit 9345aad
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions command/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type LoginCommand struct {
flagMethod string
flagPath string
flagNoStore bool
flagNoPrint bool
flagTokenOnly bool

// Deprecations
Expand Down Expand Up @@ -114,6 +115,14 @@ func (c *LoginCommand) Flags() *FlagSets {
"The token will only be displayed in the command output.",
})

f.BoolVar(&BoolVar{
Name: "no-print",
Target: &c.flagNoPrint,
Default: false,
Usage: "Do not display the token. The token will be still be stored to the " +
"configured token helper.",
})

f.BoolVar(&BoolVar{
Name: "token-only",
Target: &c.flagTokenOnly,
Expand Down Expand Up @@ -192,6 +201,12 @@ func (c *LoginCommand) Run(args []string) int {
c.flagField = "token"
}

if c.flagNoStore && c.flagNoPrint {
c.UI.Error(wrapAtLength(
"-no-store and -no-print cannot be used together"))
return 1
}

// Get the auth method
authMethod := sanitizePath(c.flagMethod)
if authMethod == "" {
Expand Down Expand Up @@ -329,6 +344,10 @@ func (c *LoginCommand) Run(args []string) int {
"Vault.") + "\n")
}

if c.flagNoPrint {
return 0
}

// If the user requested a particular field, print that out now since we
// are likely piping to another process.
if c.flagField != "" {
Expand Down

0 comments on commit 9345aad

Please sign in to comment.