plugin

package
v0.0.0-...-7dacf16 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersion uint = 1
	MagicCookieKey       = "REGINALD_PLUGIN"
	MagicCookie          = "plugin"
)

Helper values for creating the handshake configuration for the plugin server.

View Source
const (
	ExitSuccess      = 0
	ExitMarshalError = 2 // marshaling the descriptor failed
)

Exit codes for the `--describe` functionality of the plugin server executable.

Variables

View Source
var ErrEmptyPlugin = errors.New("plugin specified no commands or tasks")
View Source
var HandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  ProtocolVersion,
	MagicCookieKey:   MagicCookieKey,
	MagicCookieValue: MagicCookie,
}

Set handshake configs for the plugin servers and clients.

Functions

This section is empty.

Types

type CmdPlugin

type CmdPlugin struct {
	Impl command.Command
}

CmdPlugin is the implementation of Plugin for commands. It is used for serving and consuming a command plugin.

To serve a command given as Impl from a plugin, use the CmdPlugin.Server function to get the RPC server. It contructs and serves a CmdRPCServer.

To consume a command as a client from a plugin, use the CmdPlugin.Client function to get the RPC client. It contructs and serves a CmdRPC.

func (*CmdPlugin) Client

func (p *CmdPlugin) Client(_ *plugin.MuxBroker, c *rpc.Client) (any, error)

Client returns the client implementation of command.Command for the CmdPlugin.

func (*CmdPlugin) Server

func (p *CmdPlugin) Server(_ *plugin.MuxBroker) (any, error)

Server returns the server implementation of command.Command for the CmdPlugin.

type CmdRPC

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

CmdRPC is a command.Command implementation that talks over RPC. It is the client that consumes a plugin. The RPC client can be obtained with CmdPlugin.Client.

func (*CmdRPC) Name

func (c *CmdRPC) Name() string

func (*CmdRPC) Run

func (c *CmdRPC) Run() error

type CmdRPCServer

type CmdRPCServer struct {
	Impl command.Command
}

CmdRPCServer is a command.Command implementation used on the RPC server (the plugin) that the client-side CmdRPC talks to over RPC. The RPC server can be obtained with CmdPlugin.Server.

func (*CmdRPCServer) Name

func (s *CmdRPCServer) Name(_ any, resp *string) error

func (*CmdRPCServer) Run

func (s *CmdRPCServer) Run(_ any, resp *error) error

type Descriptor

type Descriptor struct {
	Name            string   `json:"name"`            // name of the plugin
	ProtocolVersion uint     `json:"protocolVersion"` // protocol version used by plugin
	Commands        []string `json:"commands"`        // commands the plugin provided, can be empty or nil
	Tasks           []string `json:"tasks"`           // tasks the plugin provided, can be empty or nil
}

Descriptor describes the plugin when Reginald request for information on the plugins during discovery.

type Plugin

type Plugin = plugin.Plugin

Plugin is an alias for the plugin.Plugin interface used in the implementation of Reginald plugins. It is implemented to serve and consume plugins.

type Server

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

Server represents a plugin server. Each plugin should create a new plugin server using NewServer and use that to execute the plugin. Server provides the RPC and gRPC capabilities for executing the plugin as well as the command-line implementation for Reginald's plugin discovery.

The plugins must conform the expectation of Reginald. That is, the plugin discovery should be able to execute the plugin with the `--describe` flag so that the plugin returns the plugin implementations it provides in a predefined format that is handled by Server.

func NewCommandServer

func NewCommandServer(name string, cmds []command.Command) Server

func NewServer

func NewServer(name string, cmds []command.Command, tasks []task.Task) Server

NewServer returns a new plugins server. You can pass the commands and tasks this plugin serves as parameters. If the plugin only serves the other, you can pass a nil Set to the other parameter.

func NewTaskServer

func NewTaskServer(name string, tasks []task.Task) Server

func (*Server) Describe

func (s *Server) Describe()

func (*Server) Serve

func (s *Server) Serve() error

type Set

type Set map[string]Plugin

Set is a set of plugins provided to be registered in the plugin server.

type TaskPlugin

type TaskPlugin struct {
	Impl task.Task
}

TaskPlugin is the implementation of Plugin for tasks. It is used for serving and consuming a task plugin.

To serve a task given as Impl from a plugin, use the TaskPlugin.Server function to get the RPC server. It contructs and serves a TaskRPCServer.

To consume a task as a client from a plugin, use the TaskPlugin.Client function to get the RPC client. It contructs and serves a TaskRPC.

func (*TaskPlugin) Client

func (p *TaskPlugin) Client(_ *plugin.MuxBroker, c *rpc.Client) (any, error)

Client returns the client implementation of task.Task for the TaskPlugin.

func (*TaskPlugin) Server

func (p *TaskPlugin) Server(_ *plugin.MuxBroker) (any, error)

Server returns the server implementation of task.Task for the TaskPlugin.

type TaskRPC

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

TaskRPC is a task.Task implementation that talks over RPC. It is the client that consumes a plugin. The RPC client can be obtained with TaskPlugin.Client.

func (*TaskRPC) Check

func (t *TaskRPC) Check(settings task.Settings) error

func (*TaskRPC) CheckDefaults

func (t *TaskRPC) CheckDefaults(settings task.Settings) error

func (*TaskRPC) Run

func (t *TaskRPC) Run(cfg *task.Config) error

func (*TaskRPC) Type

func (t *TaskRPC) Type() string

type TaskRPCServer

type TaskRPCServer struct {
	Impl task.Task
}

TaskRPCServer is a task.Task implementation used on the RPC server (the plugin) that the client-side TaskRPC talks to over RPC. The RPC server can be obtained with TaskPlugin.Server.

func (*TaskRPCServer) Check

func (s *TaskRPCServer) Check(settings task.Settings, resp *error) error

func (*TaskRPCServer) CheckDefaults

func (s *TaskRPCServer) CheckDefaults(settings task.Settings, resp *error) error

func (*TaskRPCServer) Run

func (s *TaskRPCServer) Run(cfg *task.Config, resp *any) error

func (*TaskRPCServer) Type

func (s *TaskRPCServer) Type(_ any, resp *string) error

Jump to

Keyboard shortcuts

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