// getToken gets the login information for a developer and gets a new token. func getToken(dev *db.Developer) error { var err error i := 0 token := "" // Get email and password up to 5 times, then report the error. for token == "" && i < 5 { validEmail := false email := "" pass := "" for !validEmail { email, err = prompt.Basic("Email", true) if err != nil { return err } _, err = mail.ParseAddress(email) if err == nil { validEmail = true } else { log.Println("yellow", "Try again! Valid email address required.") } } pass, err = prompt.Password("Password") if err != nil { return err } log.Debug("Collected email", email, "pass", pass) token, err = broome.GetTokenByLogin(email, pass) if err != nil { if i < 4 { log.Fprintln(os.Stderr, "red", errors.Newf(errors.ErrLoginRetryTmpl, err)) } i++ } } if err != nil { if err == errors.ErrInvalidLogin { err = errors.ErrTooManyLogins } return err } log.Debug("Got token", token) dev.Token = token return dev.Save() }
func saveRun(keen *keen.Client, rollbar *rollbar.Client, args ...string) int { if len(args) <= 0 { fmt.Fprintln(os.Stderr, "Usage: bowery "+Cmds["save"].Usage, "\n\n"+Cmds["save"].Short) return 2 } dev, err := getDeveloper() if err != nil { rollbar.Report(err) return 1 } state, err := db.GetState() if err != nil { rollbar.Report(err) return 1 } // Create slices of service names, and find the requested service. var service *schemas.Service services := make([]string, len(state.App.Services)) for i, v := range state.App.Services { services[i] = v.Name if args[0] == v.Name { service = v break } } // Handle no service found. if service == nil { log.Fprintln(os.Stderr, "red", errors.ErrInvalidService, args[0]) log.Println("yellow", "Valid services:", strings.Join(services, ", ")) return 1 } log.Debug("Found service", service.Name, "public addr:", service.PublicAddr) // Get image name log.Println("yellow", "What would you like to call this image?") imageName, err := prompt.Basic("Image Name", true) if err != nil { rollbar.Report(err) return 1 } log.Debug("Collected Image Name", imageName) imageDesc, err := prompt.Basic("Description", true) if err != nil { rollbar.Report(err) return 1 } log.Debug("Collected Description", imageDesc) log.Println("yellow", "A new image is being created and saved to our registry...") log.Println("yellow", "This may take a couple minutes.") err = api.SaveService(state, dev, service.Name, service.PublicAddr, imageName, imageDesc) if err != nil { errmsg := err.Error() if errmsg == imageName+" is an invalid service name" || errmsg == "Image already exists" { log.Println("yellow", err) } else { rollbar.Report(err) } return 1 } log.Println("yellow", imageName+" successfully created.") keen.AddEvent("bowery save", map[string]string{ "serviceName": service.Name, "imageName": imageName, "appId": state.App.ID, }) return 0 }