예제 #1
0
파일: sync.go 프로젝트: Bowery/bowery-cli
// wrapErr wraps an error with the given service name.
func (watcher *Watcher) wrapErr(err error) error {
	if err == nil {
		return nil
	}

	se := errors.IsStackError(err)
	if se != nil {
		se.Err = errors.Newf(errors.ErrSyncTmpl, watcher.Service.Name, se.Err)
		return se
	}

	return errors.Newf(errors.ErrSyncTmpl, watcher.Service.Name, err)
}
예제 #2
0
// GetServices retrieves the services from the bowery.json file,
// and if empty uses empty services.
func GetServices() (*Services, error) {
	services := new(Services)
	services.Data = make(map[string]*Service)
	services.Path = "bowery.json"

	err := jumpToParent(services.Path)
	if err != nil && !os.IsNotExist(err) {
		return nil, err
	}

	err = load(&services.Data, services.Path)
	if err == io.EOF || os.IsNotExist(err) {
		err = nil
	}

	// Convert ports to ints.
	for _, service := range services.Data {
		if service.Ports != nil {
			for i, port := range service.Ports {
				_, isNum := port.(float64)
				portStr, isStr := port.(string)
				if !isNum && !isStr {
					return nil, errors.Newf(errors.ErrInvalidJSONTmpl, services.Path)
				}

				if isNum {
					continue
				}

				portNum, err := strconv.Atoi(portStr)
				if err != nil {
					return nil, errors.Newf(errors.ErrInvalidJSONTmpl, services.Path)
				}

				service.Ports[i] = portNum
			}
		}
	}

	return services, err
}
예제 #3
0
파일: login.go 프로젝트: Bowery/bowery-cli
// 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()
}