-
Notifications
You must be signed in to change notification settings - Fork 506
/
cmds_auth.go
53 lines (48 loc) · 1.27 KB
/
cmds_auth.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 cli
import (
"github.com/spf13/cobra"
"github.com/telepresenceio/telepresence/v2/pkg/client/cli/ann"
"github.com/telepresenceio/telepresence/v2/pkg/client/cli/cliutil"
)
func LoginCommand() *cobra.Command {
var args struct {
apikey string
}
cmd := &cobra.Command{
Use: "login",
Args: cobra.NoArgs,
Short: "Authenticate to Ambassador Cloud",
Long: "Authenticate to Ambassador Cloud",
RunE: func(cmd *cobra.Command, _ []string) error {
if err := cliutil.InitCommand(cmd); err != nil {
return err
}
_, err := cliutil.EnsureLoggedIn(cmd.Context(), args.apikey)
return err
},
Annotations: map[string]string{
ann.UserDaemon: ann.Required,
ann.Notifications: ann.Required,
},
}
cmd.Flags().StringVar(&args.apikey, "apikey", "",
"Static API key to use instead of performing an interactive login")
return cmd
}
func LogoutCommand() *cobra.Command {
return &cobra.Command{
Use: "logout",
Args: cobra.NoArgs,
Short: "Logout from Ambassador Cloud",
Long: "Logout from Ambassador Cloud",
RunE: func(cmd *cobra.Command, _ []string) error {
if err := cliutil.InitCommand(cmd); err != nil {
return err
}
return cliutil.Logout(cmd.Context())
},
Annotations: map[string]string{
ann.UserDaemon: ann.Required,
},
}
}