api

package
v0.0.0-...-5167e8f Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: AGPL-3.0 Imports: 128 Imported by: 0

Documentation

Index

Constants

View Source
const BaseUrl = "/api/v4"
View Source
const JwtSecretEnv = "CPS_JWT_SECRET" //nolint:gosec

Variables

This section is empty.

Functions

func GetSessionKeyVar

func GetSessionKeyVar(logger zerolog.Logger) []byte

func RegisterRoutes

func RegisterRoutes(
	ctx context.Context,
	conf config.CanopsisConf,
	router gin.IRouter,
	security Security,
	enforcer libsecurity.Enforcer,
	linkGenerator link.Generator,
	dbClient mongo.DbClient,
	dbExportClient mongo.DbClient,
	pgPoolProvider postgres.PoolProvider,
	amqpChannel amqp.Channel,
	apiConfigProvider config.ApiConfigProvider,
	timezoneConfigProvider config.TimezoneConfigProvider,
	templateConfigProvider config.TemplateConfigProvider,
	pbhEntityTypeResolver libpbehavior.EntityTypeResolver,
	pbhComputeChan chan<- rpc.PbehaviorRecomputeEvent,
	entityPublChan chan<- libentityservice.ChangeEntityMessage,
	entityCleanerTaskChan chan<- entity.CleanTask,
	exportExecutor export.TaskExecutor,
	techMetricsTaskExecutor techmetrics.TaskExecutor,
	publisher amqp.Publisher,
	userInterfaceConfig config.UserInterfaceConfigProvider,
	websocketHub websocket.Hub,
	websocketStore websocket.Store,
	broadcastMessageChan chan<- bool,
	metricsEntityMetaUpdater metrics.MetaUpdater,
	metricsUserMetaUpdater metrics.MetaUpdater,
	authorProvider author.Provider,
	healthcheckStore healthcheck.Store,
	tplExecutor libtemplate.Executor,
	stateSettingsUpdatesChan chan statesetting.RuleUpdatedMessage,
	enableSameServiceNames bool,
	eventGenerator libevent.Generator,
	logger zerolog.Logger,
)

RegisterRoutes nolint: contextcheck

func RegisterValidators

func RegisterValidators(client mongo.DbClient)

Types

type API

type API interface {
	// Run starts http server.
	Run(context.Context) error
	// AddRouter adds new routes.
	AddRouter(Router)
	// AddWorker adds new worker.
	AddWorker(string, Worker)
	// AddNoRoute adds handlers for no route.
	AddNoRoute(...gin.HandlerFunc)
	// AddNoMethod adds handlers for no method.
	AddNoMethod(...gin.HandlerFunc)
	// SetWebsocketHub sets websocket hub.
	SetWebsocketHub(websocket.Hub)
	// GetWebsocketHub gets websocket hub.
	GetWebsocketHub() websocket.Hub
}

API is used to implement API http server.

func Default

func Default(
	ctx context.Context,
	flags Flags,
	enforcer libsecurity.Enforcer,
	p *ConfigProviders,
	logger zerolog.Logger,
	pgPoolProvider postgres.PoolProvider,
	metricsEntityMetaUpdater metrics.MetaUpdater,
	metricsUserMetaUpdater metrics.MetaUpdater,
	exportExecutor export.TaskExecutor,
	linkGenerator link.Generator,
	deferFunc DeferFunc,
	overrideDocs bool,
) (API, fs.ReadFileFS, error)

func New

func New(
	addr string,
	deferFunc DeferFunc,
	logger zerolog.Logger,
) API

New creates new api.

type ConfigProviders

type ConfigProviders struct {
	DataStorageConfigProvider   *config.BaseDataStorageConfigProvider
	TimezoneConfigProvider      *config.BaseTimezoneConfigProvider
	ApiConfigProvider           *config.BaseApiConfigProvider
	TemplateConfigProvider      *config.BaseTemplateConfigProvider
	UserInterfaceConfigProvider *config.BaseUserInterfaceConfigProvider
}

type CookieOptions

type CookieOptions struct {
	FileAccessName string
	MaxAge         int
}

func DefaultCookieOptions

func DefaultCookieOptions() CookieOptions

type DeferFunc

type DeferFunc func(ctx context.Context)

type FatalWorkerError

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

FatalWorkerError should be used in the Worker function with panic() call, when there is a need to stop the api, when worker fails. the worker will be recovered from the panic, but it won't be restarted and the api will be stopped normally.

func (FatalWorkerError) Error

func (e FatalWorkerError) Error() string

type Flags

type Flags struct {
	Version       bool
	Port          int64
	ConfigDir     string
	Debug         bool
	SecureSession bool
	EnableDocs    bool

	PeriodicalWaitTime                   time.Duration
	IntegrationPeriodicalWaitTime        time.Duration
	EntityCategoryMetaPeriodicalWaitTime time.Duration

	StateSettingRecomputeDelay time.Duration

	// EnableSameServiceNames affects entityservice Create/Update payload validation
	EnableSameServiceNames bool

	LogBody        bool
	LogBodyOnError bool
}

func (*Flags) ParseArgs

func (f *Flags) ParseArgs()

type Router

type Router func(*gin.Engine)

Router is used to implement adding new routes to API.

type Security

type Security interface {
	// GetHttpAuthProviders creates http providers which authenticates each API request.
	GetHttpAuthProviders() []libsecurity.HttpProvider
	// GetAuthProviders creates providers which are used in auth API request.
	GetAuthProviders() []libsecurity.Provider
	// RegisterCallbackRoutes registers callback routes for auth methods.
	RegisterCallbackRoutes(ctx context.Context, router gin.IRouter, client mongo.DbClient, sessionStore sessions.Store)
	// GetAuthMiddleware returns corresponding config auth middlewares.
	GetAuthMiddleware() []gin.HandlerFunc
	// GetFileAuthMiddleware returns auth middleware for files.
	GetFileAuthMiddleware() gin.HandlerFunc
	GetSessionStore() libsession.Store
	GetConfig() libsecurity.Config
	GetPasswordEncoder() password.Encoder
	GetTokenService() apisecurity.TokenService
	GetTokenGenerator() token.Generator
	GetTokenProviders() []libsecurity.TokenProvider
	GetCookieOptions() CookieOptions
}

Security is used to init auth methods by config.

func NewSecurity

func NewSecurity(
	config libsecurity.Config,
	globalConfig config.CanopsisConf,
	dbClient mongo.DbClient,
	sessionStore libsession.Store,
	enforcer libsecurity.Enforcer,
	apiConfigProvider config.ApiConfigProvider,
	maintenanceAdapter config.MaintenanceAdapter,
	cookieOptions CookieOptions,
	logger zerolog.Logger,
) Security

NewSecurity creates new security.

type Worker

type Worker func(context.Context)

Worker is used to implement adding new worker to API.

Jump to

Keyboard shortcuts

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