Documentation ¶
Index ¶
- Variables
- func ServeAugmentor(augmentor aug.TemplateAugmentor, hcLogger hclog.Logger) error
- type AugmentorGrpcClient
- type AugmentorGrpcServer
- type AugmentorPlugin
- type AugmentorPluginInstaller
- func (i *AugmentorPluginInstaller) GetAllPlugins() ([]*PluginMeta, error)
- func (i *AugmentorPluginInstaller) GetPlugin(pluginUri string) error
- func (i *AugmentorPluginInstaller) GetRunCmd(entrypointPath string, execPath string) (*exec.Cmd, error)
- func (i *AugmentorPluginInstaller) Install(pluginDir string) (*PluginMeta, error)
- func (i *AugmentorPluginInstaller) InstallAll() ([]*PluginMeta, error)
- func (i *AugmentorPluginInstaller) ReadMetadata(pluginDir string) (*PluginMeta, error)
- func (i *AugmentorPluginInstaller) Uninstall(pluginId string) error
- type CfsPlugin
- type PluginManager
- func (m *PluginManager[T]) AddPlugin(id string, pluginI *CfsPlugin[T]) error
- func (m *PluginManager[T]) GetUnusedPlugins() []*CfsPlugin[T]
- func (m *PluginManager[T]) InitPlugin(id string, rawPlugin plugin.Plugin) error
- func (m *PluginManager[T]) LoadAllPlugins(pluginDir string) ([]*CfsPlugin[T], error)
- func (m *PluginManager[T]) Plugins() plugin.PluginSet
- func (m *PluginManager[T]) WriteMetaToState(meta *PluginMeta, stateCfgPath string) error
- type PluginMeta
Constants ¶
This section is empty.
Variables ¶
var AugmentPluginHandshake = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "AUG_PLUGIN",
MagicCookieValue: "2f4b473f573429bca56f545f02c6bac47cebcc3130fbdaf5e1a14dda66349d93",
}
Handshake is a common handshake that is shared by plugin and host.
var AugmentorManager = &PluginManager[aug.TemplateAugmentor]{ plugins: map[string]*CfsPlugin[aug.TemplateAugmentor]{}, }
Functions ¶
func ServeAugmentor ¶
func ServeAugmentor(augmentor aug.TemplateAugmentor, hcLogger hclog.Logger) error
Called by a Go plugin to serve an implementation of aug.TemplateAugmentor.
Types ¶
type AugmentorGrpcClient ¶
type AugmentorGrpcClient struct {
// contains filtered or unexported fields
}
RPC Client to get Augmentor function results from server
func (*AugmentorGrpcClient) Augment ¶
func (g *AugmentorGrpcClient) Augment() error
func (*AugmentorGrpcClient) Id ¶
func (g *AugmentorGrpcClient) Id() string
type AugmentorGrpcServer ¶
type AugmentorGrpcServer struct { proto.UnimplementedTemplateAugmentorServer // This is the real implementation Impl aug.TemplateAugmentor }
Here is the RPC server that AugmentorGrpcClient talks to, conforming to the requirements of net/rpc
func (*AugmentorGrpcServer) Id ¶
func (s *AugmentorGrpcServer) Id(ctx context.Context, req *proto.Empty) (*proto.IdResponse, error)
type AugmentorPlugin ¶
type AugmentorPlugin struct { plugin.Plugin // Impl is the interface Impl aug.TemplateAugmentor }
This is necessary for actually serving the interface implementation.
func (*AugmentorPlugin) GRPCClient ¶
func (p *AugmentorPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)
func (*AugmentorPlugin) GRPCServer ¶
func (p *AugmentorPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error
type AugmentorPluginInstaller ¶
type AugmentorPluginInstaller struct { ParentOutputPluginDir string // Separating because the logger != writer // i.e. when running plugins, the logger will not be a zap logger. // Uses hclog Writer io.Writer Logger *zap.Logger }
Abstracting the plugin installation process. Plugins are supplied with the following file structure:
pluginDir main.go augmentor_metadata.json
pluginDirs is a collection of paths to directories like the one above.
The installer will install all of those plugins in `parentOutputPluginDir`, which has a similar directory structure:
parentOutputPluginDir
plugin1 plugin1.exe augmentor_metadata.json plugin2 ...
func NewAugmentorPluginInstaller ¶
func NewAugmentorPluginInstaller(parentPluginDir string, pluginLogger hclog.Logger) (*AugmentorPluginInstaller, error)
func (*AugmentorPluginInstaller) GetAllPlugins ¶
func (i *AugmentorPluginInstaller) GetAllPlugins() ([]*PluginMeta, error)
Gets all installed plugins. It assumes that all plugins with a valid PluginMeta json file.
func (*AugmentorPluginInstaller) GetPlugin ¶
func (i *AugmentorPluginInstaller) GetPlugin(pluginUri string) error
func (*AugmentorPluginInstaller) GetRunCmd ¶
func (i *AugmentorPluginInstaller) GetRunCmd(entrypointPath string, execPath string) (*exec.Cmd, error)
Creates the command for running the plugin. `entrypoint` is not exactly the Entrypoint from PluginMeta. It is the full path to entrypoint. `execPath` should only be set if a language requires an executable to run the plugin.
Usage [Go]:
i.GetRunCmd("main.go", "./build/jchen42703/Example-Augmentor-go")
Usage [Python]: (No Build)
i.GetRunCmd("./plugin-python/plugin.py", "")
func (*AugmentorPluginInstaller) Install ¶
func (i *AugmentorPluginInstaller) Install(pluginDir string) (*PluginMeta, error)
This function installs a single Go RPC Plugin. CFS expects the pluginDir to lead to a directory that looks like:
... main.go augmentor_metadata.json
It also expects `outputPluginDir` to be a child directory of `i.parentOutputPluginDir`.
To install the plugin, this function: 1. Builds the plugin. 2. Validates the metadata. 3. Moves the built executable and metadata into the output plugin directory.
func (*AugmentorPluginInstaller) InstallAll ¶
func (i *AugmentorPluginInstaller) InstallAll() ([]*PluginMeta, error)
Use this when you want to install multiple plugins in a directory. parentPluginDir
plugin1 plugin2
func (*AugmentorPluginInstaller) ReadMetadata ¶
func (i *AugmentorPluginInstaller) ReadMetadata(pluginDir string) (*PluginMeta, error)
Reads the plugin metadata.
func (*AugmentorPluginInstaller) Uninstall ¶
func (i *AugmentorPluginInstaller) Uninstall(pluginId string) error
Uninstalls a plugin by deleting the plugin directory from the parent plugin directory i.e.
ParentOutputPluginDir plugin1 plugin2
Result from uninstalling `plugin1`:
ParentOutputPluginDir plugin2
type CfsPlugin ¶
type CfsPlugin[T any] struct { Plugin plugin.Plugin Meta *PluginMeta Used bool // strictly for when we start using plugins with a pipeline ExecPath string // executable path PluginClient *plugin.Client // Set in CfsPlugin.Load }
General struct for storing abstracting different types of plugins. The generic type is the interface the plugin implements.
type PluginManager ¶
type PluginManager[T any] struct { // contains filtered or unexported fields }
Manages the state of installed plugins and loads plugins. Store generic plugin struct because we might have different plugin types in the future. We only want each plugin manager to handle one type of interface.
func (*PluginManager[T]) AddPlugin ¶
func (m *PluginManager[T]) AddPlugin(id string, pluginI *CfsPlugin[T]) error
Adds a full plugin implementation to the manager. This should be called by the plugins to add a real implementation of a plugin instead of having a placeholder.
func (*PluginManager[T]) GetUnusedPlugins ¶
func (m *PluginManager[T]) GetUnusedPlugins() []*CfsPlugin[T]
Gets all unused plugins. This is needed for detecting new augmentations (a.k.a. plugins are that not used yet.)
func (*PluginManager[T]) InitPlugin ¶
func (m *PluginManager[T]) InitPlugin(id string, rawPlugin plugin.Plugin) error
Called by host to populate the host's plugin map with placeholder plugins that will be completed by the plugins.
func (*PluginManager[T]) LoadAllPlugins ¶
func (m *PluginManager[T]) LoadAllPlugins(pluginDir string) ([]*CfsPlugin[T], error)
Loads all plugins in directory using the state config. Adds those plugins to the manager state.
func (*PluginManager[T]) Plugins ¶
func (m *PluginManager[T]) Plugins() plugin.PluginSet
Gets all raw plugins. This is useful for specifying the plugins in plugin.ClientConfig and plugin.ServeConfig.
func (*PluginManager[T]) WriteMetaToState ¶
func (m *PluginManager[T]) WriteMetaToState(meta *PluginMeta, stateCfgPath string) error
Writes the current installed plugin state Need to be able to detect when state is corrupted (i.e. could not find state for installed executable) Plugin State: - version - install link - executable name
type PluginMeta ¶
type PluginMeta struct { Id string `json:"pluginId"` // GitHubUsername-NameOfPluginStruct; used to name the folder Version string `json:"version"` // could do a semi-ver, could be git commit hash, etc. InstallLink string `json:"installLink"` // i.e. https://github.com/xxxx/example-plugin-repo Entrypoint string `json:"entrypoint"` // used to determine how to build the plugin i.e. what main.go, plugin.py... }
Used to define plugin metadata. This struct will be written to a state config file whenever a plugin is installed.