Documentation
¶
Overview ¶
Plugin manager used by the main application to load and invoke plugins.
Adapted from 'RPC-based plugins in Go' by Eli Bendersky (@eliben): ref: https://eli.thegreenplace.net/2023/rpc-based-plugins-in-go/ ref: https://github.com/eliben/code-for-blog/blob/main/2023/go-plugin-htmlize-rpc/plugin/manager.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Handshake = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "AUTHORIZE_PLUGIN",
MagicCookieValue: "authorize",
}
Handshake is a common handshake that is shared by plugin and host.
var Logger = hclog.New(&hclog.LoggerOptions{ Name: "plugin", Level: hclog.Trace, })
Create an hclog.Logger
var PluginMap = map[string]plugin.Plugin{ "authorize_grpc": &AuthorizeGRPCPlugin{}, "authorize": &AuthorizePlugin{}, }
PluginMap is the map of plugins we can dispense.
Functions ¶
This section is empty.
Types ¶
type Authorize ¶
type Authorize interface {
PluginAction(params map[string]string, headers map[string]*proto.StringList, config *config.Config, task *tes.Task, actionType proto.Type) (*proto.JobResponse, error)
}
Authorize is the interface that we're exposing as a plugin.
type AuthorizeGRPCPlugin ¶
type AuthorizeGRPCPlugin struct {
// GRPCPlugin must still implement the Plugin interface
plugin.Plugin
// Concrete implementation, written in Go. This is only used for plugins
// that are written in Go.
Impl Authorize
}
This is the implementation of plugin.GRPCPlugin so we can serve/consume this.
func (*AuthorizeGRPCPlugin) GRPCClient ¶
func (p *AuthorizeGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (any, error)
func (*AuthorizeGRPCPlugin) GRPCServer ¶
func (p *AuthorizeGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error
type AuthorizePlugin ¶
type AuthorizePlugin struct {
// Concrete implementation, written in Go. This is only used for plugins
// that are written in Go.
Impl Authorize
}
This is the implementation of plugin.Plugin so we can serve/consume this.
type GRPCClient ¶
type GRPCClient struct {
// contains filtered or unexported fields
}
GRPCClient is an implementation of KV that talks over RPC.
func (*GRPCClient) PluginAction ¶
func (m *GRPCClient) PluginAction(headers map[string]*proto.StringList, params map[string]string, config *config.Config, task *tes.Task, actionType proto.Type) (*proto.JobResponse, error)
type GRPCServer ¶
type GRPCServer struct {
// This is the real implementation
Impl Authorize
}
func (*GRPCServer) PluginAction ¶
func (m *GRPCServer) PluginAction(ctx context.Context, req *proto.Job) (*proto.JobResponse, error)
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager loads and manages Authorizer plugins for this application.
After creating a Manager value, call LoadPlugins with a directory path to discover and load plugins. At the end of the program call Close to kill and clean up all plugin processes.
func (*Manager) LoadPlugin ¶
LoadPlugins takes a directory path and assumes that all files within it are plugin binaries. It runs all these binaries in sub-processes, establishes RPC communication with the plugins, and registers them for the hooks they declare to support.
type RPCClient ¶
type RPCClient struct {
// contains filtered or unexported fields
}
RPCClient is an implementation of Authorize that talks over RPC.
func (*RPCClient) PluginAction ¶
func (m *RPCClient) PluginAction(params map[string]string, headers map[string]*proto.StringList, config *funnelConfig.Config, task *tes.Task, actionType proto.Type) (*proto.JobResponse, error)