api

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT, MIT Imports: 47 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 api is the HTTP control plane. This file is the request/response plumbing every route shares: the JSON envelope, query variables, cookies, the base URL, and the byte-level helpers the terminal and the tuning knobs need. Routes live in routes.go; the principal and the gate in principal.go.

Server: the control plane's remote surface. The route table is api.ts's header comment; the rules that matter are in AGENTS.md.

THIS API MUST NEVER MANAGE THE STACK IT RUNS IN (invariant 12). VARIABLES are merged from the request's `?query` (and a PUT's `env`) over the process env, once, at resolve time. SECURITY: every route but health/login/logout/bootstrap/sso is behind the principal gate; responses are built field by field and never echo a resolved Stack.Env.

Index

Constants

View Source
const WakeRetryMs = 60_000

WakeRetryMs: after a failed wake, how long a request to the hostname waits before trying again.

Variables

This section is empty.

Functions

func CrToNl

func CrToNl(b []byte) []byte

CrToNl is CR → NL for terminal input. With no pty there is no line discipline, so this is the only thing standing between "Enter" and a shell that never runs anything. CRLF collapses to ONE NL, or every Enter from a client that sends both would run the line and then an empty one. Same rule for text and binary frames.

Types

type Options

type Options struct {
	// DataDir is the registry root; deployments live under <DataDir>/deployments.
	DataDir string
	Port    int
	Host    string
	Token   string
	// RoutingDir is Traefik's dynamic-config directory. Default: the in-container mount path
	// /etc/traefik/dynamic; on a host-side run, <dataDir>/control/traefik-dynamic.
	RoutingDir string
	// RegistryDir is the DOCKER_CONFIG directory holding private-registry credentials. Default:
	// $DOCKER_CONFIG, else /docker-config.
	RegistryDir string
	// TerminalArgv opens a container shell. Default: docker exec -i <id> <shell>. Injectable for
	// the same reason Runner is: the machine this is developed on has no Docker.
	TerminalArgv func(containerID, shell string) []string
	// Readiness tuning; zero means the defaults (2s / 180s).
	ReadinessPollMs    int64
	ReadinessTimeoutMs int64
	// Domain is the preview domain (PSTACK_DOMAIN): share links and the SSO callback are built on
	// control.<domain>; without it the request's own origin is used.
	Domain string
	// MetricsURL is Traefik's Prometheus endpoint (PSTACK_TRAEFIK_METRICS). What sleep.idle reads.
	MetricsURL string
	// Scheduler tuning — a minute on a host, milliseconds in a test.
	SchedulerTickMs int64
	SchedulerFetch  scheduler.Fetcher
	// SSO: how long a half-finished sign-in is remembered (default 300s) and how long a provider's
	// discovery document is trusted (default 1h). Zero = default.
	SSOStateTTLS     int64
	SSODiscoveryTTLS int64
	// Bus defaults to events.Default.
	Bus *events.Bus
	// Env is the process environment the server hands to hooks and reads variables from; nil
	// means os.Environ().
	Env map[string]string
	// Log receives the scheduler's and the SSO adoption lines (stderr on a host).
	Log func(string)
	// Version is what /api/health reports.
	Version string
	// UIHTML and ShareHTML are the two embedded pages.
	UIHTML    string
	ShareHTML string
}

Options configure a server.

type Server

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

Server is one running control plane.

Owner of writeMu: the registry/spec mutations that were racy check-then-acts in the reference (PUT/DELETE deployment, DELETE spec, the sleep record). Everything else has its own owner.

func New

func New(o Options) (*Server, error)

New wires a server. Nothing listens until Start.

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr is the bound address.

func (*Server) Start

func (s *Server) Start() error

Start binds and serves in the background. Port 0 picks a free port; Addr() says which.

func (*Server) Stop

func (s *Server) Stop()

Stop is the reference's `server.stop`: stop listening, close the streams, detach from the bus, stop the followers, the readiness watches, the scheduler and the reindex loop. Jobs derive from context.Background and outlive this on purpose.

type Tuning

type Tuning struct {
	ReadinessPollMs    float64
	ReadinessTimeoutMs float64
	SSOStateTTLS       float64
	SSODiscoveryTTLS   float64
}

Tuning is what `serve` reads from the environment: the same four knobs a test passes as options, so a black-box harness driving the real CLI can reach the expiry paths. `??` semantics — unset means the default, and a value that is not a positive number is ignored rather than turning a timeout into NaN.

func TuningFromEnv

func TuningFromEnv(env func(string) (string, bool)) Tuning

TuningFromEnv reads the knobs.

Jump to

Keyboard shortcuts

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