server

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateTokensAndSetCookies

func GenerateTokensAndSetCookies(c echo.Context, user *api.Principal, mode string, secret string) error

GenerateTokensAndSetCookies generates jwt token and saves it to the http-only cookie.

func JWTMiddleware

func JWTMiddleware(l *zap.Logger, p api.PrincipalService, next echo.HandlerFunc, mode string, secret string) echo.HandlerFunc

JWTMiddleware validates the access token. If the access token is about to expire or has expired and the request has a valid refresh token, it will try to generate new access token and refresh token.

Types

type ActivityManager

type ActivityManager struct {
	// contains filtered or unexported fields
}

ActivityManager is the activity manager.

func NewActivityManager

func NewActivityManager(server *Server, activityService api.ActivityService) *ActivityManager

NewActivityManager creates an activity manager.

func (*ActivityManager) CreateActivity

func (m *ActivityManager) CreateActivity(ctx context.Context, create *api.ActivityCreate, meta *ActivityMeta) (*api.Activity, error)

CreateActivity creates an activity.

type ActivityMeta

type ActivityMeta struct {
	// contains filtered or unexported fields
}

ActivityMeta is the activity metadata.

type AnomalyScanner

type AnomalyScanner struct {
	// contains filtered or unexported fields
}

AnomalyScanner is the anomaly scanner.

func NewAnomalyScanner

func NewAnomalyScanner(logger *zap.Logger, server *Server) *AnomalyScanner

NewAnomalyScanner creates a anomaly scanner

func (*AnomalyScanner) Run

func (s *AnomalyScanner) Run(ctx context.Context, wg *sync.WaitGroup)

Run will run the anomaly scanner once.

type BackupRunner

type BackupRunner struct {
	// contains filtered or unexported fields
}

BackupRunner is the backup runner scheduling automatic backups.

func NewBackupRunner

func NewBackupRunner(logger *zap.Logger, server *Server, backupRunnerInterval time.Duration) *BackupRunner

NewBackupRunner creates a new backup runner.

func (*BackupRunner) Run

func (s *BackupRunner) Run(ctx context.Context, wg *sync.WaitGroup)

Run is the runner for backup runner.

type CacheService

type CacheService struct {
	// contains filtered or unexported fields
}

CacheService implements a cache.

func NewCacheService

func NewCacheService(logger *zap.Logger) *CacheService

NewCacheService creates a cache service.

func (*CacheService) FindCache

func (s *CacheService) FindCache(namespace api.CacheNamespace, id int, entry interface{}) (bool, error)

FindCache finds the value in cache.

func (*CacheService) UpsertCache

func (s *CacheService) UpsertCache(namespace api.CacheNamespace, id int, entry interface{}) error

UpsertCache upserts the value to cache.

type Claims

type Claims struct {
	Name string `json:"name"`
	jwt.StandardClaims
}

Claims creates a struct that will be encoded to a JWT. We add jwt.StandardClaims as an embedded type, to provide fields like name.

type DataUpdateTaskExecutor

type DataUpdateTaskExecutor struct {
	// contains filtered or unexported fields
}

DataUpdateTaskExecutor is the data update (DML) task executor.

func (*DataUpdateTaskExecutor) RunOnce

func (exec *DataUpdateTaskExecutor) RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, result *api.TaskRunResultPayload, err error)

RunOnce will run the data update (DML) task executor once.

type DatabaseBackupTaskExecutor

type DatabaseBackupTaskExecutor struct {
	// contains filtered or unexported fields
}

DatabaseBackupTaskExecutor is the task executor for database backup.

func (*DatabaseBackupTaskExecutor) RunOnce

func (exec *DatabaseBackupTaskExecutor) RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, result *api.TaskRunResultPayload, err error)

RunOnce will run database backup once.

type DatabaseCreateTaskExecutor

type DatabaseCreateTaskExecutor struct {
	// contains filtered or unexported fields
}

DatabaseCreateTaskExecutor is the database create task executor.

func (*DatabaseCreateTaskExecutor) RunOnce

func (exec *DatabaseCreateTaskExecutor) RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, result *api.TaskRunResultPayload, err error)

RunOnce will run the database create task executor once.

type DatabaseRestoreTaskExecutor

type DatabaseRestoreTaskExecutor struct {
	// contains filtered or unexported fields
}

DatabaseRestoreTaskExecutor is the task executor for database restore.

func (*DatabaseRestoreTaskExecutor) RunOnce

func (exec *DatabaseRestoreTaskExecutor) RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, result *api.TaskRunResultPayload, err error)

RunOnce will run database restore once.

type DefaultTaskExecutor

type DefaultTaskExecutor struct {
	// contains filtered or unexported fields
}

DefaultTaskExecutor is the default task executor.

func (*DefaultTaskExecutor) RunOnce

func (exec *DefaultTaskExecutor) RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, result *api.TaskRunResultPayload, err error)

RunOnce will run the default task executor once.

type SchemaSyncer

