Skip to content

Commit

Permalink
Merge pull request #45 from astronomerio/feature/39-add-suggested-reg…
Browse files Browse the repository at this point in the history
…istry-output

add custom registry flag
  • Loading branch information
schnie committed Mar 7, 2018
2 parents e9f9466 + 9403284 commit 6e2af4d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cmd/auth.go
Expand Up @@ -2,10 +2,14 @@ package cmd

import (
"github.com/astronomerio/astro-cli/auth"
"github.com/astronomerio/astro-cli/config"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var (
registryOverride string

authRootCmd = &cobra.Command{
Use: "auth",
Short: "Mangage astronomer identity",
Expand All @@ -16,7 +20,7 @@ var (
Use: "login",
Short: "Login to Astronomer services",
Long: "Login to Astronomer services",
Run: authLogin,
RunE: authLogin,
}

authLogoutCmd = &cobra.Command{
Expand All @@ -33,13 +37,23 @@ func init() {

// Auth login
authRootCmd.AddCommand(authLoginCmd)

authLoginCmd.Flags().StringVarP(&registryOverride, "registry", "r", "", "pass a custom project registry for authentication")
// Auth logout
authRootCmd.AddCommand(authLogoutCmd)
}

func authLogin(cmd *cobra.Command, args []string) {
func authLogin(cmd *cobra.Command, args []string) error {
if len(registryOverride) > 0 {
config.CFG.RegistryAuthority.SetProjectString(registryOverride)
}

if config.CFG.RegistryAuthority.GetHomeString() == "" &&
registryOverride == "" {
return errors.New("No registry set. Use -r to pass a custom registry\n\nEx.\nastro auth login -r registry.EXAMPLE_DOMAIN.com\n ")
}

auth.Login()
return nil
}

func authLogout(cmd *cobra.Command, args []string) {
Expand Down

0 comments on commit 6e2af4d

Please sign in to comment.