/
auth.go
56 lines (46 loc) · 1.29 KB
/
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
54
55
56
package cmd
import (
"github.com/astronomerio/astro-cli/auth"
"github.com/astronomerio/astro-cli/config"
"github.com/spf13/cobra"
)
var (
domainOverride string
oAuthOnly bool
authRootCmd = &cobra.Command{
Use: "auth",
Short: "Mangage astronomer identity",
Long: "Handles authentication to the Astronomer Platform",
}
authLoginCmd = &cobra.Command{
Use: "login",
Short: "Login to Astronomer services",
Long: "Authenticate to houston-api using oAuth or basic auth.",
RunE: authLogin,
}
authLogoutCmd = &cobra.Command{
Use: "logout",
Short: "Logout of Astronomer services",
Long: "Logout of Astronomer services",
Run: authLogout,
}
)
func init() {
// Auth root
RootCmd.AddCommand(authRootCmd)
// Auth login
authRootCmd.AddCommand(authLoginCmd)
authLoginCmd.Flags().StringVarP(&domainOverride, "domain", "d", "", "pass the cluster domain for authentication")
authLoginCmd.Flags().BoolVarP(&oAuthOnly, "oauth", "o", false, "do not prompt for local auth")
// Auth logout
authRootCmd.AddCommand(authLogoutCmd)
}
func authLogin(cmd *cobra.Command, args []string) error {
if domainOverride != "" {
config.CFG.CloudDomain.SetProjectString(domainOverride)
}
return auth.Login(oAuthOnly)
}
func authLogout(cmd *cobra.Command, args []string) {
auth.Logout()
}