contracts

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package contracts holds rig's contracts: the named sources and actions a plugin provides to stand in for a kind of tool (metrics/1, scm/1, ...), with their arguments and frame fields, a conformance check, bridges that let a plugin serve rig's built-in screens, and standard views.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bridge

func Bridge(kind core.Kind, c Caller, plugin, component string, pr *protocol.Provides) (any, error)

Bridge is component, served by plugin through the contract for kind, as the core interface that kind's screens and commands use. Every call carries the component's name, so one plugin can serve several components. The bridge has every optional interface of the kind, and core.As admits only those whose capability pr provides.

func IDs

func IDs() []string

IDs are every contract's id, sorted.

Types

type Action

type Action struct {
	Effect  string            `yaml:"effect"`
	Args    map[string]string `yaml:"args"`
	Outputs map[string]string `yaml:"outputs"`
}

type ActionFunc

type ActionFunc func(ctx context.Context, a protocol.Args, out io.Writer) (protocol.Args, error)

type Caller

type Caller interface {
	Query(ctx context.Context, name string, args protocol.Args) (*protocol.Frame, error)
	Run(ctx context.Context, name string, args protocol.Args, dryRun bool) (*protocol.RunResult, error)
	Stream(ctx context.Context, name string, args protocol.Args) (<-chan protocol.StreamBatch, error)
}

Caller reaches a plugin's sources and actions by their namespaced names: the plugin host.

type Capability

type Capability struct {
	Sources []string `yaml:"sources"`
	Actions []string `yaml:"actions"`
}

Capability is an optional group of sources and actions a plugin provides all of or none.

type Captured

type Captured struct {
	Argv, Env []string
	Dir       string
}

Captured is the command an attach would have run on a terminal, caught instead of run.

func CaptureOf

func CaptureOf(ctx context.Context) *Captured

CaptureOf is the Captured to fill, or nil when ctx asks to run the command.

func WithCapture

func WithCapture(ctx context.Context) (context.Context, *Captured)

WithCapture asks an adapter to fill the returned Captured and return instead of running an interactive command (exec, shell): the plugin serving it has no terminal, the caller does.

type Contract

type Contract struct {
	ID          string                `yaml:"contract"`
	Kind        string                `yaml:"kind"`
	Description string                `yaml:"description"`
	Sources     map[string]Source     `yaml:"sources"`
	Actions     map[string]Action     `yaml:"actions"`
	Caps        map[string]Capability `yaml:"capabilities"`
	// View is the standard view's YAML, for contracts no built-in screen shows.
	View []byte `yaml:"-"`
}

Contract is one contract version. Args and fields map a name to a protocol type; an arg type ending in ! is required.

func ForKind

func ForKind(kind string) *Contract

ForKind is the contract that stands in for a component kind (runtime, metrics, ...), or nil.

func Get

func Get(id string) *Contract

Get returns a contract by id (metrics/1); a bare name means its version 1.

func (*Contract) ArgsSchema

func (c *Contract) ArgsSchema(name string) protocol.Schema

ArgsSchema is the JSON Schema of a source's or action's arguments, as a plugin declares them.

func (*Contract) Check

func (c *Contract) Check(p *protocol.Provides) []Problem

Check compares what a plugin says it provides with c: every source and action outside a capability is there, streams stream, and a capability is all there or not at all.

func (*Contract) CheckFrames

func (c *Contract) CheckFrames(ctx context.Context, q Querier, plugin string, p *protocol.Provides) []Problem

CheckFrames queries every source p provides that needs no arguments and checks the frame's fields: each one the contract names is present with its type (a plugin may add more).

func (*Contract) Has

func (c *Contract) Has(p *protocol.Provides, name string) bool

Has says whether p provides every source and action of capability name.

type Lookup

type Lookup struct {
	Component func(ctx context.Context, name string) (any, error)
	Service   func(name string) (*spec.Service, error)
}

Lookup finds what a call names: its component (args.component) and services.

type Problem

type Problem struct {
	Name, Text string
}

Problem is one way a plugin falls short of a contract.

func (Problem) String

func (p Problem) String() string

type Querier

type Querier interface {
	Query(ctx context.Context, name string, args protocol.Args) (*protocol.Frame, error)
}

Querier is what a live check calls: the host, with names already namespaced by the plugin.

type Served

type Served struct {
	Contract *Contract
	Sources  map[string]SourceFunc
	Streams  map[string]StreamFunc
	Actions  map[string]ActionFunc
	Effects  map[string]string
}

Served is a component kind's side of its contract, the reverse of Bridge: what a plugin registers (names without the plugin prefix) to stand in for components it builds in-process.

func Serve

func Serve(kind core.Kind, probe any, l Lookup) (*Served, error)

Serve is the contract for kind served by components that look like probe (a nil pointer of the adapter's type will do): only the optional interfaces probe's type has are served.

type Source

type Source struct {
	Stream bool              `yaml:"stream"`
	Args   map[string]string `yaml:"args"`
	Fields map[string]string `yaml:"fields"`
}

type SourceFunc

type SourceFunc func(ctx context.Context, a protocol.Args) (*protocol.Frame, error)

type StreamFunc

type StreamFunc func(ctx context.Context, a protocol.Args, emit func(*protocol.Frame) error) error

Jump to

Keyboard shortcuts

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