script

package
v0.0.0-...-d5eaaa5 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package script is the script plugin: it runs every executable file in a folder as a pipeline step, so a user can customize Cortex with a small Python or shell script instead of a Go plugin and a rebuild.

One pipeline entry, `script`, is one slot: the files directly in its folder (default ~/.cortex/plugins), in file-name order. Each file is a long-lived worker process (see internal/worker) that answers one JSON message per hook. Repeating `script` with a different `dir` puts a second slot elsewhere in the chain, which is how a Go plugin sits between two scripts.

A script declares, in its handshake, which hooks it implements and whether it enforces. It starts in shadow mode — its denies and edits are recorded and not applied — so trying a script cannot break a request. A script that errors (a crash, a timeout, a malformed reply) or does not start lets the request through unless its slot is fail_closed.

Scripts run only on a local install (plugins.Deps.LocalInstall). Anywhere else a `script` entry loads nothing, so a config that names one cannot run commands in a sidecar.

Index

Constants

View Source
const Name = "script"

Name is the plugin's registered name.

Variables

This section is empty.

Functions

func Fingerprint

func Fingerprint(dir string) string

Fingerprint is a digest of every script directly in dir — names, order and contents — so the reloader can tell that a slot changed even when the config file did not. Empty for an empty or missing directory.

func SlotDir

func SlotDir(dir string) (string, error)

SlotDir is the folder a slot's dir config names: ~/.cortex/plugins, or a folder directly inside it.

Types

type Script

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

Script is the plugin.

func New

func New() *Script

New returns an unconfigured instance.

func (*Script) Capabilities

func (s *Script) Capabilities() pipeline.PluginCapabilities

Capabilities is the ceiling until Configure, and after it what the slot is wherever scripts run: a request writer, empty or not. The response side is what still narrows to what the loaded scripts asked for — reading or rewriting responses — so a slot of request scripts does not cost every streamed response its streaming.

func (*Script) ConfigSchema

func (s *Script) ConfigSchema() []pipeline.FieldSchema

func (*Script) Configure

func (s *Script) Configure(raw json.RawMessage) error

Configure loads the slot's scripts and starts their workers. A script that will not start is skipped with a WARN, never failing the build: one broken file must not stop the proxy from starting or a config edit from applying. A fail_closed slot remembers it and refuses requests until a build in which it starts; see notStarted.

func (*Script) Init

func (s *Script) Init(context.Context) error

Init runs when this build's pipeline starts: from here its workers are the ones traffic uses, and anything an abandoned build left in the pool can go.

func (*Script) Metrics

func (s *Script) Metrics() []pipeline.Metric

Metrics reports the slot's counters on /v1/pipeline.

func (*Script) Name

func (s *Script) Name() string

func (*Script) OnRequest

func (s *Script) OnRequest(ctx context.Context, pctx *pipeline.Context) pipeline.Action

OnRequest runs every loaded script's request hook, in order. Each sees the request as the scripts before it left it, except that a shadow script's edits are not applied and so are not seen.

func (*Script) OnResponse

func (s *Script) OnResponse(ctx context.Context, pctx *pipeline.Context) pipeline.Action

OnResponse is never called: the pipeline sends a StreamingResponder's responses to OnResponseFrame instead, buffered or streamed. It exists for the Plugin interface, and runs the hooks should a caller use it directly.

func (*Script) OnResponseFrame

func (s *Script) OnResponseFrame(ctx context.Context, pctx *pipeline.Context, frame []byte, last bool) pipeline.Action

OnResponseFrame is how responses reach scripts. A buffered response arrives as one last frame with the whole body; a streamed one as each SSE event's payload, then an empty last frame — by then every byte is with the client, so the scripts read it and cannot change or block it. A script that rewrites responses narrows this plugin to WritesResponseBody, which sends streamed responses down the buffered path, where its edits apply.

func (*Script) SetLocalInstall

func (s *Script) SetLocalInstall(local bool)

SetLocalInstall is how plugins.BuildWithDeps tells the plugin it may run scripts.

func (*Script) Shutdown

func (s *Script) Shutdown(context.Context) error

Shutdown releases this build's workers when its pipeline has drained. A worker the running build also holds keeps running; an edited or removed script's old worker stops here, and not before.

Directories

Path Synopsis
Package catalog is the script plugins Cortex ships: each folder under entries/ is one entry, which installed is one slot.
Package catalog is the script plugins Cortex ships: each folder under entries/ is one entry, which installed is one slot.
internal
worker
Package worker runs one script as a long-lived child process and exchanges line-delimited JSON with it: one object per line on the child's stdin, one per line back on its stdout.
Package worker runs one script as a long-lived child process and exchanges line-delimited JSON with it: one object per line on the child's stdin, one per line back on its stdout.

Jump to

Keyboard shortcuts

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