shared

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package shared provides shared functionality for Privateer plugins.

Index

Constants

View Source
const (
	TestPass = iota
	TestFail
	Aborted
	InternalError
	BadUsage
	NoTests
)

Canonical exit codes. Defined here so command/ and pluginkit/ can both reference them without an import cycle.

View Source
const PluginName = "plugin"

PluginName is used by Privateer Core sally.go: rpcClient.Dispense(plugin.PluginName).

Variables

This section is empty.

Functions

func GetHandshakeConfig

func GetHandshakeConfig() hcplugin.HandshakeConfig

GetHandshakeConfig provides handshake config details. It is used by core and service packs.

func Serve

func Serve(pluginName string, opts *ServeOpts)

Serve serves a plugin. This function never returns and should be the final function called in the main function of the plugin.

Types

type Plugin

type Plugin struct {
	// Impl is the plugin implementation.
	Impl Pluginer
}

Plugin is the implementation of plugin.Plugin so we can serve/consume this.

This has two methods: Server must return an RPC server for this plugin type. We construct a PluginRPCServer for this.

Client must return an implementation of our interface that communicates over an RPC client. We return PluginRPC for this.

Ignore MuxBroker. That is used to create more multiplexed streams on our plugin connection and is a more advanced use case.

func (Plugin) Client

func (Plugin) Client(b *hcplugin.MuxBroker, c *rpc.Client) (interface{}, error)

Client implements RPC client.

func (*Plugin) Server

func (p *Plugin) Server(*hcplugin.MuxBroker) (interface{}, error)

Server implements RPC server.

type PluginRPC

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

PluginRPC is an implementation that talks over RPC.

func (*PluginRPC) Start

func (g *PluginRPC) Start() (int, error)

Start is a wrapper for interface implementation of Start.

type PluginRPCServer

type PluginRPCServer struct {
	// Impl is the real implementation.
	Impl Pluginer
}

PluginRPCServer is the RPC server that PluginRPC talks to, conforming to the requirements of net/rpc.

func (*PluginRPCServer) Start

func (s *PluginRPCServer) Start(args interface{}, resp *StartResponse) error

Start is a wrapper for interface implementation.

type Pluginer

type Pluginer interface {
	Start() (int, error)
}

Pluginer is the interface that we're exposing as a plugin. Start returns a privateer exit code (TestPass, TestFail, InternalError, BadUsage) and an optional error for diagnostic logging. Typed errors do not survive net/rpc, so classification must happen on the plugin side — see pluginkit.ExitCodeFor.

type ServeOpts

type ServeOpts struct {
	// Plugin is the interface implementation.
	Plugin Pluginer

	// Logger is the logger that go-plugin will use.
	Logger hclog.Logger
}

ServeOpts are the configurations to serve a plugin.

type StartResponse added in v1.24.0

type StartResponse struct {
	ExitCode int
	Err      string
}

Jump to

Keyboard shortcuts

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