plugin

package
v1.508.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

grpc.go hides all the complexity of doing the gRPC calls between the aspect Core and a Plugin implementation by providing simple abstractions from the point of view of Plugin maintainers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AspectPluginFile

type AspectPluginFile struct {
	Path string
}

AspectPluginFile contains metadata for the aspectplugins file relevant for a plugin.

func NewAspectPluginFile

func NewAspectPluginFile(path string) *AspectPluginFile

NewAspectPluginFile creates a new AspectPluginFile.

type Base

type Base struct{}

Base satisfies the Plugin interface. For plugins that only implement a subset of the Plugin interface, using this as a base will give the advantage of not needing to implement the empty methods.

func (*Base) BEPEventCallback

func (*Base) BEPEventCallback(*buildeventstream.BuildEvent) error

BEPEventCallback satisfies Plugin.BEPEventCallback.

func (*Base) CustomCommands

func (*Base) CustomCommands() ([]*Command, error)

CustomCommands satisfies Plugin.BEPEventCallback.

func (*Base) PostBuildHook

func (*Base) PostBuildHook(bool, ioutils.PromptRunner) error

PostBuildHook satisfies Plugin.PostBuildHook.

func (*Base) PostRunHook

func (*Base) PostRunHook(bool, ioutils.PromptRunner) error

PostRunHook satisfies Plugin.PostRunHook.

func (*Base) PostTestHook

func (*Base) PostTestHook(bool, ioutils.PromptRunner) error

PostTestHook satisfies Plugin.PostTestHook.

func (*Base) Setup

func (*Base) Setup(*SetupConfig) error

Setup satisfies Plugin.Setup.

type Command

type Command struct {
	*proto.Command
	Run CustomCommandFn
}

Command defines the information needed to create a custom command that will be callable when running the CLI.

func NewCommand

func NewCommand(
	use string,
	shortDesc string,
	longDesc string,
	run CustomCommandFn,
) *Command

NewCommand is a wrapper around Command. Designed to be used as a cleaner way to make a Command given Command's nested proto

type CommandManager

type CommandManager interface {
	Save(commands []*Command) error
	Execute(command string, ctx context.Context, args []string, bazelStartupArgs []string) error
}

CommandManager is internal to the SDK and is used to manage custom commands that are provided by plugins.

type CustomCommandFn

type CustomCommandFn (func(ctx context.Context, args []string, bazelStartupArgs []string) error)

CustomCommandFn defines the parameters of that the Run functions will be called with.

type GRPCClient

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

GRPCClient implements the gRPC client that is used by the Core to communicate with the Plugin instances.

func (*GRPCClient) BEPEventCallback

func (m *GRPCClient) BEPEventCallback(event *buildeventstream.BuildEvent) error

BEPEventCallback is called from the Core to execute the Plugin BEPEventCallback.

func (*GRPCClient) CustomCommands

func (m *GRPCClient) CustomCommands() ([]*Command, error)

CustomCommands is called from the Core to execute the Plugin CustomCommands. It returns a list of commands that the plugin implements.

func (*GRPCClient) ExecuteCustomCommand

func (m *GRPCClient) ExecuteCustomCommand(customCommand string, ctx context.Context, args []string, bazelStartupArgs []string) error

ExecuteCustomCommand is called from the Core to execute the sdk ExecuteCustomCommand.

func (*GRPCClient) PostBuildHook

func (m *GRPCClient) PostBuildHook(isInteractiveMode bool, promptRunner ioutils.PromptRunner) error

PostBuildHook is called from the Core to execute the Plugin PostBuildHook. It starts the prompt runner server with the provided PromptRunner.

func (*GRPCClient) PostRunHook

func (m *GRPCClient) PostRunHook(isInteractiveMode bool, promptRunner ioutils.PromptRunner) error

PostRunHook is called from the Core to execute the Plugin PostRunHook. It starts the prompt runner server with the provided PromptRunner.

func (*GRPCClient) PostTestHook

func (m *GRPCClient) PostTestHook(isInteractiveMode bool, promptRunner ioutils.PromptRunner) error

PostTestHook is called from the Core to execute the Plugin PostTestHook. It starts the prompt runner server with the provided PromptRunner.

func (*GRPCClient) Setup

func (m *GRPCClient) Setup(config *SetupConfig) error

Setup is called from the Core to execute the Plugin Setup.

type GRPCPlugin

type GRPCPlugin struct {
	goplugin.Plugin
	Impl Plugin
}

GRPCPlugin represents a Plugin that communicates over gRPC.

func (*GRPCPlugin) GRPCClient

func (p *GRPCPlugin) GRPCClient(ctx context.Context, broker *goplugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)

