service

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2018 License: AGPL-3.0 Imports: 51 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

func FirstRun

func FirstRun() *version.Version

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

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 RestError403

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

func RestError404

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

func RestError500

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

func Retry

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

func UpdateServiceVersion

func UpdateServiceVersion(s Service) error

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

Create 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(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 config.Map)

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 Handler

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

func (*Handler) Status

func (h *Handler) 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 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
}

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

func ExposedConfigs(f *forms.Form) ServiceOption

func Migrations

func Migrations(migrations []*Migration) ServiceOption

func Name

func Name(n string) ServiceOption

func PluginBoxes

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

func Regexp

func Regexp(r string) ServiceOption

func Source

func Source(s string) ServiceOption

func Tag

func Tag(t ...string) ServiceOption

func Version

func Version(v string) ServiceOption

func WithChecker

func WithChecker(c Checker) ServiceOption

func WithGeneric

func WithGeneric(f func(context.Context, context.CancelFunc) (Runner, Checker, Stopper, error), opts ...micro.Option) 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

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

	Micro micro.Service
	Web   web.Service

	Dependencies []*dependency

	Registry registry.Registry

	Regexp  *regexp.Regexp
	Flags   pflag.FlagSet
	Checker Checker

	MinNumberOfNodes int
	ExposedConfigs   *forms.Form

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

	OnRegexpMatch func(Service, []string) error

	// Micro init
	MicroInit func(Service) error
}

ServiceOptions stores all options for a pydio service

type StopFunctionKey

type StopFunctionKey struct{}

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 defaults initializes the defaults GRPC clients and servers used by services
Package defaults initializes the defaults GRPC clients and servers used by services
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