Add -no-print to 'vault login' (#4454)

Trivially manually tested

Closes #2758
This commit is contained in:
Jeff Mitchell 2018-04-25 15:47:49 -04:00 committed by GitHub
parent 669ed87311
commit 9345aade8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,6 +25,7 @@ type LoginCommand struct {
flagMethod string
flagPath string
flagNoStore bool
flagNoPrint bool
flagTokenOnly bool
// Deprecations
@ -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,
@ -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 == "" {
@ -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 != "" {