service

package
v3.0.0-rc4+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: AGPL-3.0 Imports: 70 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

This section is empty.

Variables

View Source
var (
	// HTTPMetaJwtClientApp constant
	HTTPMetaJwtClientApp = "JwtClientApp"
	// HTTPMetaJwtIssuer constant
	HTTPMetaJwtIssuer = "JwtIssuer"
)
View Source
var (
	DefaultRegisterTTL = 10 * time.Minute
)

Functions

func AddMicroMeta

func AddMicroMeta(m micro.Service, k, v string)

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 NewConfigHTTPHandlerWrapper

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

NewConfigHTTPHandlerWrapper is the same as ConfigHandlerWrapper but for pure http

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 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 NewGenericServer

func NewGenericServer(srv interface{}, opt ...server.Option) server.Server

NewGenericServer wraps a micro server out of a simple interface

func NewLogHTTPHandlerWrapper

func NewLogHTTPHandlerWrapper(h http.Handler, serviceName string) http.Handler

NewLogHTTPHandlerWrapper wraps a db connection to the HTTP Handler

func NewLogHandlerWrapper

func NewLogHandlerWrapper(name string) server.HandlerWrapper

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

func NewServiceWithStopOnError

func NewServiceWithStopOnError(s micro.Service) micro.Service

func PolicyHTTPWrapper

func PolicyHTTPWrapper(h http.Handler) http.Handler

PolicyHTTPWrapper applies relevant policy rules and blocks the request if necessary

func RegisterSwaggerJSON

func RegisterSwaggerJSON(json string)

RegisterSwaggerJSON receives a json string and adds it to the swagger definition

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(ctx context.Context, f func() error, seconds ...time.Duration) error

Retry function

func SwaggerSpec added in v1.2.0

func SwaggerSpec() *loads.Document

SwaggerSpec returns the swagger specification as a 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 Addressable

type Addressable interface {
	Addresses() []net.Addr
}

Addressable service definition

type ChildrenRunner

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

ChildrenRunner For Regexp based service

func NewChildrenRunner

func NewChildrenRunner(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))

OnDeleteConfig defines what's happening when the config related to the service is deleted

func (*ChildrenRunner) Start

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

Start starts a forked process for a new source

func (*ChildrenRunner) StartFromInitialConf

func (c *ChildrenRunner) StartFromInitialConf(ctx context.Context, cfg configx.Values)

StartFromInitialConf list the sources keys and start them

func (*ChildrenRunner) StopAll

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

StopAll services

func (*ChildrenRunner) Watch

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

Watch watches the configuration changes for new sources

type Cmd

type Cmd struct{}

Cmd definition to pass as default for a micro server

func (*Cmd) App

func (c *Cmd) App() *cli.App

App for default cmd

func (*Cmd) Init

func (c *Cmd) Init(opts ...cmd.Option) error

Init for default cmd

func (*Cmd) Options

func (c *Cmd) Options() cmd.Options

Options for default cmd

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 NonAddressable

type NonAddressable interface {
	NoAddress() string
}

NonAddressable service definition

type ProtoEntityReaderWriter

type ProtoEntityReaderWriter struct {
}

ProtoEntityReaderWriter 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 Runnable

type Runnable interface {
	Run() error
}

Runnable service definition

type RunnableFunc

type RunnableFunc func() error

RunnableFunc provides ability to use a function as a run service

func (RunnableFunc) Run

func (f RunnableFunc) Run() error

Run function as a service

type Service

type Service interface {
	registry.Service

	Init(...ServiceOption)
	Options() ServiceOptions
	Done() chan (struct{})
}

Service definition

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)

ServiceOption function to set ServiceOptions

func AfterInit

func AfterInit(fn func(Service) error) ServiceOption

AfterInit option for a service

func AfterStart

func AfterStart(fn func(Service) error) ServiceOption

AfterStart option for a service

func AfterStop

func AfterStop(fn func(Service) error) ServiceOption

AfterStop option for a service

func AutoRestart

func AutoRestart(b bool) ServiceOption

AutoRestart option for a service