GRPCClient returns a client to perform the RPC calls to the Plugin instance from the Core.

func (*GRPCPlugin) GRPCServer

func (p *GRPCPlugin) GRPCServer(broker *goplugin.GRPCBroker, s *grpc.Server) error

GRPCServer registers an instance of the GRPCServer in the Plugin binary.

type GRPCServer

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

GRPCServer implements the gRPC server that runs on the Plugin instances.

func (*GRPCServer) BEPEventCallback

func (m *GRPCServer) BEPEventCallback(
	ctx context.Context,
	req *proto.BEPEventCallbackReq,
) (*proto.BEPEventCallbackRes, error)

BEPEventCallback translates the gRPC call to the Plugin BEPEventCallback implementation.

func (*GRPCServer) CustomCommands

func (m *GRPCServer) CustomCommands(
	ctx context.Context,
	req *proto.CustomCommandsReq,
) (*proto.CustomCommandsRes, error)

CustomCommands translates the gRPC call to the Plugin CustomCommands implementation. It returns a list of commands that the plugin implements.

func (*GRPCServer) ExecuteCustomCommand

ExecuteCustomCommand translates the gRPC call to the sdk ExecuteCustomCommand implementation.

func (*GRPCServer) PostBuildHook

func (m *GRPCServer) PostBuildHook(
	ctx context.Context,
	req *proto.PostBuildHookReq,
) (*proto.PostBuildHookRes, error)

PostBuildHook translates the gRPC call to the Plugin PostBuildHook implementation. It starts a prompt runner that is passed to the Plugin instance to be able to perform prompt actions to the CLI user.

func (*GRPCServer) PostRunHook

func (m *GRPCServer) PostRunHook(
	ctx context.Context,
	req *proto.PostRunHookReq,
) (*proto.PostRunHookRes, error)

PostRunHook translates the gRPC call to the Plugin PostRunHook implementation. It starts a prompt runner that is passed to the Plugin instance to be able to perform prompt actions to the CLI user.

func (*GRPCServer) PostTestHook

func (m *GRPCServer) PostTestHook(
	ctx context.Context,
	req *proto.PostTestHookReq,
) (*proto.PostTestHookRes, error)

PostTestHook translates the gRPC call to the Plugin PostTestHook implementation. It starts a prompt runner that is passed to the Plugin instance to be able to perform prompt actions to the CLI user.

func (*GRPCServer) Setup

func (m *GRPCServer) Setup(
	ctx context.Context,
	req *proto.SetupReq,
) (*proto.SetupRes, error)

Setup translates the gRPC call to the Plugin Setup implementation.

type Plugin

type Plugin interface {
	BEPEventCallback(event *buildeventstream.BuildEvent) error
	CustomCommands() ([]*Command, error)
	PostBuildHook(
		isInteractiveMode bool,
		promptRunner ioutils.PromptRunner,
	) error
	PostTestHook(
		isInteractiveMode bool,
		promptRunner ioutils.PromptRunner,
	) error
	PostRunHook(
		isInteractiveMode bool,
		promptRunner ioutils.PromptRunner,
	) error
	Setup(config *SetupConfig) error
}

Plugin determines how an aspect Plugin should be implemented.

type PluginCommandManager

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

PluginCommandManager is internal to the SDK and is used to manage custom commands that are provided by plugins.

func (*PluginCommandManager) Execute

func (cm *PluginCommandManager) Execute(command string, ctx context.Context, args []string, bazelStartupArgs []string) error

Execute satisfies CommandManager.

func (*PluginCommandManager) Save

func (cm *PluginCommandManager) Save(commands []*Command) error

Save satisfies CommandManager.

type PrompterGRPCClient

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

PrompterGRPCClient implements the gRPC client that is used by the Plugin instance to communicate with the Core to request prompt actions from the user.

func (*PrompterGRPCClient) Run

func (p *PrompterGRPCClient) Run(prompt promptui.Prompt) (string, error)

Run is called from the Plugin to request the Core to run the given promptui.Prompt.

type PrompterGRPCServer

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

PrompterGRPCServer implements the gRPC server that runs on the Core and is passed to the Plugin to allow prompt actions to the CLI user.

func (*PrompterGRPCServer) Run

Run translates the gRPC call to perform a prompt Run on the Core.

type SetupConfig

type SetupConfig struct {
	File       *AspectPluginFile
	Properties []byte
}

SetupConfig represents a plugin configuration parsed from the aspectplugins file.

func NewSetupConfig

func NewSetupConfig(
	properties []byte,
) *SetupConfig

NewSetupConfig creates a new SetupConfig.

Directories

Path Synopsis
Package mock contains generated files.
Package mock contains generated files.

Jump to

Keyboard shortcuts

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