sm

package
v0.0.0-...-6049a1a Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EasyTVApiKeyHeader  = "X-Easytv-Key"
	EasyTVSessionHeader = "X-Easytv-Session"

	SessionExpiration = 60 * 20 // 20 minutes

	RoleAdmin        = 0
	RoleContentOwner = 1

	OK = 200

	// Generic errors
	CodeMissingInput        = -400
	CodeNoSession           = -401
	CodeNotFound            = -404
	CodeInternalServerError = -500

	// Domain errors
	CodeTaskNotDisabled                    = -1
	CodeTaskHasActiveJobs                  = -2
	CodeJobAlreadyCanceled                 = -3
	CodeJobAlreadyCompleted                = -4
	CodeEmptyAsset                         = -5
	CodeTaskAlreadyExists                  = -8
	CodeTaskNoInputParameter               = -9
	CodeTaskNoOutputParameter              = -10
	CodeInvalidStartUrl                    = -11
	CodeInvalidCancelUrl                   = -12
	CodeInvalidInput                       = -13
	CodeInvalidPublicationdate             = -14
	CodeInvalidExpirationDate              = -15
	CodeJobStatusNotUpdatable              = -16
	CodeForbiddenAsset                     = -17
	CodeInvalidOutput                      = -18
	CodeNotCompletable                     = -19
	CodeLinkedParameterNotTheSameType      = -20
	CodeLinkedOutputNotFound               = -21
	CodeServiceNameInUse                   = -22
	CodeContentOwnerNameExists             = -23
	CodeContentOwnerUsernameExists         = -24
	CodeContentOwnerEmailExists            = -25
	CodeJobWithDisabledTasks               = -26
	CodePasswordIsTooShort                 = -27
	CodeInvalidCredentials                 = -28
	CodeNewPasswordDoesntMatchVerification = -29
)

Variables

View Source
var ErrAdminNameTooShort = errors.New("Admin name is too short")
View Source
var ErrEmptyInput = errors.New("Input can't be empty")
View Source
var ErrEmptyOutput = errors.New("Output can't be empty")
View Source
var ErrEmptyTasks = errors.New("There should be at least on task for a job")
View Source
var ErrInvalidCancelUrl = errors.New("invalid cancel url")
View Source
var ErrInvalidCredentials = errors.New("credentials were not valid")
View Source
var ErrInvalidExpirationDate = errors.New("Expiration date should be after publication date")
View Source
var ErrInvalidInputType = errors.New("invalid input type")
View Source
var ErrInvalidOutputType = errors.New("invalid output type")
View Source
var ErrInvalidPublicationDate = errors.New("Publication date should be in the future")
View Source
var ErrInvalidStartUrl = errors.New("invalid start url")
View Source
var ErrJobIsCanceled = errors.New("Job is canceled")
View Source
var ErrJobIsCompleted = errors.New("Job is completed")
View Source
var ErrJobStatusNotUpdatable = errors.New(
	"Job status can't be updated because it is copmleted")
View Source
var ErrMissingTaskID = errors.New("The task_id is missing in the input")
View Source
var ErrNotFound = errors.New("Whatever you are looking for, it doesn't exist")
View Source
var ErrOwnerEmailExists = errors.New("Owner email exists")
View Source
var ErrOwnerEmailTooShort = errors.New("Owner email too short")
View Source
var ErrOwnerNameExists = errors.New("Owner name exists")
View Source
var ErrOwnerNameTooShort = errors.New("Owner name too short")
View Source
var ErrOwnerUsernameExists = errors.New("Owner username exists")
View Source
var ErrOwnerUsernameTooShort = errors.New("Owner username too short")
View Source
var ErrPasswordTooShort = errors.New("Admin password too short")
View Source
var ErrServiceDescTooShort = errors.New("Desc is too short")
View Source
var ErrServiceNameInUse = errors.New("Name is in use")
View Source
var ErrServiceNameTooShort = errors.New("Name is too short")
View Source
var ErrTaskAlreadyExists = errors.New("Task already exists")
View Source
var ErrTaskDescTooShort = errors.New("Task desc is short")
View Source
var ErrTaskHasJobStepsInProgress = errors.New("Task has job steps in progress")
View Source
var ErrTaskIsEnabled = errors.New("Task is enabled")
View Source
var ErrTaskNameTooShort = errors.New("Task name is short")

Functions

func ParamTypeStr

func ParamTypeStr(param_type ParamType) string

ParamTypeStr returns a string name of the given ParamType

Types

type AdminRepository

type AdminRepository interface {
	GetByID(id int64) (*AdminUser, error)

	GetByUsername(username string) (*AdminUser, error)

	Insert(user *AdminUser) error

	SavePassword(admin *AdminUser) error
}

type AdminService

