-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathauth.go
More file actions
108 lines (83 loc) · 2.21 KB
/
auth.go
File metadata and controls
108 lines (83 loc) · 2.21 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package parser
import (
"fmt"
docopt "github.com/docopt/docopt-go"
"github.com/drycc/workflow-cli/cmd"
)
// Auth routes auth commands to the specific function.
func Auth(argv []string, cmdr cmd.Commander) error {
usage := `
Valid commands for auth:
auth:login authenticate against a controller
auth:logout clear the current user session
auth:whoami display the current user
Use 'drycc help [command]' to learn more.
`
switch argv[0] {
case "auth:login":
return authLogin(argv, cmdr)
case "auth:logout":
return authLogout(argv, cmdr)
case "auth:whoami":
return authWhoami(argv, cmdr)
case "auth":
fmt.Print(usage)
return nil
default:
PrintUsage(cmdr)
return nil
}
}
func authLogin(argv []string, cmdr cmd.Commander) error {
usage := `
Logs in by authenticating against a controller.
Usage: drycc auth:login <controller> [options]
Arguments:
<controller>
a fully-qualified controller URI, e.g. "http://drycc.local3.dryccapp.com/".
Options:
--username=<username>
provide a username for the account.
--password=<password>
provide a password for the account.
--ssl-verify=true
enables/disables SSL certificate verification for API requests
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
controller := safeGetString(args, "<controller>")
sslVerify := true
if args["--ssl-verify"] != nil && args["--ssl-verify"].(string) == "false" {
sslVerify = false
}
username := safeGetString(args, "--username")
password := safeGetString(args, "--password")
return cmdr.Login(controller, sslVerify, username, password)
}
func authLogout(argv []string, cmdr cmd.Commander) error {
usage := `
Logs out from a controller and clears the user session.
Usage: drycc auth:logout
Options:
`
if _, err := docopt.ParseArgs(usage, argv, ""); err != nil {
return err
}
return cmdr.Logout()
}
func authWhoami(argv []string, cmdr cmd.Commander) error {
usage := `
Displays the currently logged in user.
Usage: drycc auth:whoami [options]
Options:
--all
fetch a more detailed description about the user.
`
args, err := docopt.ParseArgs(usage, argv, "")
if err != nil {
return err
}
return cmdr.Whoami(args["--all"].(bool))
}