func AutoStart added in v1.2.2

func AutoStart(b bool) ServiceOption

AutoStart option for a service

func BeforeInit

func BeforeInit(fn func(Service) error) ServiceOption

BeforeInit option for a service

func BeforeStart

func BeforeStart(fn func(Service) error) ServiceOption

BeforeStart option for a service

func BeforeStop

func BeforeStop(fn func(Service) error) ServiceOption

BeforeStop option for a service

func Cancel

Cancel option for a service

func Context

func Context(c context.Context) ServiceOption

Context option for a service

func Dependency

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

Dependency option for a service

func Description

func Description(d string) ServiceOption

Description option for a service

func Fork added in v1.2.2

func Fork(b bool) ServiceOption

Fork option for a service

func ID

func ID(i string) ServiceOption

ID option for a service

func Micro

func Micro(m micro.Service) ServiceOption

Micro service option

func Migrations

func Migrations(migrations []*Migration) ServiceOption

Migrations option for a service

func Name

func Name(n string) ServiceOption

Name option for a service

func PluginBoxes

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

PluginBoxes option for a service

func Port added in v1.2.2

func Port(p string) ServiceOption

Port option for a service

func Regexp

func Regexp(r string) ServiceOption

Regexp option for a service

func RouterDependencies added in v1.0.1

func RouterDependencies() ServiceOption

RouterDependencies option for a service

func Source

func Source(s string) ServiceOption

Source option for a service

func Tag

func Tag(t ...string) ServiceOption

Tag option for a service

func Unique added in v1.2.2

func Unique(b bool) ServiceOption

Unique option for a service

func Version

func Version(v string) ServiceOption

Version option for a service

func Watch

func Watch(fn func(Service, configx.Values)) ServiceOption

Watch option for a service

func WatchPath

func WatchPath(path string, fn func(Service, configx.Values)) ServiceOption

WatchPath option for a service

func WithGeneric

func WithGeneric(f func(...server.Option) server.Server) ServiceOption

WithGeneric runs a micro server

func WithHTTP

func WithHTTP(handlerFunc func() http.Handler) ServiceOption

WithHTTP adds a http 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

WithMicroChildrenRunner option to define a micro server that runs children services

func WithStorage

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

WithStorage adds a storage handler to the current service

func WithTLSConfig

func WithTLSConfig(c *tls.Config) ServiceOption

WithTLSConfig option for a service

func WithWeb

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

WithWeb returns a web handler

func WithWebAuth added in v1.0.1

func WithWebAuth() ServiceOption

WithWebAuth adds auth wrappers to auth handlers

func WithWebHandler added in v1.4.0

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

WithWebHandler option for a service

func WithWebSession added in v1.2.0

func WithWebSession(excludes ...string) ServiceOption

WithWebSession option for a service

type ServiceOptions

type ServiceOptions struct {
	Name string
	ID   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
	TLSConfig *tls.Config

	Micro micro.Service

	Dependencies []*dependency

	// Starting options
	AutoStart   bool
	AutoRestart bool
	Fork        bool
	Unique      bool

	Registry registry.Registry

	Regexp *regexp.Regexp
	Flags  pflag.FlagSet

	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
	MicroCancel context.CancelFunc

	// Web init
	WebInit func(Service) error

	// Watcher
	Watchers map[string][]func(Service, configx.Values)
	// contains filtered or unexported fields
}

ServiceOptions stores all options for a pydio service

type Starter

type Starter interface {
	Start() error
}

Starter service definition

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)

SetAddress for a service

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{}

StopFunctionKey definition

type StopHandler added in v1.2.2

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

StopHandler provides functionality for stopping a service

func (*StopHandler) ProcessEvent

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

ProcessEvent handler

func (*StopHandler) SetService

func (s *StopHandler) SetService(srv Service)

SetService handler

type Stopper

type Stopper interface {
	Stop() error
}

Stopper service definiion

type StopperFunc

type StopperFunc func() error

StopperFunc allows to use a function as a stopper service

func (StopperFunc) Stop

func (f StopperFunc) Stop() error

Stop service with recover

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