plugin

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2017 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PluginInitMaxRetryCount defines the maximum retries for plugin initialization
	PluginInitMaxRetryCount = 100
)

Variables

This section is empty.

Functions

func ContextMap

func ContextMap(ctx context.Context) map[string]interface{}

ContextMap returns a map of the user request context.

func CreateHookFunc

func CreateHookFunc(p *Plugin, hookInfo pluginHookInfo) hook.Func

CreateHookFunc returns a hook.HookFunc that run the hook registered by a plugin

func RegisterTransport

func RegisterTransport(name string, transport TransportFactory)

RegisterTransport registers a transport factory by name.

func SupportedTransports

func SupportedTransports() []string

SupportedTransports tells all supported transport names

Types

type AuthProvider

type AuthProvider struct {
	Name string
	// contains filtered or unexported fields
}

AuthProvider is implemented by plugin to provider user authentication functionality to Skygear.

func NewAuthProvider

func NewAuthProvider(providerName string, plugin *Plugin) *AuthProvider

NewAuthProvider creates a new AuthProvider.

func (*AuthProvider) Info

func (p *AuthProvider) Info(ctx context.Context, authData map[string]interface{}) (newAuthData map[string]interface{}, err error)

Info calls the AuthProvider implemented by plugin to request for user information.

func (*AuthProvider) Login

func (p *AuthProvider) Login(ctx context.Context, authData map[string]interface{}) (principalID string, newAuthData map[string]interface{}, err error)

Login calls the AuthProvider implemented by plugin to request for user login authentication

func (*AuthProvider) Logout

func (p *AuthProvider) Logout(ctx context.Context, authData map[string]interface{}) (newAuthData map[string]interface{}, err error)

Logout calls the AuthProvider implemented by plugin to request for user logout.

type AuthRequest

type AuthRequest struct {
	ProviderName string
	Action       string
	AuthData     map[string]interface{}
}

AuthRequest is sent by Skygear Server to plugin which contains data for authentication

type AuthResponse

type AuthResponse struct {
	PrincipalID string                 `json:"principal_id"`
	AuthData    map[string]interface{} `json:"auth_data"`
}

AuthResponse is sent by plugin to Skygear Server which contains authenticated data

type Context added in v0.19.0

type Context struct {
	Router           *router.Router
	Mux              *http.ServeMux
	Preprocessors    router.PreprocessorRegistry
	HookRegistry     *hook.Registry
	ProviderRegistry *provider.Registry
	Scheduler        *cron.Cron
	Config           skyconfig.Configuration
	// contains filtered or unexported fields
}

Context contains reference to structs that will be initialized by plugin.

func (*Context) AddPluginConfiguration added in v0.19.0

func (c *Context) AddPluginConfiguration(name string, path string, args []string) *Plugin

AddPluginConfiguration creates and appends a plugin

func (*Context) InitPlugins added in v0.19.0

func (c *Context) InitPlugins()

InitPlugins initializes all plugins registered

func (*Context) IsInitialized added in v0.19.0

func (c *Context) IsInitialized() bool

IsInitialized returns true if all the plugins have been initialized

func (*Context) IsReady added in v0.19.0

func (c *Context) IsReady() bool

IsReady returns true if all the plugins are ready for client requests

func (*Context) SendEvent added in v0.19.0

func (c *Context) SendEvent(name string, data []byte, async bool)

SendEvent sends event to all plugins

SendEvent accepts `async` flag. Setting `async` to `false` means that an event will be sent to a plugin after another.

type Handler

type Handler struct {
	Plugin            *Plugin
	Name              string
	AccessKeyRequired bool
	UserRequired      bool
	PreprocessorList  router.PreprocessorRegistry
	// contains filtered or unexported fields
}

func NewPluginHandler

func NewPluginHandler(info pluginHandlerInfo, ppreg router.PreprocessorRegistry, p *Plugin) *Handler

