open-vault/command/auth.go

118 lines
3.3 KiB
Go
Raw Normal View History

2015-03-04 07:34:32 +00:00
package command
import (
2017-09-08 01:56:39 +00:00
"flag"
2015-05-21 02:43:47 +00:00
"io"
2017-09-08 01:56:39 +00:00
"io/ioutil"
2015-03-04 07:34:32 +00:00
"strings"
2015-03-30 17:55:41 +00:00
2017-09-08 01:56:39 +00:00
"github.com/mitchellh/cli"
2015-03-04 07:34:32 +00:00
)
2017-09-08 01:56:39 +00:00
var _ cli.Command = (*AuthCommand)(nil)
2015-03-04 07:34:32 +00:00
type AuthCommand struct {
2017-09-05 03:59:24 +00:00
*BaseCommand
2017-09-08 01:56:39 +00:00
Handlers map[string]LoginHandler
2017-09-05 03:59:24 +00:00
testStdin io.Reader // for tests
2015-03-04 07:34:32 +00:00
}
2017-09-05 03:59:24 +00:00
func (c *AuthCommand) Synopsis() string {
2017-09-08 01:56:39 +00:00
return "Interact with auth methods"
2017-09-05 03:59:24 +00:00
}
2015-03-04 07:34:32 +00:00
2017-09-05 03:59:24 +00:00
func (c *AuthCommand) Help() string {
2017-09-08 01:56:39 +00:00
return strings.TrimSpace(`
Usage: vault auth <subcommand> [options] [args]
2015-05-21 02:43:47 +00:00
2017-09-08 01:56:39 +00:00
This command groups subcommands for interacting with Vault's auth methods.
Users can list, enable, disable, and get help for different auth methods.
2017-09-08 01:56:39 +00:00
To authenticate to Vault as a user or machine, use the "vault login" command
instead. This command is for interacting with the auth methods themselves, not
authenticating to Vault.
2015-05-21 02:43:47 +00:00
2017-09-08 01:56:39 +00:00
List all enabled auth methods:
2015-03-30 17:55:41 +00:00
2017-09-08 01:56:39 +00:00
$ vault auth list
2017-09-08 01:56:39 +00:00
Enable a new auth method "userpass";
2017-09-08 01:56:39 +00:00
$ vault auth enable userpass
2017-09-08 01:56:39 +00:00
Get detailed help information about how to authenticate to a particular auth
method:
2015-04-06 16:38:16 +00:00
2017-09-08 01:56:39 +00:00
$ vault auth help github
2017-09-08 01:56:39 +00:00
Please see the individual subcommand help for detailed usage information.
`)
2017-09-05 03:59:24 +00:00
}
func (c *AuthCommand) Run(args []string) int {
2017-09-08 01:56:39 +00:00
// If we entered the run method, none of the subcommands picked up. This
// means the user is still trying to use auth as "vault auth TOKEN" or
// similar, so direct them to vault login instead.
//
// This run command is a bit messy to maintain BC for a bit. In the future,
// it will just be a tiny function, but for now we have to maintain bc.
//
// Deprecation
2017-09-05 03:59:24 +00:00
// TODO: remove in 0.9.0
2017-09-08 01:56:39 +00:00
// Parse the args for our deprecations and defer to the proper areas.
for _, arg := range args {
switch {
case strings.HasPrefix(arg, "-methods"):
c.UI.Warn(wrapAtLength(
"WARNING! The -methods flag is deprecated. Please use "+
"\"vault auth list\" instead. This flag will be removed in the "+
"next major release of Vault.") + "\n")
return (&AuthListCommand{
BaseCommand: &BaseCommand{
UI: c.UI,
client: c.client,
},
}).Run(nil)
case strings.HasPrefix(arg, "-method-help"):
c.UI.Warn(wrapAtLength(
"WARNING! The -method-help flag is deprecated. Please use "+
"\"vault auth help\" instead. This flag will be removed in the "+
"next major release of Vault.") + "\n")
// Parse the args to pull out the method, surpressing any errors because
// there could be other flags that we don't care about.
f := flag.NewFlagSet("", flag.ContinueOnError)
f.Usage = func() {}
f.SetOutput(ioutil.Discard)
flagMethod := f.String("method", "", "")
f.Parse(args)
return (&AuthHelpCommand{
BaseCommand: &BaseCommand{
UI: c.UI,
client: c.client,
},
Handlers: c.Handlers,
}).Run([]string{*flagMethod})
2017-09-05 03:59:24 +00:00
}
}
2017-09-08 01:56:39 +00:00
// If we got this far, we have an arg or a series of args that should be
// passed directly to the new "vault login" command.
c.UI.Warn(wrapAtLength(
"WARNING! The \"vault auth ARG\" command is deprecated and is now a "+
"subcommand for interacting with auth methods. To "+
"authenticate locally to Vault, use \"vault login\" instead. This "+
"backwards compatability will be removed in the next major release of "+
"Vault.") + "\n")
return (&LoginCommand{
BaseCommand: &BaseCommand{
UI: c.UI,
client: c.client,
},
Handlers: c.Handlers,
}).Run(args)
}