Documentation
¶
Overview ¶
Package exec is the subprocess adapter: it runs `executable` implementations, and `script` implementations in r / python / node (sugar for an executable with the conventional interpreter), under the OpenFlange CLI protocol (openflange.org/cli/v0.1).
The simple protocol is implemented here: one input on stdin, one output on stdout, stderr as diagnostics, exit status as outcome, parameters in OPENFLANGE_PARAM_* and in the 0600 JSON file named by OPENFLANGE_CONFIG. Additional ports use a transport that is pluggable through Adapter.Extra (see ExtraPorts); the default, Endpoints, is the baseline: authenticated HTTP endpoints on 127.0.0.1 from which the executable GETs additional inputs and to which it POSTs additional outputs. With Extra set to nil, a node with enabled additional ports is rejected before execution with E_UNSUPPORTED.
A subprocess is NOT a sandbox. Declared permissions are checked against the consumer's grants before the process starts (the planner refuses a node without the `subprocess` grant), the environment is minimal, and no shell is involved, but the operating system does not restrict what the program does.
Index ¶
- Constants
- func EnvName(param string) string
- type Adapter
- func (a *Adapter) Capabilities() []adapter.Capability
- func (a *Adapter) Check(ctx context.Context, n *adapter.Node) error
- func (a *Adapter) Location(*manifest.Implementation) adapter.Location
- func (a *Adapter) Name() string
- func (a *Adapter) Run(ctx context.Context, n *adapter.Node, nio *adapter.IO) (err error)
- func (a *Adapter) Supports(impl *manifest.Implementation) bool
- func (a *Adapter) SupportsBatch(impl *manifest.Implementation) bool
- type BatchConfig
- type Config
- type Endpoints
- type ExtraPorts
- type ExtraSession
- type PortConfig
- type UsageConfig
- type UsageSession
Constants ¶
const ConfigSpec = "openflange.org/cli/v0.1"
ConfigSpec is the spec identifier written into the config file.
const DefaultGrace = 5 * time.Second
DefaultGrace is the time between SIGTERM and SIGKILL on cancellation.
const DefaultMaxBatchFileBytes = 1 << 30
DefaultMaxBatchFileBytes bounds one batch output file.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adapter ¶
type Adapter struct {
// MaxBatchFileBytes bounds the output of one batch with file delivery
// (default DefaultMaxBatchFileBytes); more is E_RESOURCE.
MaxBatchFileBytes int64
// Grace is the SIGTERM → SIGKILL delay (default DefaultGrace).
Grace time.Duration
// Extra provides the transport for ports beyond stdin/stdout. Nil means
// multi-port executables are reported as E_UNSUPPORTED.
Extra ExtraPorts
// LookPath finds interpreters and bare commands (default exec.LookPath).
LookPath func(file string) (string, error)
// Environ returns the runner's environment (default os.Environ); only the
// allow-listed and granted variables are passed on.
Environ func() []string
}
Adapter runs nodes as subprocesses.
func New ¶
func New() *Adapter
New returns the adapter with defaults: additional ports are served by the authenticated loopback HTTP transport (NewEndpoints).
func (*Adapter) Capabilities ¶
func (a *Adapter) Capabilities() []adapter.Capability
Capabilities implements adapter.Adapter: the interpreters are probed on PATH so that `openflange version --capabilities` is truthful.
func (*Adapter) Check ¶
Check resolves the command, verifies that the program or interpreter exists (before anything is executed) and maps ports to transports.
func (*Adapter) Location ¶
func (a *Adapter) Location(*manifest.Implementation) adapter.Location
Location implements adapter.Adapter.
func (*Adapter) Supports ¶
func (a *Adapter) Supports(impl *manifest.Implementation) bool
Supports implements adapter.Adapter.
func (*Adapter) SupportsBatch ¶
func (a *Adapter) SupportsBatch(impl *manifest.Implementation) bool
SupportsBatch implements adapter.BatchAdapter: executables, and scripts run by an interpreter, receive slices in the framing of the CLI specification.
type BatchConfig ¶
type BatchConfig struct {
MaxItems int `json:"maxItems"`
MaxWaitMs int `json:"maxWaitMs"`
Delivery string `json:"delivery"`
Dir string `json:"dir,omitempty"` // file delivery: the directory of the batch files
}
BatchConfig is the `batch` member of the config document.
type Config ¶
type Config struct {
Spec string `json:"spec"`
Pipe struct {
ID string `json:"id"`
Version string `json:"version"`
} `json:"pipe"`
Parameters map[string]any `json:"parameters"`
Inputs map[string]PortConfig `json:"inputs"`
Outputs map[string]PortConfig `json:"outputs"`
Token string `json:"token,omitempty"`
Batch *BatchConfig `json:"batch,omitempty"` // batch mode (batchio.go)
Usage *UsageConfig `json:"usage,omitempty"` // usage reporting (cli/v0.1 5.3)
}
Config is the JSON document a subprocess finds at $OPENFLANGE_CONFIG.
type Endpoints ¶
type Endpoints struct{}
Endpoints is the baseline transport for additional ports (openflange.org/cli/v0.1 §6) and for usage reporting (§5.3): one authenticated HTTP listener on 127.0.0.1 per node execution. The executable GETs each additional input (the response body is the stream) and POSTs each additional output (the request body is the stream), sending `Authorization: Bearer <token>`.
The listener is bound on an ephemeral loopback port before the process starts and is closed, with every open connection, when the process has exited. The token has 256 bits of entropy, is scoped to one node execution and is only ever written to the 0600 configuration file. Requests whose Host header is not the loopback address the listener is bound to are refused, so a web page cannot reach an endpoint through DNS rebinding.
func NewEndpoints ¶
func NewEndpoints() *Endpoints
NewEndpoints returns the loopback HTTP transport.
type ExtraPorts ¶
type ExtraPorts interface {
Start(ctx context.Context, n *adapter.Node, io *adapter.IO, inputs, outputs []string) (ExtraSession, error)
}
ExtraPorts is the extension point for ports that are not bound to stdin/stdout. The baseline transport is HTTP on 127.0.0.1: the executable GETs additional inputs and POSTs additional outputs with a bearer token.
Start is called before the process is started, with the names of the enabled extra input and output ports. The implementation owns the endpoint lifecycle: it must be listening when Start returns, pump io.In(port) to attached readers and attached writers into io.Out(port).
type ExtraSession ¶
type ExtraSession interface {
// Port returns the config entry (transport, url) for an extra port.
Port(name string) PortConfig
// Token is the opaque credential scoped to this execution. It is only
// ever written to the 0600 config file.
Token() string
// Finish is called after the process exited (procErr is nil for exit 0).
// It completes the streams (an enabled output that was never attached is
// an empty completed stream after a clean exit) and returns the first
// transport error.
Finish(ctx context.Context, procErr error) error
// Close releases the endpoints. It is always called, after Finish.
Close() error
}
ExtraSession is one node execution's set of extra endpoints.
type PortConfig ¶
type PortConfig struct {
Enabled bool `json:"enabled"`
Transport string `json:"transport,omitempty"` // stdin | stdout | http
URL string `json:"url,omitempty"`
MediaType string `json:"mediaType,omitempty"`
}
PortConfig is one port entry of the config file.
type UsageConfig ¶
type UsageConfig struct {
URL string `json:"url"`
}
UsageConfig is the `usage` member of the config document: the endpoint to which the executable may POST usage counters with the bearer token.
type UsageSession ¶
type UsageSession interface {
UsageURL() string
}
UsageSession is an optional interface of an ExtraSession that also receives usage counters (cli/v0.1 section 5.3). UsageURL returns the loopback URL to announce as `usage.url`, or "" when it offers none. Counters go to the node's report through adapter.IO.ReportUsage.