// Login to a Deis controller. func Login(controller string, username string, password string, sslVerify bool) error { u, err := url.Parse(controller) if err != nil { return err } controllerURL, err := chooseScheme(*u) httpClient := client.CreateHTTPClient(sslVerify) if err != nil { return err } if err = client.CheckConection(httpClient, controllerURL); err != nil { return err } if username == "" { fmt.Print("username: "******"" { fmt.Print("password: ") password, err = readPassword() fmt.Println() if err != nil { return err } } c := &client.Client{ControllerURL: controllerURL, SSLVerify: sslVerify, HTTPClient: httpClient} return doLogin(c, username, password) }
// Register creates a account on a Deis controller. func Register(controller string, username string, password string, email string, sslVerify bool) error { u, err := url.Parse(controller) httpClient := client.CreateHTTPClient(sslVerify) if err != nil { return err } controllerURL, err := chooseScheme(*u) if err != nil { return err } if err = client.CheckConection(httpClient, controllerURL); err != nil { return err } if username == "" { fmt.Print("username: "******"" { fmt.Print("password: "******"\npassword (confirm): ") passwordConfirm, err := readPassword() fmt.Println() if err != nil { return err } if password != passwordConfirm { return errors.New("Password mismatch, aborting registration.") } } if email == "" { fmt.Print("email: ") fmt.Scanln(&email) } c := &client.Client{ControllerURL: controllerURL, SSLVerify: sslVerify, HTTPClient: httpClient} tempClient, err := client.New() if err == nil { c.Token = tempClient.Token } err = auth.Register(c, username, password, email) c.Token = "" if err != nil { fmt.Print("Registration failed: ") return err } fmt.Printf("Registered %s\n", username) return doLogin(c, username, password) }