type AdminService interface {
	Login(username, password string) (*AdminUser, error)

	CreateAdminUser(username, password string) (*AdminUser, error)

	ChangePassword(admin_id int64, old_password, new_password string) error
}

func NewAdminService

func NewAdminService(repository AdminRepository) AdminService

type AdminUser

type AdminUser struct {
	ID       int64
	Username string
	Password string
}

type Asset

type Asset struct {
	ID       int64
	JobID    int64
	UrlParam string
	Path     string
	Size     int64
}

type AssetRepository

type AssetRepository interface {
	Create(asset *Asset) error

	GetAssetsForJob(job_id int64, assets *[]*Asset) error

	GetAssetsForUser(content_owner_id int64, assets *[]*Asset) error

	DeleteAssetsForJob(job_id int64) error

	GetAsset(asset_id int64) (*Asset, error)

	GetAssetByUrlParam(url_param string) (*Asset, error)
}

type AssetService

type AssetService interface {
	CreateAsset(step_id int64,
		module *Module,
		file multipart.File,
		filename string,
		filesize int64) (*Asset, error)

	GC() error
}

func NewAssetService

func NewAssetService(repository AssetRepository,
	job_repository JobRepository,
	task_repository TaskRepository) AssetService

type ContentOwner

type ContentOwner struct {
	ID       int64
	Username string
	Password string
	Email    string
	Name     string
}

type ContentOwnerRepository

type ContentOwnerRepository interface {
	NameExists(name string) (bool, error)

	UsernameExists(username string) (bool, error)

	EmailExists(email string) (bool, error)

	GetContentOwnerByUsername(username string) (*ContentOwner, error)

	GetContentOwnerByID(owner *ContentOwner) error

	Insert(owner *ContentOwner) error

	SavePassword(owner *ContentOwner) error

	Save(owner *ContentOwner) error

	GetAll() ([]*ContentOwner, error)
}

type ContentOwnerService

type ContentOwnerService interface {
	CreateContentOwner(name, username, email, password string) (*ContentOwner, error)

	GenerateRandomPassword(n int) string

	Login(username, password string) (*ContentOwner, error)

	ChangePassword(user_id int64, old_password, new_password string) error

	ResetPassword(user_id int64, new_password string) error

	Update(user_id int64, fields map[string]string) error
}

service

func NewContentOwnerService

func NewContentOwnerService(repo ContentOwnerRepository) ContentOwnerService

type ErrInvalidTaskInput

type ErrInvalidTaskInput struct{ Message string }

func (*ErrInvalidTaskInput) Error

func (e *ErrInvalidTaskInput) Error() string

type ErrInvalidTaskOutput

type ErrInvalidTaskOutput struct{ Message string }

func (*ErrInvalidTaskOutput) Error

func (e *ErrInvalidTaskOutput) Error() string

type ErrLinkedParameterNotTheSameType

type ErrLinkedParameterNotTheSameType struct {
	InputName  string
	OutputName string
}

func (*ErrLinkedParameterNotTheSameType) Error

type ErrModuleIsDisabled

type ErrModuleIsDisabled struct{ ModuleID int64 }

func (*ErrModuleIsDisabled) Error

func (e *ErrModuleIsDisabled) Error() string

type ErrTaskIsDisabled

type ErrTaskIsDisabled struct{ TaskID int64 }

func (*ErrTaskIsDisabled) Error

func (e *ErrTaskIsDisabled) Error() string

type ErrTaskNotFound

type ErrTaskNotFound struct{ TaskID int64 }

func (*ErrTaskNotFound) Error

func (e *ErrTaskNotFound) Error() string

type ErrTaskOutputNotFound

type ErrTaskOutputNotFound struct{ Name string }

func (*ErrTaskOutputNotFound) Error

func (e *ErrTaskOutputNotFound) Error() string

type Job

type Job struct {
	ID              int64
	IsCompleted     bool
	IsCanceled      bool
	CreationDate    time.Time
	CompletionDate  *time.Time
	PublicationDate time.Time
	ExpirationDate  time.Time
	Owner           ContentOwner
	Status          string
	CurrentStep     int
	Steps           []*JobStep
}

type JobParam

type JobParam struct {
	DataType ParamType
	Value    interface{}
	// can be linked with an output param of the previous step
	LinkedOutputName *string
}

type JobRepository