func (*Handler) GetPreprocessors

func (h *Handler) GetPreprocessors() []router.Processor

func (*Handler) Handle

func (h *Handler) Handle(payload *router.Payload, response *router.Response)

Handle executes lambda function implemented by the plugin.

func (*Handler) Setup

func (h *Handler) Setup()

type LambdaHandler

type LambdaHandler struct {
	Plugin            *Plugin
	Name              string
	AccessKeyRequired bool
	UserRequired      bool
	PreprocessorList  router.PreprocessorRegistry
	// contains filtered or unexported fields
}

func NewLambdaHandler

func NewLambdaHandler(info map[string]interface{}, ppreg router.PreprocessorRegistry, p *Plugin) *LambdaHandler

func (*LambdaHandler) GetPreprocessors

func (h *LambdaHandler) GetPreprocessors() []router.Processor

func (*LambdaHandler) Handle

func (h *LambdaHandler) Handle(payload *router.Payload, response *router.Response)

Handle executes lambda function implemented by the plugin.

func (*LambdaHandler) Setup

func (h *LambdaHandler) Setup()

type Plugin

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

Plugin represents a collection of handlers, hooks and lambda functions that extends or modifies functionality provided by skygear.

func NewPlugin

func NewPlugin(name string, path string, args []string, config skyconfig.Configuration) Plugin

NewPlugin creates an instance of Plugin by transport and configuration.

func (*Plugin) Init

func (p *Plugin) Init(context *Context)

Init instantiates a plugin. This sets up hooks and handlers.

func (*Plugin) IsInitialized added in v0.19.0

func (p *Plugin) IsInitialized() bool

IsInitialized returns true if the plugin has been initialized

func (*Plugin) IsReady

func (p *Plugin) IsReady() bool

IsReady returns true if the plugin is ready for client request

type Transport

type Transport interface {
	State() TransportState
	SetState(TransportState)

	SendEvent(name string, in []byte) ([]byte, error)

	RunLambda(ctx context.Context, name string, in []byte) ([]byte, error)
	RunHandler(ctx context.Context, name string, in []byte) ([]byte, error)

	// RunHook runs the hook with a name recognized by plugin, passing in
	// record as a parameter. Transport may not modify the record passed in.
	//
	// A skydb.Record is returned as a result of invocation. Such record must be
	// a newly allocated instance, and may not share any reference type values
	// in any of its memebers with the record being passed in.
	RunHook(ctx context.Context, hookName string, record *skydb.Record, oldRecord *skydb.Record) (*skydb.Record, error)

	RunTimer(name string, in []byte) ([]byte, error)

	// RunProvider runs the auth provider with the specified AuthRequest.
	RunProvider(context context.Context, request *AuthRequest) (*AuthResponse, error)
}

A Transport represents the interface of data transfer between skygear and remote process.

type TransportFactory

type TransportFactory interface {
	Open(path string, args []string, config skyconfig.Configuration) Transport
}

A TransportFactory is a generic interface to instantiates different kinds of Plugin Transport.

type TransportInitHandler

type TransportInitHandler func([]byte, error) error

TransportInitHandler models the handler for transport init

type TransportState

type TransportState int

TransportState refers to the operation state of the transport

const (
	// TransportStateUninitialized is the state when the transport has not
	// been initialized
	TransportStateUninitialized TransportState = iota

	// TransportStateInitialized is the state when the transport has been
	// initialized. During this state, only requests from plugins with master key
	// will be accepted.
	TransportStateInitialized

	// TransportStateReady is the state when the transport is ready for
	// the requests from client.
	TransportStateReady

	// TransportStateWorkerUnavailable is the state when all workers
	// for the transport is not available
	TransportStateWorkerUnavailable

	// TransportStateError is the state when an error has occurred
	// in the transport and it is not able to serve requests
	TransportStateError
)

func (TransportState) String

func (i TransportState) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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