/
users.go
41 lines (32 loc) · 932 Bytes
/
users.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
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
}