Skip to content

Commit

Permalink
Add houston auth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
andscoop committed Apr 18, 2018
1 parent 85e19c5 commit 9731937
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
23 changes: 19 additions & 4 deletions auth/auth.go
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/astronomerio/astro-cli/config"
"github.com/astronomerio/astro-cli/docker"
"github.com/astronomerio/astro-cli/houston"
"github.com/astronomerio/astro-cli/utils"
)

Expand All @@ -14,14 +15,28 @@ func Login() {
username := utils.InputText("Username: ")
password, _ := utils.InputPassword("Password: ")

err := docker.ExecLogin(registry, username, password)
if err != nil {
HTTP := houston.NewHTTPClient()
API := houston.NewHoustonClient(HTTP)

// authenticate with houston
body, houstonErr := API.CreateToken(username, password)
if houstonErr != nil {
panic(houstonErr)
} else if body.Data.CreateToken.Success != true {
fmt.Println(body.Data.CreateToken.Message)
return
}

config.CFG.APIAuthToken.SetProjectString(body.Data.CreateToken.Token)

//authenticate with registry
dockerErr := docker.ExecLogin(registry, username, password)
if dockerErr != nil {
// Println instead of panic to prevent excessive error logging to stdout on a failed login
fmt.Println(err)
fmt.Println(dockerErr)
return
}

// pass successful credentials to config
config.CFG.RegistryUser.SetProjectString(username)
config.CFG.RegistryPassword.SetProjectString(password)
}
Expand Down
5 changes: 2 additions & 3 deletions config/config.go
Expand Up @@ -41,7 +41,7 @@ var (
APIHostName: newCfg("api.hostname", true, "localhost"),
APIProtocol: newCfg("api.protocol", true, "http"),
APIPort: newCfg("api.port", true, "8870"),
APIVersion: newCfg("api.version", true, "v1"),
APIAuthToken: newCfg("api.authToken", true, ""),
}

// viperHome is the viper object in the users home directory
Expand Down Expand Up @@ -183,10 +183,9 @@ func saveConfig(v *viper.Viper, file string) error {
// APIURL will return a full qualified API url
func APIURL() string {
return fmt.Sprintf(
"%s://%s:%s/%s",
"%s://%s:%s/v1",
CFG.APIProtocol.GetString(),
CFG.APIHostName.GetString(),
CFG.APIPort.GetString(),
CFG.APIVersion.GetString(),
)
}
2 changes: 1 addition & 1 deletion config/types.go
Expand Up @@ -12,7 +12,7 @@ type cfgs struct {
APIHostName cfg
APIProtocol cfg
APIPort cfg
APIVersion cfg
APIAuthToken cfg
PostgresUser cfg
PostgresPassword cfg
PostgresHost cfg
Expand Down

0 comments on commit 9731937

Please sign in to comment.