interactor

package
v0.0.0-...-08daa4e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBearerTokenNotFound = errors.New("token not found")

ErrBearerTokenNotFound is returned when the bearer token can't be found in the http request

View Source
var ErrCookieFormat = errors.New("wrong cookie format")

ErrCookieFormat is returned when the cookie value can't be unmarshalled

View Source
var ErrCookieNotFound = errors.New("cookie not found")

ErrCookieNotFound is returned when the cookie can't be found

View Source
var ErrInvalidCredentials = errors.New("invalid credentials")

ErrInvalidCredentials is returned when invalid credentials are provided

View Source
var ErrInvalidJWT = errors.New("invalid jwt")

ErrInvalidJWT is returned when the JWT isn't valid (expired, unsigned, etc.)

View Source
var ErrJWT = errors.New("jwt error")

ErrJWT is a JWT error

View Source
var ErrNoAuthenticationFound = errors.New("no authentication found")

ErrNoAuthenticationFound is returned when neither the bearer token or the cookie can be found

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when an element isn't found

View Source
var ErrPermission = errors.New("permission error")

ErrPermission is returned when a permission error occurs

Functions

This section is empty.

Types

type AuthProvider

type AuthProvider interface {
	GenerateTokenPair(user *models.User) (*models.TokenPair, error)
	CheckToken(token string) (*jwt.RegisteredClaims, error)
	ValidateBearerToken(r *http.Request) (*jwt.RegisteredClaims, error)

	ValidateCookie(r *http.Request) (*jwt.RegisteredClaims, bool, error)
	GenerateCookie(u *models.User, tp *models.TokenPair) (*http.Cookie, error)
	DropAccessCookie() *http.Cookie
}

AuthProvider is a simple auth provider interface

type Formatter

type Formatter interface {
	Self(user *models.User) interface{}
	Service(svc *models.Service) interface{}
	Services(svx []*models.Service) interface{}
	TimedResponses(tr []*models.TimedResponse) interface{}
}

Formatter is a simple interface in charge of formatting our documents

type Interactor

type Interactor struct {
	Store     StorageProvider
	Auth      AuthProvider
	Formatter Formatter
	Logger    *zerolog.Logger
	Scheduler Scheduler
}

Interactor contains the dependencies of the service

func (Interactor) AuthCheck

func (i Interactor) AuthCheck(w http.ResponseWriter, r *http.Request) (*models.User, error)

AuthCheck extracts the JWT token and the associated user from the incoming HTTP request

func (Interactor) FormatSelf

func (i Interactor) FormatSelf(user *models.User) interface{}

func (Interactor) FormatService

func (i Interactor) FormatService(svc *models.Service) interface{}

func (Interactor) FormatServices

func (i Interactor) FormatServices(svx []*models.Service) interface{}

func (Interactor) FormatTimedResponses

func (i Interactor) FormatTimedResponses(tr []*models.TimedResponse) interface{}

func (Interactor) GetServiceByID

func (i Interactor) GetServiceByID(user *models.User, id string) (*models.Service, error)

func (Interactor) GetServices

func (i Interactor) GetServices(user *models.User) ([]*models.Service, error)

func (Interactor) GetTimedResponseRange

func (i Interactor) GetTimedResponseRange(user *models.User, id string, from, to time.Time) ([]*models.TimedResponse, error)

func (Interactor) GetTimedResponsesByServiceID

func (i Interactor) GetTimedResponsesByServiceID(user *models.User, id string, limit int, reverse bool) ([]*models.TimedResponse, error)

func (Interactor) Login

func (i Interactor) Login(email, password string) (*models.TokenPair, *http.Cookie, error)

Login allows users to login and will return an access token on successful login

func (Interactor) Logout

func (i Interactor) Logout() *http.Cookie

func (Interactor) NewService

func (i Interactor) NewService(user *models.User, name, description, url string) (*models.Service, error)

func (Interactor) Refresh

func (i Interactor) Refresh(token string) (*models.TokenPair, error)

func (Interactor) Register

func (i Interactor) Register(email, password string) error

type LogicHandler

type LogicHandler interface {
	Register(email, password string) error
	Login(email, password string) (*models.TokenPair, *http.Cookie, error)
	Refresh(token string) (*models.TokenPair, error)
	Logout() *http.Cookie
	AuthCheck(w http.ResponseWriter, r *http.Request) (*models.User, error)
	NewService(user *models.User, name, description, url string) (*models.Service, error)

	FormatSelf(user *models.User) interface{}
	FormatService(svc *models.Service) interface{}
	FormatServices(svx []*models.Service) interface{}
	FormatTimedResponses(tr []*models.TimedResponse) interface{}

	GetServiceByID(user *models.User, id string) (*models.Service, error)
	GetServices(user *models.User) ([]*models.Service, error)
	GetTimedResponsesByServiceID(user *models.User, id string, limit int, reverse bool) ([]*models.TimedResponse, error)
	GetTimedResponseRange(user *models.User, id string, from, to time.Time) ([]*models.TimedResponse, error)
}

LogicHandler is the interface that must implement the struct holding the usecases. The interactor struct must implement this interface. This interface is the main entrypoint for the router.

func NewInteractor

NewInteractor will return a new Interactor struct with all the required dependecies injected. This interactor implements the LogicHandler interface and thus should be provided to the router.

type Scheduler

type Scheduler interface {
	Start(svc *models.Service) error
	Restart(svc *models.Service) error
}

type StorageProvider

type StorageProvider interface {
	SaveService(user *models.User, svc *models.Service) error
	SaveRawService(svc *models.Service) error
	SaveUser(usr *models.User) error

	GetUserByEmail(email string) (*models.User, error)
	GetUserByID(id string) (*models.User, error)

	GetTimedResponses(svc *models.Service, limit int, reverse bool) ([]*models.TimedResponse, error)
	GetTimedResponseRange(svc *models.Service, from, to time.Time) ([]*models.TimedResponse, error)
	CountTimedResponses(svc *models.Service) (int, error)
	SaveTimedResponse(tr *models.TimedResponse) error

	GetAllServices() ([]*models.Service, error)
	GetServiceByID(id string) (*models.Service, error)
	GetServices(user *models.User) ([]*models.Service, error)
}

StorageProvider is a storage interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL