service

package
v2.0.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2020 License: AGPL-3.0 Imports: 59 Imported by: 0

Documentation

Overview

Package service acts as a factory for all Pydio services.

Pydio services are wrapped around micro services with additional information and ability to declare themselves to the registry. Services can be of three main different type : - Generic Service : providing a Runner function, they can be used to package any kind of server library as a pydio service - Micro Service : GRPC-based services implementing specific protobuf-services - Web Service : Services adding more logic and exposing Rest APIs defined by the OpenAPI definitions generated from protobufs.

Package provides additional aspects that can be added to any service and declared by "WithXXX" functions.

Index

Constants

View Source
const (
	TYPE_GENERIC = iota
	TYPE_GRPC
	TYPE_REST
	TYPE_API
)

Variables

View Source
var (
	HttpMetaJwtClientApp = "JwtClientApp"
	HttpMetaJwtIssuer    = "JwtIssuer"
)

Functions

func ApplyMigrations

func ApplyMigrations(ctx context.Context, current *version.Version, target *version.Version, migrations []*Migration) (*version.Version, error)

ApplyMigrations browse migrations upward on downward and apply them sequentially. It returns a version to be saved as the current valid version of the service, or nil if no changes were necessary. In specific case where current version is 0.0.0 (first run), it only applies first run migration (if any) and returns target version.

func FirstRun

func FirstRun() *version.Version

FirstRun returns version "zero".

func JWTHttpWrapper

func JWTHttpWrapper(h http.Handler) http.Handler

JWTHttpWrapper captures and verifies a JWT token if it's present in the headers. Warning: it goes through if there is no JWT => the next handlers must verify if a valid user was found or not.

func LastKnownVersion

func LastKnownVersion(serviceName string) (v *version.Version, e error)

LastKnownVersion looks on this server if there was a previous version of this service

func Latest

func Latest() *version.Version

Latest retrieves current common Cells version.

func NewBackoffClientWrapper

func NewBackoffClientWrapper() client.Wrapper

NewBackoffClientWrapper wraps a client with a backoff option

func NewClaimsHandlerWrapper

func NewClaimsHandlerWrapper() server.HandlerWrapper

NewClaimsHandlerWrapper decodes json claims passed via context metadata ( = headers ) and sets Claims as a proper value in the context

func NewConfigHandlerWrapper

func NewConfigHandlerWrapper(service micro.Service) server.HandlerWrapper

NewConfigHandlerWrapper wraps the service config within the handler so it can be accessed by the handler itself.

func NewConfigHttpHandlerWrapper

func NewConfigHttpHandlerWrapper(h http.Handler, serviceName string) (http.Handler, error)

NewConfigHttpHandlerWrapper is the same as ConfigHandlerWrapper but for pure http

func NewDAOClientWrapper

func NewDAOClientWrapper(v dao.DAO) client.Wrapper

NewDAOClientWrapper wraps a db connection so it can be accessed by subsequent client wrappers.

func NewDAOHandlerWrapper

func NewDAOHandlerWrapper(val dao.DAO) server.HandlerWrapper

NewDAOHandlerWrapper wraps a db connection within the handler so it can be accessed by the handler itself.

func NewDAOSubscriberWrapper

func NewDAOSubscriberWrapper(val dao.DAO) server.SubscriberWrapper

NewDAOSubscriberWrapper wraps a db connection for each subscriber

func NewLogHandlerWrapper

func NewLogHandlerWrapper(name string, color uint64) server.HandlerWrapper

NewLogHandlerWrapper wraps a db connection within the handler so it can be accessed by the handler itself.

func NewLogHttpHandlerWrapper

func NewLogHttpHandlerWrapper(h http.Handler, serviceName string, serviceColor uint64) http.Handler

Same but for http

func PolicyHttpWrapper

func PolicyHttpWrapper(h http.Handler) http.Handler

PolicyHttpWrapper applies relevant policy rules and blocks the request if necessary

func RegisterSwaggerJson added in v1.2.0

func RegisterSwaggerJson(json string)

func RestError401 added in v1.2.0

func RestError401(req *restful.Request, resp *restful.Response, err error)

RestError401 logs the error with context and write an Error 401 on the response.

func RestError403

func RestError403(req *restful.Request, resp *restful.Response, err error)

RestError403 logs the error with context and write an Error 403 on the response.

func RestError404

func RestError404(req *restful.Request, resp *restful.Response, err error)

RestError404 logs the error with context and writes an Error 404 on the response.

func RestError423

func RestError423(req *restful.Request, resp *restful.Response, err error)

RestError423 logs the error with context and write an Error 423 on the response.

func RestError500

func RestError500(req *restful.Request, resp *restful.Response, err error)

RestError500 logs the error with context and write an Error 500 on the response.

func RestError503

func RestError503(req *restful.Request, resp *restful.Response, err error)

RestError503 logs the error with context and write an Error 503 on the response.

