Skip to content

Commit

Permalink
Add option to skip-verify and pass email through args
Browse files Browse the repository at this point in the history
  • Loading branch information
andscoop committed Jun 27, 2018
1 parent c356c65 commit 6c957ca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd/users.go
Expand Up @@ -9,6 +9,9 @@ import (
)

var (
skipVerify bool
userEmail string

usersRootCmd = &cobra.Command{
Use: "users",
Short: "Manage astronomer users",
Expand Down Expand Up @@ -46,6 +49,8 @@ func init() {

// Users create
usersRootCmd.AddCommand(usersCreateCmd)
usersCreateCmd.Flags().BoolVar(&skipVerify, "skip-verify", false, "Skips password verification on create")
usersCreateCmd.Flags().StringVar(&userEmail, "email", "", "Supply user email at runtime")

// Users delete
usersRootCmd.AddCommand(usersDeleteCmd)
Expand All @@ -55,7 +60,7 @@ func usersList(cmd *cobra.Command, args []string) {
}

func usersCreate(cmd *cobra.Command, args []string) error {
err := users.CreateUser()
err := users.CreateUser(skipVerify, userEmail)
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
41 changes: 41 additions & 0 deletions users/users.go
@@ -0,0 +1,41 @@
package users

import (
"errors"

"github.com/astronomerio/astro-cli/config"
"github.com/astronomerio/astro-cli/houston"
"github.com/astronomerio/astro-cli/pkg/httputil"
"github.com/astronomerio/astro-cli/pkg/input"
)

var (
HTTP = httputil.NewHTTPClient()
)

// CreateUser verifies input before sending a CreateUser API call to houston
func CreateUser(skipVerify bool, emailIn string) error {
API := houston.NewHoustonClient(HTTP)
email := emailIn

if len(emailIn) == 0 {
email = input.InputText("Email: ")
}

password, _ := input.InputPassword("Password: ")

if !skipVerify {
passwordVerify, _ := input.InputPassword("Re-enter Password: ")
if password != passwordVerify {
return errors.New("Passwords do not match, try again")
}
}

status, houstonErr := API.CreateUser(email, password)
if houstonErr != nil {
return houstonErr
}

config.CFG.CloudAPIToken.SetProjectString(status.Token)
return nil
}

0 comments on commit 6c957ca

Please sign in to comment.