diff --git a/auth/auth.go b/auth/auth.go index b6f676286..a58ee53c2 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -32,7 +32,8 @@ func basicAuth(username string) string { // oAuth handles oAuth with houston api func oAuth(oAuthUrl string) string { - fmt.Sprintf(messages.HOUSTON_OAUTH_REDIRECT, oAuthUrl) + fmt.Println("\n" + messages.HOUSTON_OAUTH_REDIRECT) + fmt.Println(oAuthUrl + "\n") authSecret := input.InputText(messages.INPUT_OAUTH_TOKEN) token, err := API.CreateOAuthToken(authSecret) @@ -44,12 +45,12 @@ func oAuth(oAuthUrl string) string { } // registryAuth authenticates with the private registry -func registryAuth(username, password string) error { - registry := config.CFG.RegistryAuthority.GetString() +func registryAuth() error { + registry := config.RegistryUrl() + token := config.CFG.CloudAPIToken.GetProjectString() - dockerErr := docker.ExecLogin(registry, username, password) + dockerErr := docker.ExecLogin(registry, "user", token) if dockerErr != nil { - // Println instead of panic to prevent excessive error logging to stdout on a failed login fmt.Println(dockerErr) os.Exit(1) } @@ -59,8 +60,8 @@ func registryAuth(username, password string) error { return nil } -// Login logs a user into the docker registry. Will need to login to Houston next. -func Login() { +// Login handles authentication to houston and registry +func Login(oAuthOnly bool) { token := "" authConfig, err := API.GetAuthConfig() if err != nil { @@ -68,7 +69,11 @@ func Login() { os.Exit(1) } - username := input.InputText(messages.INPUT_USERNAME) + username := "" + if !oAuthOnly { + username = input.InputText(messages.INPUT_USERNAME) + } + if len(username) == 0 { if authConfig.GoogleEnabled { token = oAuth(authConfig.OauthUrl) @@ -85,13 +90,11 @@ func Login() { } config.CFG.CloudAPIToken.SetProjectString(token) - - // pass successful credentials to config - // TODO - // config.CFG.RegistryAuth.SetProjectString(config.EncodeAuth(username, password)) + registryAuth() } // Logout logs a user out of the docker registry. Will need to logout of Houston next. func Logout() { - docker.Exec("logout", config.CFG.RegistryAuthority.GetString()) + // forget jwt + config.CFG.CloudAPIToken.SetProjectString("") } diff --git a/cmd/auth.go b/cmd/auth.go index 19340ad21..c95dcf515 100644 --- a/cmd/auth.go +++ b/cmd/auth.go @@ -3,13 +3,12 @@ package cmd import ( "github.com/astronomerio/astro-cli/auth" "github.com/astronomerio/astro-cli/config" - "github.com/astronomerio/astro-cli/messages" - "github.com/pkg/errors" "github.com/spf13/cobra" ) var ( domainOverride string + oAuthOnly bool authRootCmd = &cobra.Command{ Use: "auth", @@ -39,6 +38,7 @@ func init() { // 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) } @@ -48,17 +48,10 @@ func authLogin(cmd *cobra.Command, args []string) error { config.CFG.CloudDomain.SetProjectString(domainOverride) } - projectCloudDomain := config.CFG.CloudDomain.GetProjectString() - globalCloudDomain := config.CFG.CloudDomain.GetHomeString() - - if len(projectCloudDomain) == 0 && len(globalCloudDomain) == 0 { - return errors.New(messages.CONFIG_DOMAIN_NOT_SET_ERROR) - } - - auth.Login() + auth.Login(oAuthOnly) return nil } func authLogout(cmd *cobra.Command, args []string) { - auth.Logout() + // auth.Logout() } diff --git a/houston/houston.go b/houston/houston.go index bc0147b76..02e4a1e5e 100644 --- a/houston/houston.go +++ b/houston/houston.go @@ -142,7 +142,7 @@ func (c *Client) QueryHouston(query string) (*HoustonResponse, error) { // } var response httputil.HTTPResponse - httpResponse, err := c.HTTPClient.Do("POST", config.APIURL(), &doOpts) + httpResponse, err := c.HTTPClient.Do("POST", config.APIUrl(), &doOpts) if err != nil { return nil, err } diff --git a/messages/messages.go b/messages/messages.go index b1eb872ef..313f61b55 100644 --- a/messages/messages.go +++ b/messages/messages.go @@ -50,7 +50,7 @@ var ( HOUSTON_DEPLOYING_PROMPT = "Deploying: %s\n" HOUSTON_NO_DEPLOYMENTS_ERROR = "No airflow deployments found" HOUSTON_SELECT_DEPLOYMENT_PROMT = "Select which airflow deployment you want to deploy to:" - HOUSTON_OAUTH_REDIRECT = "Please visit the following URL, authenticate and paste token in next prompt \n%s" + HOUSTON_OAUTH_REDIRECT = "Please visit the following URL, authenticate and paste token in next prompt " HOUSTON_OAUTH_DISABLED = "OAuth is disabled, contact administrator or defer to basic auth" HOUSTON_INVALID_DEPLOYMENT_KEY = "Invalid deployment selection"