func RestErrorDetect added in v1.2.0

func RestErrorDetect(req *restful.Request, resp *restful.Response, err error, defaultCode ...int32)

RestErrorDetect parses the error and tries to detect the correct code.

func Retry

func Retry(f func() error, seconds ...time.Duration) error

func SwaggerSpec added in v1.2.0

func SwaggerSpec() *loads.Document

func UpdateServiceVersion

func UpdateServiceVersion(s Service) error

UpdateServiceVersion applies migration(s) if necessary and stores new current version for future use.

func UpdateVersion

func UpdateVersion(serviceName string, v *version.Version) error

UpdateVersion writes the version string to file

func ValidVersion

func ValidVersion(v string) *version.Version

ValidVersion creates a version.NewVersion ignoring the error.

Types

type Checker

type Checker interface {
	Check() error
}

Checker is a function that checks if the service is correctly Running

type CheckerFunc

type CheckerFunc func() error

func (CheckerFunc) Check

func (f CheckerFunc) Check() error

Check implements the Chercker interface

type ChildrenRunner

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

For Regexp based service

func NewChildrenRunner

func NewChildrenRunner(parentService micro.Service, parentName string, childPrefix string) *ChildrenRunner

NewChildrenRunner creates a ChildrenRunner

func (*ChildrenRunner) FilterOutSource

func (c *ChildrenRunner) FilterOutSource(ctx context.Context, sourceName string) bool

FilterOutSource checks in the actual source config if there are some keys that would prevent running on this node

func (*ChildrenRunner) OnDeleteConfig

func (c *ChildrenRunner) OnDeleteConfig(callback func(context.Context, string))

func (*ChildrenRunner) Start

func (c *ChildrenRunner) Start(ctx context.Context, source string) error

Start starts a forked process for a new source

func (*ChildrenRunner) StartFromInitialConf

func (c *ChildrenRunner) StartFromInitialConf(ctx context.Context, cfg common.ConfigValues)

StartFromInitialConf list the sources keys and start them

func (*ChildrenRunner) StopAll

func (c *ChildrenRunner) StopAll(ctx context.Context)

func (*ChildrenRunner) Watch

func (c *ChildrenRunner) Watch(ctx context.Context) error

Watch watches the configuration changes for new sources

type HandlerProvider

type HandlerProvider func(micro.Service) interface{}

HandlerProvider returns a handler function from a micro service

type Migration

type Migration struct {
	TargetVersion *version.Version
	Up            func(ctx context.Context) error
	Down          func(ctx context.Context) error
}

Migration defines a target version and functions to upgrade and/or downgrade.

type ProtoEntityReaderWriter

type ProtoEntityReaderWriter struct {
}

EntityReaderWriter can read and write values using an encoding such as JSON,XML.

func (*ProtoEntityReaderWriter) Read

func (e *ProtoEntityReaderWriter) Read(req *restful.Request, v interface{}) error

Read a serialized version of the value from the request. The Request may have a decompressing reader. Depends on Content-Encoding.

func (*ProtoEntityReaderWriter) Write

func (e *ProtoEntityReaderWriter) Write(resp *restful.Response, status int, v interface{}) error

Write a serialized version of the value on the response. The Response may have a compressing writer. Depends on Accept-Encoding. status should be a valid Http Status code

type RestHandlerBuilder

type RestHandlerBuilder func(service web.Service, defaultClient client.Client) interface{}

RestHandlerBuilder builds a RestHandler

type Runner

type Runner interface {
	Run() error
}

type RunnerFunc

type RunnerFunc func() error

func (RunnerFunc) Run

func (f RunnerFunc) Run() error

type Service

type Service interface {
	registry.Service

	Init(...ServiceOption)
	Options() ServiceOptions
}

func NewService

func NewService(opts ...ServiceOption) Service

NewService provides everything needed to run a service, no matter the type

type ServiceOption

type ServiceOption func(*ServiceOptions)

func AfterInit

func AfterInit(fn func(Service) error) ServiceOption

func AfterStart

func AfterStart(fn func(Service) error) ServiceOption

func AfterStop

func AfterStop(fn func(Service) error) ServiceOption

func AutoStart added in v1.2.2

func AutoStart(b bool) ServiceOption

func BeforeInit

func BeforeInit(fn func(Service) error) ServiceOption

Before and Afters

func BeforeStart

func BeforeStart(fn func(Service) error) ServiceOption

func BeforeStop

func BeforeStop(fn func(Service) error) ServiceOption

func Cancel

func Context

func Context(c context.Context) ServiceOption

func Dependency

func Dependency(n string, t []string) ServiceOption

func Description

func Description(d string) ServiceOption

func Fork added in v1.2.2

func Fork(b bool) ServiceOption

func Migrations

func Migrations(migrations []*Migration) ServiceOption

func Name

func Name(n string) ServiceOption

func PluginBoxes

