-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathauth.go
More file actions
80 lines (72 loc) · 2.37 KB
/
auth.go
File metadata and controls
80 lines (72 loc) · 2.37 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
package parser
import (
"github.com/drycc/workflow-cli/internal/commands"
"github.com/drycc/workflow-cli/pkg/i18n"
"github.com/spf13/cobra"
)
// NewAuthCommand creates the auth command
func NewAuthCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "auth",
Short: i18n.T("Manage authentication"),
RunE: nil,
}
cmd.AddCommand(authLogin(cmdr))
cmd.AddCommand(authLogout(cmdr))
cmd.AddCommand(authWhoami(cmdr))
return cmd
}
// AuthLogin creates the auth:login command
func authLogin(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
username string
password string
sslVerify bool
}
cmd := &cobra.Command{
Use: "login <controller>",
Args: cobra.ExactArgs(1),
Example: "drycc auth login http://drycc.local3.dryccapp.com/",
Short: i18n.T("Authenticate against a controller"),
Long: i18n.T("Logs in by authenticating against a controller"),
RunE: func(_ *cobra.Command, args []string) error {
controller := args[0]
return cmdr.Login(controller, flags.sslVerify, flags.username, flags.password)
},
}
cmd.Flags().StringVarP(&flags.username, "username", "u", "", i18n.T("Provide a username for the account"))
cmd.Flags().StringVarP(&flags.password, "password", "p", "", i18n.T("Provide a password for the account"))
cmd.Flags().BoolVar(&flags.sslVerify, "ssl-verify", true, i18n.T("Enables or disables SSL certificate verification for API requests"))
cmd.Flags().SortFlags = false
return cmd
}
// AuthLogout creates the auth:logout command
func authLogout(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "logout",
Example: "drycc auth logout",
Short: i18n.T("Clear the current user session"),
Long: i18n.T("Logs out from a controller and clears the user session"),
RunE: func(_ *cobra.Command, _ []string) error {
return cmdr.Logout()
},
}
return cmd
}
// AuthWhoami creates the auth:whoami command
func authWhoami(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
all bool
}
cmd := &cobra.Command{
Use: "whoami",
Example: "drycc auth whoami",
Short: i18n.T("Display the current user"),
Long: i18n.T("Displays the currently logged in user"),
RunE: func(_ *cobra.Command, _ []string) error {
return cmdr.Whoami(flags.all)
},
}
cmd.Flags().BoolVarP(&flags.all, "all", "a", false, i18n.T("Fetch detailed user information"))
return cmd
}