func (d *Daemon) Run() error {
	email, hasEmail := os.LookupEnv("TORUS_EMAIL")
	password, hasPassword := os.LookupEnv("TORUS_PASSWORD")
	tokenID, hasTokenID := os.LookupEnv("TORUS_TOKEN_ID")
	tokenSecret, hasTokenSecret := os.LookupEnv("TORUS_TOKEN_SECRET")

	if hasEmail && hasPassword {
		log.Printf("Attempting to login as: %s", email)
		userLogin := &apitypes.UserLogin{
			Email:    email,
			Password: password,
		}

		err := d.logic.Session.Login(context.Background(), userLogin)
		if err != nil {
			return err
		}
	}

	if hasTokenID && hasTokenSecret {
		log.Printf("Attempting to login as machine token id: %s", tokenID)

		ID, err := identity.DecodeFromString(tokenID)
		if err != nil {
			log.Printf("Could not parse TORUS_TOKEN_ID")
			return err
		}

		secret, err := base64.NewValueFromString(tokenSecret)
		if err != nil {
			log.Printf("Could not parse TORUS_TOKEN_SECRET")
			return err
		}

		machineLogin := &apitypes.MachineLogin{
			TokenID: &ID,
			Secret:  secret,
		}

		err = d.logic.Session.Login(context.Background(), machineLogin)
		if err != nil {
			return err
		}
	}

	return d.proxy.Listen()
}
// Run starts the daemon main loop. It returns on failure, or when the daemon
// has been gracefully shut down.
Run starts the daemon main loop. It returns on failure, or when the daemon
has been gracefully shut down.
// Run starts the daemon main loop . It returns on failure or when the daemon // has been gracefully shut down .
func (d *Daemon) Run() error {
	email, hasEmail := os.LookupEnv("TORUS_EMAIL")
	password, hasPassword := os.LookupEnv("TORUS_PASSWORD")
	tokenID, hasTokenID := os.LookupEnv("TORUS_TOKEN_ID")
	tokenSecret, hasTokenSecret := os.LookupEnv("TORUS_TOKEN_SECRET")
	if hasEmail && hasPassword {
		log.Printf("Attempting to login as: %s", email)
		userLogin := &apitypes.UserLogin{
			Email:    email,
			Password: password,
		}
		err := d.logic.Session.Login(context.Background(), userLogin)
		if err != nil {
			return err
		}
	}
	if hasTokenID && hasTokenSecret {
		log.Printf("Attempting to login as machine token id: %s", tokenID)
		ID, err := identity.DecodeFromString(tokenID)
		if err != nil {
			log.Printf("Could not parse TORUS_TOKEN_ID")
			return err
		}
		secret, err := base64.NewValueFromString(tokenSecret)
		if err != nil {
			log.Printf("Could not parse TORUS_TOKEN_SECRET")
			return err
		}
		machineLogin := &apitypes.MachineLogin{
			TokenID: &ID,
			Secret:  secret,
		}
		err = d.logic.Session.Login(context.Background(), machineLogin)
		if err != nil {
			return err
		}
	}
	return d.proxy.Listen()
}
func ( d * Daemon ) Run ( ) error { email , hasEmail := os . LookupEnv ( " " ) password , hasPassword := os . LookupEnv ( " " ) tokenID , hasTokenID := os . LookupEnv ( " " ) tokenSecret , hasTokenSecret := os . LookupEnv ( " " ) if hasEmail && hasPassword { log . Printf ( " " , email ) userLogin := & apitypes . UserLogin { Email : email , Password : password , } err := d . logic . Session . Login ( context . Background ( ) , userLogin ) if err != nil { return err } } if hasTokenID && hasTokenSecret { log . Printf ( " " , tokenID ) ID , err := identity . DecodeFromString ( tokenID ) if err != nil { log . Printf ( " " ) return err } secret , err := base64 . NewValueFromString ( tokenSecret ) if err != nil { log . Printf ( " " ) return err } machineLogin := & apitypes . MachineLogin { TokenID : & ID , Secret : secret , } err = d . logic . Session . Login ( context . Background ( ) , machineLogin ) if err != nil { return err } } return d . proxy . Listen ( ) }
Run starts the daemon main loop.
Run starts the daemon main loop .