func PluginBoxes(boxes ...frontend.PluginBox) ServiceOption

func Port added in v1.2.2

func Port(p string) ServiceOption

func Regexp

func Regexp(r string) ServiceOption

func RouterDependencies added in v1.0.1

func RouterDependencies() ServiceOption

func Source

func Source(s string) ServiceOption

func Tag

func Tag(t ...string) ServiceOption

func Unique added in v1.2.2

func Unique(b bool) ServiceOption

func Version

func Version(v string) ServiceOption

func Watch

func Watch(fn func(common.ConfigValues)) ServiceOption

func WithChecker

func WithChecker(c Checker) ServiceOption

func WithGeneric

func WithGeneric(f func(context.Context, context.CancelFunc) (Runner, Checker, Stopper, error), opts ...func(Service) (micro.Option, error)) ServiceOption

WithGeneric adds a generic micro service handler to the current service

func WithMicro

func WithMicro(f func(micro.Service) error) ServiceOption

WithMicro adds a micro service handler to the current service

func WithMicroChildrenRunner

func WithMicroChildrenRunner(parentName string, childrenPrefix string, cleanEndpointBeforeDelete bool, afterDeleteListener func(context.Context, string)) ServiceOption

func WithStorage

func WithStorage(d func(dao.DAO) dao.DAO, prefix ...interface{}) ServiceOption

WithStorage adds a storage handler to the current service

func WithWeb

func WithWeb(handler func() WebHandler, opts ...web.Option) ServiceOption

WithWeb returns a web handler

func WithWebAuth added in v1.0.1

func WithWebAuth() ServiceOption

WithWebAuth adds dependencies to the web services and auth wrappers to auth handlers

func WithWebHandler added in v1.4.0

func WithWebHandler(h func(http.Handler) http.Handler) ServiceOption

func WithWebSession added in v1.2.0

func WithWebSession(excludes ...string) ServiceOption

type ServiceOptions

type ServiceOptions struct {
	Name string
	Tags []string

	Version     string
	Description string
	Source      string

	Context context.Context
	Cancel  context.CancelFunc

	DAO        func(dao.DAO) dao.DAO
	Prefix     interface{}
	Migrations []*Migration

	Port string

	Micro micro.Service
	Web   web.Service

	Dependencies []*dependency

	// Starting options
	AutoStart bool
	Fork      bool
	Unique    bool

	Registry registry.Registry

	Regexp  *regexp.Regexp
	Flags   pflag.FlagSet
	Checker Checker

	MinNumberOfNodes int

	// Before and After funcs
	BeforeInit  []func(Service) error
	AfterInit   []func(Service) error
	BeforeStart []func(Service) error
	AfterStart  []func(Service) error
	BeforeStop  []func(Service) error
	AfterStop   []func(Service) error

	OnRegexpMatch func(Service, []string) error

	// Micro init
	MicroInit func(Service) error

	// Web init
	WebInit func(Service) error

	// Watcher
	Watchers []func(common.ConfigValues)
	// contains filtered or unexported fields
}

ServiceOptions stores all options for a pydio service

type StatusHandler added in v1.2.2

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

StatusHandler provides functionality for getting the status of a service

func (*StatusHandler) SetAddress

func (sh *StatusHandler) SetAddress(a string)

func (*StatusHandler) Status added in v1.2.2

func (sh *StatusHandler) Status(ctx context.Context, in *empty.Empty, out *proto.StatusResponse) error

Status of the service - If we reach this point, it means that this micro service is correctly up and running

type StopFunctionKey

type StopFunctionKey struct{}

type StopHandler added in v1.2.2

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

StatusHandler provides functionality for stopping a service

func (*StopHandler) Process added in v1.2.2

func (s *StopHandler) Process(ctx context.Context, in *proto.StopEvent) error

func (*StopHandler) SetService

func (s *StopHandler) SetService(srv Service)

type Stopper

type Stopper interface {
	Stop() error
}

type StopperFunc

type StopperFunc func() error

func (StopperFunc) Stop

func (f StopperFunc) Stop() error

type WebHandler

type WebHandler interface {
	SwaggerTags() []string
	Filter() func(string) string
}

WebHandler defines what functions a web handler must answer to

Directories

Path Synopsis
Package servicecontext performs context values read/write, generally through server or client wrappers
Package servicecontext performs context values read/write, generally through server or client wrappers
Package frontend provides tools to publish static data from within any micro service It implements a simple Union HttpFS to be exposed by a standard net.HttpFileServer interface.
Package frontend provides tools to publish static data from within any micro service It implements a simple Union HttpFS to be exposed by a standard net.HttpFileServer interface.
Package service is a generated protocol buffer package.
Package service is a generated protocol buffer package.
Package resources provides extendable service Handler for managing resource-policy based data.
Package resources provides extendable service Handler for managing resource-policy based data.

Jump to

Keyboard shortcuts

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