api

package
v0.0.0-...-d841f61 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 80 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultOldAPI = "localhost:8081"
	EnvOldApiURL  = "CPS_OLD_API_URL"
)

Variables

This section is empty.

Functions

func GetLegacyURL

func GetLegacyURL() (parsed *url.URL)

GetLegacyURL returns old API url from env var or default url.

func GetProxy

func GetProxy(
	security Security,
	enforcer libsecurity.Enforcer,
	accessConfig proxy.AccessConfig,
) []gin.HandlerFunc

func RegisterRoutes

func RegisterRoutes(
	ctx context.Context,
	conf config.CanopsisConf,
	router gin.IRouter,
	security Security,
	enforcer libsecurity.Enforcer,
	dbClient mongo.DbClient,
	timezoneConfigProvider config.TimezoneConfigProvider,
	pbhStore redis.Store,
	pbhService libpbehavior.Service,
	pbhComputeChan chan<- libpbehavior.ComputeTask,
	entityPublChan chan<- libentityservice.ChangeEntityMessage,
	runInfoManager engine.RunInfoManager,
	exportExecutor export.TaskExecutor,
	actionLogger logger.ActionLogger,
	publisher amqp.Publisher,
	jobQueue contextgraph.JobQueue,
	userInterfaceConfig config.UserInterfaceConfigProvider,
	logger zerolog.Logger,
)

func RegisterValidators

func RegisterValidators(client mongo.DbClient)

func RestartGoroutine

func RestartGoroutine(
	key string,
	f func(),
	wg *sync.WaitGroup,
	logger zerolog.Logger,
)

RestartGoroutine starts goroutine with panic recovery. RestartGoroutine logs recovery and restarts goroutine on panic.

func ReverseProxyHandler

func ReverseProxyHandler() gin.HandlerFunc

ReverseProxyHandler directs requests to old API. It doesn't support old API session and uses auth api key for authentication.

Types

type API

type API interface {
	// Run starts http server.
	Run(context.Context) error
	// AddRouter adds new router.
	AddRouter(Router)
	// AddWorker adds new worker.
	AddWorker(string, Worker)
	// AddNoRoute adds handlers for no roure.
	AddNoRoute([]gin.HandlerFunc)
}

API is used to implement API http server.

func Default

func Default(
	ctx context.Context,
	addr string,
	configDir string,
	secureSession bool,
	test bool,
	enforcer libsecurity.Enforcer,
	timezoneConfigProvider *config.BaseTimezoneConfigProvider,
	logger zerolog.Logger,
) (API, error)

func New

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

New creates new api.

type Router

type Router func(gin.IRouter)

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(router gin.IRouter)
	GetAuthMiddleware() []gin.HandlerFunc
	GetSessionStore() libsession.Store
	GetConfig() libsecurity.Config
	GetPasswordEncoder() password.Encoder
}

Security is used to init auth methods by config.

func NewSecurity

func NewSecurity(
	config *libsecurity.Config,
	dbClient mongo.DbClient,
	sessionStore libsession.Store,
	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