type SchemaSyncer struct {
	// contains filtered or unexported fields
}

SchemaSyncer is the schema syncer.

func NewSchemaSyncer

func NewSchemaSyncer(logger *zap.Logger, server *Server) *SchemaSyncer

NewSchemaSyncer creates a schema syncer.

func (*SchemaSyncer) Run

func (s *SchemaSyncer) Run(ctx context.Context, wg *sync.WaitGroup)

Run will run the schema syncer once.

type SchemaUpdateTaskExecutor

type SchemaUpdateTaskExecutor struct {
	// contains filtered or unexported fields
}

SchemaUpdateTaskExecutor is the schema update (DDL) task executor.

func (*SchemaUpdateTaskExecutor) RunOnce

func (exec *SchemaUpdateTaskExecutor) RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, result *api.TaskRunResultPayload, err error)

RunOnce will run the schema update (DDL) task executor once.

type Server

type Server struct {
	// Asynchronous runners.
	TaskScheduler      *TaskScheduler
	TaskCheckScheduler *TaskCheckScheduler
	SchemaSyncer       *SchemaSyncer
	BackupRunner       *BackupRunner
	AnomalyScanner     *AnomalyScanner

	ActivityManager *ActivityManager

	CacheService api.CacheService

	SettingService          api.SettingService
	PrincipalService        api.PrincipalService
	MemberService           api.MemberService
	PolicyService           api.PolicyService
	ProjectService          api.ProjectService
	ProjectMemberService    api.ProjectMemberService
	ProjectWebhookService   api.ProjectWebhookService
	EnvironmentService      api.EnvironmentService
	InstanceService         api.InstanceService
	InstanceUserService     api.InstanceUserService
	DatabaseService         api.DatabaseService
	TableService            api.TableService
	ColumnService           api.ColumnService
	ViewService             api.ViewService
	IndexService            api.IndexService
	DataSourceService       api.DataSourceService
	BackupService           api.BackupService
	IssueService            api.IssueService
	IssueSubscriberService  api.IssueSubscriberService
	PipelineService         api.PipelineService
	StageService            api.StageService
	TaskService             api.TaskService
	TaskCheckRunService     api.TaskCheckRunService
	ActivityService         api.ActivityService
	InboxService            api.InboxService
	BookmarkService         api.BookmarkService
	VCSService              api.VCSService
	RepositoryService       api.RepositoryService
	AnomalyService          api.AnomalyService
	LabelService            api.LabelService
	DeploymentConfigService api.DeploymentConfigService
	LicenseService          enterprise.LicenseService
	SheetService            api.SheetService
	// contains filtered or unexported fields
}

Server is the Bytebase server.

func NewServer

func NewServer(logger *zap.Logger, loggerLevel *zap.AtomicLevel, version string, host string, port int, frontendHost string, frontendPort, datastorePort int, mode string, dataDir string, backupRunnerInterval time.Duration, secret string, readonly bool, demo bool, debug bool) *Server

NewServer creates a server.

func (*Server) GetEcho

func (server *Server) GetEcho() *echo.Echo

GetEcho returns the echo server.

func (*Server) InitSubscription

func (server *Server) InitSubscription()

InitSubscription will initial the subscription cache in memory

func (*Server) Run

func (server *Server) Run(ctx context.Context) error

Run will run the server.

func (*Server) ScheduleNextTaskIfNeeded

func (s *Server) ScheduleNextTaskIfNeeded(ctx context.Context, pipeline *api.Pipeline) (*api.Task, error)

ScheduleNextTaskIfNeeded tries to schedule the next task if needed. Returns nil if no task applicable can be scheduled

func (*Server) Shutdown

func (server *Server) Shutdown(ctx context.Context)

Shutdown will shut down the server.

type TaskCheckDatabaseConnectExecutor

type TaskCheckDatabaseConnectExecutor struct {
	// contains filtered or unexported fields
}

TaskCheckDatabaseConnectExecutor is the task check database connect executor.

func (*TaskCheckDatabaseConnectExecutor) Run

func (exec *TaskCheckDatabaseConnectExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error)

Run will run the task check database connector executor once.

type TaskCheckExecutor

type TaskCheckExecutor interface {
	// Run will be called periodically by the task check scheduler
	Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error)
}

TaskCheckExecutor is the task check executor.

func NewTaskCheckDatabaseConnectExecutor

func NewTaskCheckDatabaseConnectExecutor(logger *zap.Logger) TaskCheckExecutor

NewTaskCheckDatabaseConnectExecutor creates a task check database connect executor.

func NewTaskCheckMigrationSchemaExecutor

func NewTaskCheckMigrationSchemaExecutor(logger *zap.Logger) TaskCheckExecutor

NewTaskCheckMigrationSchemaExecutor creates a task check migration schema executor.

func NewTaskCheckStatementAdvisorExecutor

func NewTaskCheckStatementAdvisorExecutor(logger *zap.Logger) TaskCheckExecutor

