-
Notifications
You must be signed in to change notification settings - Fork 1
/
authenticate.go
53 lines (41 loc) · 1010 Bytes
/
authenticate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package command
import (
"bytes"
"fmt"
"github.com/jessevdk/go-flags"
"github.com/mitchellh/cli"
"github.com/prokosna/dementor/lib"
)
type AuthenticateCommand struct {
Ui cli.Ui
}
var authenticateOpts struct {
dementor.CommonConf
}
var authenticateParser *flags.Parser
func init() {
authenticateParser = flags.NewParser(&authenticateOpts, flags.IgnoreUnknown|flags.HelpFlag|flags.PassDoubleDash)
}
func (c *AuthenticateCommand) Run(args []string) int {
_, err := authenticateParser.ParseArgs(args)
if err != nil {
c.Ui.Error(err.Error())
c.Ui.Output(c.Help())
return 1
}
id, err := getSessionId(authenticateOpts.CommonConf)
if err != nil {
c.Ui.Error(err.Error())
return 1
}
c.Ui.Info(fmt.Sprintf("Session ID is [%s]", id))
return 0
}
func (c *AuthenticateCommand) Help() string {
buf := new(bytes.Buffer)
authenticateParser.WriteHelp(buf)
return buf.String()
}
func (c *AuthenticateCommand) Synopsis() string {
return "Fetch a session id by username and password."
}