pluginmain

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pluginmain is the common executable entrypoint helper for CloudPath process plugins. It reads the launch identity the A4 Plugin Host injects through the process environment, renders the single handshake line the host parses with pluginhost.ParseHandshake, dials the host's loopback endpoint, and serves an SDK RPC server over that authenticated transport.

This package is public and must never import internal/pluginhost, so the handshake format and environment contract are defined here independently and locked by the tests in this package.

Index

Constants

View Source
const (
	EnvPluginID        = "CLOUDPATH_PLUGIN_ID"
	EnvProtocol        = "CLOUDPATH_PROTOCOL"
	EnvProtocolVersion = "CLOUDPATH_PROTOCOL_VERSION"
	EnvLaunchID        = "CLOUDPATH_LAUNCH_ID"
	EnvProof           = "CLOUDPATH_PROOF"
	EnvPluginEndpoint  = "CLOUDPATH_PLUGIN_ENDPOINT"
)

Environment variables injected by the A4 Plugin Host. These names mirror the host contract in internal/pluginhost/handshake.go.

View Source
const HandshakeMarker = "CP1"

HandshakeMarker is the fixed first field of a plugin handshake line.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, out, errw io.Writer, newServer ServerFactory) error

Run is the standard plugin entrypoint: it validates the environment, prints the unique handshake line to out, dials the host, serves the RPC server and closes the transport. Diagnostics are written to errw; Proof is never written to out or errw except as the final field of the single handshake line.

func Serve

func Serve(ctx context.Context, cfg Config, newServer ServerFactory) error

Serve dials the host, builds the RPC server with newServer, serves frames until ctx is canceled or the transport closes, and then closes the transport. A canceled context is reported as nil: signal-driven shutdown is the normal plugin exit path.

Types

type Config

type Config struct {
	PluginID        string
	Protocol        string
	ProtocolVersion uint32
	LaunchID        string
	Proof           string
	Endpoint        pluginruntime.Endpoint
}

Config is the validated launch identity and endpoint for one plugin process.

func FromEnv

func FromEnv(getenv func(string) string) (Config, error)

FromEnv reads and validates the host-injected environment. getenv is os.Getenv in production and a map lookup in tests. Missing or malformed values fail fast; error messages never contain secret values such as Proof.

func (Config) Dial

func (c Config) Dial(ctx context.Context) (transport.Transport, error)

Dial connects to the host endpoint and authenticates with the launch credentials. The returned transport is ready for the SDK RPC server and must be closed by the caller.

func (Config) Handshake

func (c Config) Handshake() Handshake

Handshake builds the handshake for the configured launch. The transport and endpoint fields are the host endpoint the plugin is about to dial, matching what the host handed out in the environment.

type Handshake

type Handshake struct {
	Marker          string
	PluginID        string
	Protocol        string
	ProtocolVersion uint32
	Transport       string
	Endpoint        string
	RPC             string
	LaunchID        string
	Proof           string
}

Handshake is the public mirror of the host's parsed handshake record. Its String form is the canonical handshake line.

func (Handshake) String

func (h Handshake) String() string

String renders the canonical eight-field handshake line:

CP1|<plugin-id>|<protocol>=<version>|<transport>|<endpoint>|<rpc>|<launch-id>|<proof>

type ServerFactory

type ServerFactory func(tr transport.Transport) *rpc.Server

ServerFactory builds the protocol RPC server bound to an authenticated transport.

Jump to

Keyboard shortcuts

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