type JobRepository interface {
	TaskHasActiveJobs(task_id int64) (bool, error)

	GetJobsStepsForModule(
		module_id,
		limit,
		before_job_id int64) ([]map[string]interface{}, error)

	GetJobStepForModule(
		step_id, module_id int64) (map[string]interface{}, error)

	GetJobsForContentOwner(
		owner_id, limit, before_job_id int64) ([]*Job, error)

	GetJobByStepID(step_id int64) (*Job, error)

	GetJobByID(job_id int64) (*Job, error)

	GetJobSteps(job_id int64, steps *[]*JobStep) error

	GetParamsForStep(step *JobStep) error

	SaveStatus(job *Job) error

	CreateJob(job *Job) error

	SaveStepProgress(job *Job) error

	SaveFinishedState(job *Job) error

	GetJobsExceedingPublicationDate(
		timestamp time.Time,
		limit, offset_id int64) ([]*Job, error)

	CancelJobsWithExceedingPublicatinDate(timestamp time.Time) error

	GetJobsExceedingExpirationDate(
		timestamp time.Time,
		limit, offset_id int64) ([]*Job, error)

	CancelJobsWithExceedingExpirationDate(timestamp time.Time) error

	GetNewExpiredJobsAt(
		timestamp time.Time,
		limit int64,
		offset_id int64) ([]*Job, error)

	ExpireJobsBefore(timestamp time.Time) error

	DeleteParamsForJob(job_id int64) error
}

type JobService

type JobService interface {
	SetJobStatusForStep(step_id int64, status string) error

	CreateJob(user_id, publication_date, expiration_date int64,
		tasks []map[string]interface{}) (*Job, error)

	CancelJobsWithExceedingPublicationDate() error

	CancelJobsWithExceedingExpirationDate() error

	CancelJobAsModule(module *Module, step_id int64) error

	CancelJobAsOwner(owner_id, job_id int64) error

	SendCancelRequest(job *Job, task *Task, module *Module) error

	// The job is passed by value in order to make the function
	// safe to call as a goroutine
	PerformNextStepOfJob(job Job)

	FinishJobStep(step_id int64, module *Module, output map[string]interface{}) error
}

func NewJobService

func NewJobService(repository JobRepository,
	task_repository TaskRepository,
	module_repository ModuleRepository,
	owner_repository ContentOwnerRepository) JobService

type JobStep

type JobStep struct {
	ID     int64
	TaskID int64
	// The `key` of the map is the name of the parameter
	Input  map[string]JobParam
	Output map[string]JobParam
}

type Module

type Module struct {
	ID          int64
	Name        string
	Description string
	ApiKey      string
	Enabled     bool
}

type ModuleRepository

type ModuleRepository interface {
	CreateModule(module *Module) error

	IsNameInUse(name string) (bool, error)

	SetAvailability(id int64, enabled bool) error

	GetModules(modules *[]map[string]interface{}) error

	GetModulesOBJ(modules *[]*Module) error

	GetModuleByKey(api_key string) (*Module, error)

	GetModuleByID(id int64) (*Module, error)

	GenerateApiKey(module_name string) string

	Save(module *Module) error
}

type ModuleService

type ModuleService interface {
	CreateService(name, description string) (*Module, error)

	UpdateName(id int64, name string) error

	UpdateDescription(id int64, description string) error

	Update(id int64, name string, description string) error

	SetAvailability(id int64, enable bool) error

	RenewApiKey(id int64) (*Module, error)
}

func NewModuleService

func NewModuleService(repo ModuleRepository) ModuleService

type ParamType

type ParamType int

ParamType is the type of an input or output parameter of a task

const (
	IntParam             ParamType = 0
	StringParam          ParamType = 1
	DoubleParam          ParamType = 2
	UnsupportedTypeParam ParamType = -1
)

func GetParamType

func GetParamType(value interface{}) ParamType

func GetParamTypeFromSting

func GetParamTypeFromSting(value string) ParamType

type Task

type Task struct {
	ID          int64
	ModuleID    int64
	Name        string
	Description string
	StartUrl    string
	CancelUrl   string
	Enabled     bool
	Deleted     bool
	Input       map[string]ParamType
	Output      map[string]ParamType
}

type TaskRepository

type TaskRepository interface {
	CreateTask(task *Task) error

	NameExists(name string) (bool, error)

	GetTask(id int64) (*Task, error)

	GetTasks(module_id int64, fetch_deleted bool) ([]*Task, error)

	SetAvailability(id int64, enabled bool) error

	DeleteTask(id int64) error

	Save(task *Task) error

	SaveVars(task *Task, is_input bool) error
}

type TaskService

type TaskService interface {
	RegisterTask(
		module_id int64,
		name, description, start_url, cancel_url string,
		input, output map[string]ParamType) (*Task, error)

	SetAvailability(id int64, enabled bool) error

	DeleteTask(id int64) error

	Update(id int64, fields map[string]string) error

	UpdateVars(id int64, data map[string]ParamType, is_input bool) error
}

Service

func NewTaskService

func NewTaskService(
	repository TaskRepository, job_repository JobRepository) TaskService

Directories

Path Synopsis
cmd
api
srt

Jump to

Keyboard shortcuts

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