domain

package
Version: v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2019 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MalformedRequest = UseCaseError{Code: 000, Reason: "Bad request", Fix: "See documentation and try again"}
	InvalidToken     = UseCaseError{Code: 001, Reason: "Invalid Token", Fix: "Use a valid token or create a new device to obtain a new one"}
)

BasicErrors

View Source
var (
	RouterAlreadyExists = UseCaseError{Code: 100, Reason: "Router already exists", Fix: "Use the router"}
	RouterNotFound      = UseCaseError{Code: 101, Reason: "Router Not Found", Fix: "Create a new router or use an existing router"}
)

RouterErrors

View Source
var (
	DriverNotFound       = UseCaseError{Code: 201, Reason: "Driver not found", Fix: "Use other driver. See available drivers in /driver/available"}
	AuthModeNotSupported = UseCaseError{Code: 202, Reason: "Driver does not support requested auth mode", Fix: "Use a supported auth mode listed in /routers/{name}/authmodes"}
)

Driver Errors

Functions

This section is empty.

Types

type AddRouterRequest

type AddRouterRequest struct {
	Name     string                   `validate:"required"`
	IP       percorsodrivers.IP       `validate:"required"`
	AuthMode percorsodrivers.AuthMode `validate:"required"`
	AuthData percorsodrivers.AuthData `validate:"required"`
	Driver   string                   `validate:"required"`
}

AddRouterRequest represent a request for AddRouterCase

type AddRouterResponse

type AddRouterResponse struct {
	Token string `json:"token"`
}

type Cipher

type Cipher interface {
	Encrypt(source []byte, key []byte) []byte
	Decrypt(source []byte, key []byte) []byte
}

type DeleteRouterRequest

type DeleteRouterRequest struct {
	RouterName string `validate:"required"`
}

DeleteRouterRequest request for DeleteRouterCase

type Driver

type Driver interface {
	Name() string
	Version() string
	GetAvailableCommands() []percorsodrivers.CommandName
	GetAuthModes() []percorsodrivers.AuthMode
	Execute(command percorsodrivers.Command, config percorsodrivers.RouterConfig) (percorsodrivers.Payload, percorsodrivers.DriverError)
}

type DriverStore

type DriverStore interface {
	GetDriverByName(name string) (Driver, error)
	GetAllDrivers() []Driver
}

type DriversResponse

type DriversResponse struct {
	Name    string
	Version string
}

DriversResponse represents a driver for serialize (like json serialize)

type ExecutionData

type ExecutionData struct {
	Commands []percorsodrivers.Command `validate:"required"`
	Token    string                    `validate:"required"`
}

type ExecutionResponse

type ExecutionResponse struct {
	Command percorsodrivers.CommandName
	State   ExecutionState
	Payload percorsodrivers.Payload
}

ExecutionResponse is a reponse for ONE command exectution

type ExecutionState

type ExecutionState string

ExecutionState is the final command state

const (
	Successful  ExecutionState = "successful"
	Failed      ExecutionState = "failed"
	Unsupported ExecutionState = "unsupported"
)

Execution states

type GetAuthModesRequest

type GetAuthModesRequest struct {
	DriverName string `validate:"required"`
}

type GetAvailableCommandsRequest

type GetAvailableCommandsRequest struct {
	RouterName string `validate:"required"`
}

GetAvailableCommandsRequest is a request for GetAvailableCommandsCase UseCase. Is required to have a RouterName

type Presenter

type Presenter interface {
	PresentInformation(interface{})
	PresentError(UseCaseError)
}

type Router

type Router struct {
	Name   string
	Driver Driver
	Cipher Cipher
	Config percorsodrivers.RouterConfig
}

Router is a physical router

func (Router) CanExecute

func (router Router) CanExecute(commandToExecute percorsodrivers.CommandName) bool

CanExecute the command in this router?

func (Router) DecryptConfigWithToken

func (router Router) DecryptConfigWithToken(token string) error

Decrypts RouterConfig with token using Router's Cipher