NewTaskCheckStatementAdvisorExecutor creates a task check statement advisor executor.

func NewTaskCheckTimingExecutor

func NewTaskCheckTimingExecutor(logger *zap.Logger) TaskCheckExecutor

NewTaskCheckTimingExecutor creates a task check timing executor.

type TaskCheckMigrationSchemaExecutor

type TaskCheckMigrationSchemaExecutor struct {
	// contains filtered or unexported fields
}

TaskCheckMigrationSchemaExecutor is the task check migration schema executor.

func (*TaskCheckMigrationSchemaExecutor) Run

func (exec *TaskCheckMigrationSchemaExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error)

Run will run the task check migration schema executor once.

type TaskCheckScheduler

type TaskCheckScheduler struct {
	// contains filtered or unexported fields
}

TaskCheckScheduler is the task check scheduler.

func NewTaskCheckScheduler

func NewTaskCheckScheduler(logger *zap.Logger, server *Server) *TaskCheckScheduler

NewTaskCheckScheduler creates a task check scheduler.

func (*TaskCheckScheduler) Register

func (s *TaskCheckScheduler) Register(taskType string, executor TaskCheckExecutor)

Register will register the task check executor.

func (*TaskCheckScheduler) Run

func (s *TaskCheckScheduler) Run(ctx context.Context, wg *sync.WaitGroup)

Run will run the task check scheduler once.

func (*TaskCheckScheduler) ScheduleCheckIfNeeded

func (s *TaskCheckScheduler) ScheduleCheckIfNeeded(ctx context.Context, task *api.Task, creatorID int, skipIfAlreadyTerminated bool) (*api.Task, error)

ScheduleCheckIfNeeded schedules a check if needed.

type TaskCheckStatementAdvisorExecutor

type TaskCheckStatementAdvisorExecutor struct {
	// contains filtered or unexported fields
}

TaskCheckStatementAdvisorExecutor is the task check statement advisor executor.

func (*TaskCheckStatementAdvisorExecutor) Run

func (exec *TaskCheckStatementAdvisorExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error)

Run will run the task check statement advisor executor once.

type TaskCheckTimingExecutor

type TaskCheckTimingExecutor struct {
	// contains filtered or unexported fields
}

TaskCheckTimingExecutor is the task check timing executor.

func (*TaskCheckTimingExecutor) Run

func (exec *TaskCheckTimingExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error)

Run will run the task check timing executor once.

type TaskExecutor

type TaskExecutor interface {
	// RunOnce will be called periodically by the scheduler until terminated is true.
	//
	// NOTE
	//
	// 1. It's possible that err could be non-nil while terminated is false, which
	// usually indicates a transient error and will make scheduler retry later.
	// 2. If err is non-nil, then the detail field will be ignored since info is provided in the err.
	RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, result *api.TaskRunResultPayload, err error)
}

TaskExecutor is the task executor.

func NewDataUpdateTaskExecutor

func NewDataUpdateTaskExecutor(logger *zap.Logger) TaskExecutor

NewDataUpdateTaskExecutor creates a data update (DML) task executor.

func NewDatabaseBackupTaskExecutor

func NewDatabaseBackupTaskExecutor(logger *zap.Logger) TaskExecutor

NewDatabaseBackupTaskExecutor creates a new database backup task executor.

func NewDatabaseCreateTaskExecutor

func NewDatabaseCreateTaskExecutor(logger *zap.Logger) TaskExecutor

NewDatabaseCreateTaskExecutor creates a database create task executor.

func NewDatabaseRestoreTaskExecutor

func NewDatabaseRestoreTaskExecutor(logger *zap.Logger) TaskExecutor

NewDatabaseRestoreTaskExecutor creates a new database restore task executor.

func NewDefaultTaskExecutor

func NewDefaultTaskExecutor(logger *zap.Logger) TaskExecutor

NewDefaultTaskExecutor creates a default task executor.

func NewSchemaUpdateTaskExecutor

func NewSchemaUpdateTaskExecutor(logger *zap.Logger) TaskExecutor

NewSchemaUpdateTaskExecutor creates a schema update (DDL) task executor.

type TaskScheduler

type TaskScheduler struct {
	// contains filtered or unexported fields
}

TaskScheduler is the task scheduler.

func NewTaskScheduler

func NewTaskScheduler(logger *zap.Logger, server *Server) *TaskScheduler

NewTaskScheduler creates a new task scheduler.

func (*TaskScheduler) Register

func (s *TaskScheduler) Register(taskType string, executor TaskExecutor)

Register will register a task executor.

func (*TaskScheduler) Run

func (s *TaskScheduler) Run(ctx context.Context, wg *sync.WaitGroup)

Run will run the task scheduler.

func (*TaskScheduler) ScheduleIfNeeded

func (s *TaskScheduler) ScheduleIfNeeded(ctx context.Context, task *api.Task) (*api.Task, error)

ScheduleIfNeeded schedules the task if its required check does not contain error in the latest run

Jump to

Keyboard shortcuts

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