command/auth: boilerplate

This commit is contained in:
Mitchell Hashimoto 2015-03-29 16:42:45 -07:00
parent b89ac8e3c5
commit 9d8d24f7fb
2 changed files with 63 additions and 7 deletions

View File

@ -18,6 +18,18 @@ func (c *AuthCommand) Run(args []string) int {
return 1 return 1
} }
args = flags.Args()
if len(args) > 1 {
flags.Usage()
c.Ui.Error("\nError: auth expects at most one argument")
return 1
}
if method != "" && len(args) > 0 {
flags.Usage()
c.Ui.Error("\nError: auth expects no arguments if -method is specified")
return 1
}
return 0 return 0
} }
@ -27,15 +39,18 @@ func (c *AuthCommand) Synopsis() string {
func (c *AuthCommand) Help() string { func (c *AuthCommand) Help() string {
helpText := ` helpText := `
Usage: vault auth [options] Usage: vault auth [options] [token]
Outputs instructions for authenticating with vault. Authenticate with Vault with the given token or via any supported
authentication backend.
Vault authentication is always done via environmental variables. The If no -method is specified, then the token is expected. If it is not
specific environmental variables and the meaning for each environmental given on the command-line, it will be asked via user input. If the
variable varies depending on the auth mechanism that Vault is using. token is "-", it will be read from stdin.
This command outputs the mechanism vault is using along with documentation
for how to authenticate. By specifying -method, alternate authentication methods can be used
such as OAuth or TLS certificates. For these, additional -var flags
may be required. It is an error to specify a token with -method.
General Options: General Options:

41
command/auth_test.go Normal file
View File

@ -0,0 +1,41 @@
package command
import (
"testing"
"github.com/mitchellh/cli"
)
func TestAuth_argsWithMethod(t *testing.T) {
ui := new(cli.MockUi)
c := &AuthCommand{
Meta: Meta{
Ui: ui,
},
}
args := []string{
"-method=foo",
"bar",
}
if code := c.Run(args); code != 1 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
}
func TestAuth_tooManyArgs(t *testing.T) {
ui := new(cli.MockUi)
c := &AuthCommand{
Meta: Meta{
Ui: ui,
},
}
args := []string{
"foo",
"bar",
}
if code := c.Run(args); code != 1 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
}