func (Router) EncryptConfigWithToken

func (router Router) EncryptConfigWithToken(token string) error

Encrypts RouterConfig with token using Router's Cipher

func (Router) Execute

func (router Router) Execute(command percorsodrivers.Command) (rPayload percorsodrivers.Payload, rErr percorsodrivers.DriverError)

Execute command to this router using its internal driver. Also checks if the command is not supported before it executes it. If driver panics, here is recovered and returns an ExecutrionError.

func (Router) GetAuthModes

func (router Router) GetAuthModes() []percorsodrivers.AuthMode

GetAuthModes is a proxy to router driver's GetAuthModes

func (Router) GetAvailableCommands

func (router Router) GetAvailableCommands() []percorsodrivers.CommandName

GetAvailableCommands is a proxy to router driver's GetAvailableCommands

func (Router) SupportsAuthMode

func (router Router) SupportsAuthMode(mode percorsodrivers.AuthMode) bool

type RouterBuilder

type RouterBuilder struct {
	DriverStore DriverStore
	Cipher      Cipher
}

RouterBuilder builds routers only knowing his name, driver name and ip

func (RouterBuilder) BuildRouterWith

func (build RouterBuilder) BuildRouterWith(name, driverName string, config percorsodrivers.RouterConfig) Router

BuildRouterWith his name, drivername and ip

type RouterExecuteRequest

type RouterExecuteRequest struct {
	Router string        `validate:"required"`
	Data   ExecutionData `validate:"required"`
}

RouterExecuteRequest is a request for RouterExecuteCase. For a router, executes an array of commands asynchronous

type RouterRepository

type RouterRepository interface {
	Save(router Router) error
	DeleteWithName(name string) error
	ExistsWithName(name string) bool
	GetAll() []Router
	GetOneByName(name string) (Router, error)
}

type RouterResponse

type RouterResponse struct {
	Name     string
	IP       string
	Driver   string
	AuthMode string
}

RouterResponse represents a router for serialize (like json serialize)

type Tokenizer

type Tokenizer func() []byte

type UseCase

type UseCase func(Presenter, UseCaseRequest)

func NewAddRouterCase

func NewAddRouterCase(routerRepo RouterRepository, driverStore DriverStore, cipher Cipher, createToken Tokenizer, validator Validator) UseCase

NewAddRouterCase creates a UseCase that adds a router if doesn't already exist

func NewDeleteRouterCase

func NewDeleteRouterCase(routerRepo RouterRepository, validator Validator) UseCase

NewDeleteRouterCase creates a UseCase that deletes a router if already exists

func NewGetAllDriversCase

func NewGetAllDriversCase(driverStore DriverStore) UseCase

NewGetAllDriversCase creates a UseCase that gets all drivers loaded previously by the Core

func NewGetAllRoutersCase

func NewGetAllRoutersCase(routerRepo RouterRepository) UseCase

NewGetAllRoutersCase creates a UseCase that gets all routers

func NewGetAuthModesCase

func NewGetAuthModesCase(driverStore DriverStore, validator Validator) UseCase

NewGetAuthModesCase creates a UseCase that gets all authmodes for one router

func NewGetAvailableCommandsCase

func NewGetAvailableCommandsCase(routerRepo RouterRepository, validator Validator) UseCase

NewGetAvailableCommandsCase creates a UseCase that gets all commands for router

func NewRouterExecuteCase

func NewRouterExecuteCase(routerRepo RouterRepository, validator Validator) UseCase

NewRouterExecuteCase creates a UseCase that gets all commands for router

type UseCaseError

type UseCaseError struct {
	Code   uint16
	Reason string
	Fix    string
}

UseCaseError is an error that can return a UseCase

func (UseCaseError) Error

func (caseErr UseCaseError) Error() string

type UseCaseRequest

type UseCaseRequest interface{}
var EmptyRequest UseCaseRequest = struct{}{}

type Validator

type Validator interface {
	Validate(interface{}) error
}

Jump to

Keyboard shortcuts

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