plugin

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CastToPrimitiveTypes added in v0.2.4

func CastToPrimitiveTypes(args map[string]interface{}) map[string]interface{}

CastToPrimitiveTypes casts the values of a map to its primitive type (e.g. time.Duration to float64) to prevent structpb invalid type(s) errors.

func NewCommand added in v0.2.0

func NewCommand(cmd string, args []string, env []string) *exec.Cmd

NewCommand returns a command with the given arguments and environment variables.

func Verify added in v0.0.8

func Verify(params, returnVal *structpb.Struct) bool

Verify compares two structs and returns true if they are equal.

Types

type IHook added in v0.2.5

type IHook interface {
	AddHook(hookName v1.HookName, priority sdkPlugin.Priority, hookMethod sdkPlugin.Method)
	Hooks() map[v1.HookName]map[sdkPlugin.Priority]sdkPlugin.Method
	Run(
		ctx context.Context,
		args map[string]interface{},
		hookName v1.HookName,
		opts ...grpc.CallOption,
	) (map[string]interface{}, *gerr.GatewayDError)
}

type IPlugin added in v0.2.2

type IPlugin interface {
	Start() (net.Addr, error)
	Stop()
	Dispense() (v1.GatewayDPluginServiceClient, *gerr.GatewayDError)
	Ping() *gerr.GatewayDError
}

type IRegistry added in v0.2.4

type IRegistry interface {
	// Plugin management
	Add(plugin *Plugin) bool
	Get(pluginID sdkPlugin.Identifier) *Plugin
	List() []sdkPlugin.Identifier
	Size() int
	Exists(name, version, remoteURL string) bool
	ForEach(f func(sdkPlugin.Identifier, *Plugin))
	Remove(pluginID sdkPlugin.Identifier)
	Shutdown()
	LoadPlugins(ctx context.Context, plugins []config.Plugin)
	RegisterHooks(ctx context.Context, pluginID sdkPlugin.Identifier)

	// Hook management
	IHook
}

type Plugin added in v0.0.8

type Plugin sdkPlugin.Plugin

func (*Plugin) Dispense added in v0.0.8

Dispense returns the plugin client.

func (*Plugin) Ping added in v0.4.1

func (p *Plugin) Ping() *gerr.GatewayDError

Ping pings the plugin.

func (*Plugin) Start added in v0.0.8

func (p *Plugin) Start() (net.Addr, error)

Start starts the plugin.

func (*Plugin) Stop added in v0.0.8

func (p *Plugin) Stop()

Stop kills the plugin.

type Registry added in v0.0.8

type Registry struct {
	Logger        zerolog.Logger
	Compatibility config.CompatibilityPolicy
	Verification  config.VerificationPolicy
	Acceptance    config.AcceptancePolicy
	Termination   config.TerminationPolicy
	// contains filtered or unexported fields
}

func NewRegistry added in v0.0.8

func NewRegistry(
	ctx context.Context,
	compatibility config.CompatibilityPolicy,
	verification config.VerificationPolicy,
	acceptance config.AcceptancePolicy,
	termination config.TerminationPolicy,
	logger zerolog.Logger,
	devMode bool,
) *Registry

NewRegistry creates a new plugin registry.

func (*Registry) Add added in v0.0.8

func (reg *Registry) Add(plugin *Plugin) bool

Add adds a plugin to the registry.

func (*Registry) AddHook added in v0.2.4

func (reg *Registry) AddHook(hookName v1.HookName, priority sdkPlugin.Priority, hookMethod sdkPlugin.Method)

Add adds a hook with a priority to the hooks map.

func (*Registry) Exists added in v0.2.0

func (reg *Registry) Exists(name, version, remoteURL string) bool

Exists checks if a plugin exists in the registry.

func (*Registry) ForEach added in v0.3.0

func (reg *Registry) ForEach(function func(sdkPlugin.Identifier, *Plugin))

ForEach iterates over all plugins in the registry.

func (*Registry) Get added in v0.0.8

func (reg *Registry) Get(pluginID sdkPlugin.Identifier) *Plugin

Get returns a plugin from the registry.

func (*Registry) Hooks added in v0.2.4

func (reg *Registry) Hooks() map[v1.HookName]map[sdkPlugin.Priority]sdkPlugin.Method

Hooks returns the hooks map.

func (*Registry) List added in v0.0.8

func (reg *Registry) List() []sdkPlugin.Identifier

List returns a list of all plugins in the registry.

func (*Registry) LoadPlugins added in v0.0.8

func (reg *Registry) LoadPlugins(ctx context.Context, plugins []config.Plugin)

LoadPlugins loads plugins from the config file.

func (*Registry) RegisterHooks added in v0.0.8

func (reg *Registry) RegisterHooks(ctx context.Context, pluginID sdkPlugin.Identifier)

RegisterHooks registers the hooks for the given plugin.

func (*Registry) Remove added in v0.0.8

func (reg *Registry) Remove(pluginID sdkPlugin.Identifier)

Remove removes plugin hooks and then removes the plugin from the registry.

func (*Registry) Run added in v0.2.4

func (reg *Registry) Run(
	ctx context.Context,
	args map[string]interface{},
	hookName v1.HookName,
	opts ...grpc.CallOption,
) (map[string]interface{}, *gerr.GatewayDError)

Run runs the hooks of a specific type. The result of the previous hook is passed to the next hook as the argument, aka. chained. The context is passed to the hooks as well to allow them to cancel the execution. The args are passed to the first hook as the argument. The result of the first hook is passed to the second hook, and so on. The result of the last hook is eventually returned. The verification mode is used to determine how to handle errors. If the verification mode is set to Abort, the execution is aborted on the first error. If the verification mode is set to Remove, the hook is removed from the list of hooks on the first error. If the verification mode is set to Ignore, the error is ignored and the execution continues. If the verification mode is set to PassDown, the extra keys/values in the result are passed down to the next The verification mode is set to PassDown by default. The opts are passed to the hooks as well to allow them to use the grpc.CallOption.

func (*Registry) Shutdown added in v0.0.8

func (reg *Registry) Shutdown()

Shutdown shuts down all plugins in the registry.

func (*Registry) Size added in v0.4.4

func (reg *Registry) Size() int

Size returns the number of plugins in the registry.

Jump to

Keyboard shortcuts

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