api

package
v0.31.5 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: GPL-3.0 Imports: 37 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 defines the HTTP surface served at the apex host: JSON endpoints under /api/ plus the embedded dashboard SPA at /.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware added in v0.9.0

func AuthMiddleware(d Deps, next http.Handler) http.Handler

AuthMiddleware gates /api/* behind a GitHub identity when SSO is configured; it returns next unchanged when SSO is off, so an unconfigured instance keeps its historical open API. A request is allowed when it carries either a valid personal-access token (Authorization: Bearer — CSRF-immune, so no Origin check) or a valid apex session cookie (with an Origin check on state-changing methods). Login, health, the HMAC-authenticated webhook, the OIDC-gated uploads, and all non-API paths are exempt.

func NewMux

func NewMux(d Deps) *http.ServeMux

NewMux returns the apex-host handler: API routes plus the dashboard SPA.

Types

type BuildInfo

type BuildInfo struct {
	Version string `json:"version"`
}

BuildInfo describes the running binary; mirrored from cmd/server so the api package doesn't import it.

type Deps

type Deps struct {
	Store  *db.Store
	Build  BuildInfo
	Config config.Config
	Git    *gitrepo.Manager
	Queue  *build.Queue
	Super  *supervise.Manager
	// Runtime is the live-process view handlers render from; nil falls back
	// to Super (single-node). Super stays alongside it for control-node-local
	// lifecycle work (artifact GC, container purges) that never moves to
	// workers.
	Runtime RuntimeView
	// Cloner runs registrations' mirror clones in the background and holds
	// their live progress.
	Cloner *clone.Cloner
	// Watcher, when set, is kicked after watch settings change so a newly
	// watched repo polls immediately instead of waiting an interval.
	Watcher *watch.Watcher
	// Files locates published artifacts on disk (downloadable-artifact
	// listings and downloads).
	Files *store.Store
	// Sweeper runs retention sweeps (POST /api/gc).
	Sweeper *retain.Sweeper
	// DBPath is the SQLite location actually opened (":memory:" for
	// --in-memory), not Config's default — storage reporting sizes the real
	// database, never a stale file from a previous on-disk run.
	DBPath string
	// GitHubWebhookSecret validates X-Hub-Signature-256 on webhook
	// deliveries; empty disables POST /api/webhooks/github.
	GitHubWebhookSecret string
	// UploadAuth authenticates upload requests against GitHub Actions OIDC.
	// When non-nil, every upload must present a valid token whose repository
	// claim matches the target repo's source; nil leaves uploads
	// unauthenticated (the default, matching the rest of the API).
	UploadAuth UploadVerifier
	// MaxUploadBytes caps the compressed request body an upload may stream
	// before the server rejects it with 413, bounding the bytes an untrusted
	// (auth-exempt by default) client can push before extraction. 0 disables
	// the wire cap; the store's decompression cap still bounds expansion.
	MaxUploadBytes int64
	// SSO authenticates interactive dashboard logins (browser session cookie)
	// and programmatic callers (GitHub personal-access token as a bearer),
	// both against one allowlist. nil disables authentication entirely — the
	// API stays open, as it was before SSO existed.
	SSO SSOProvider
	// DashboardOrigin is the scheme://host the dashboard is served from,
	// derived from --sso-callback-url. State-changing API requests must carry
	// this Origin (CSRF defense), and preview-auth redirects target it.
	DashboardOrigin string
	// CookiesSecure marks session cookies Secure (HTTPS-only). Derived from the
	// callback URL: true for https and for localhost (a secure context even
	// over plain http).
	CookiesSecure bool
	// WarmPolicy reads the effective warm policy and SetWarmPolicy persists a
	// new one and applies it everywhere processes run (the local manager, and
	// every worker via the fleet's reconcile loop). Both nil disables the
	// endpoints (tests that don't care).
	WarmPolicy    func() WarmPolicy
	SetWarmPolicy func(p WarmPolicy) error
	// FleetStats returns the control node's fleet runtime rollup for the
	// statistics view (worker count, capacity, warm/cold totals). nil on a
	// single node, where handleStats falls back to the local Manager.
	FleetStats func() FleetSummary
}

Deps carries the dependencies handlers need.

type FleetSummary added in v0.17.1

type FleetSummary struct {
	Workers    int
	Running    int
	Capacity   int // 0 = unbounded
	WarmHits   int64
	ColdStarts int64
}

FleetSummary is the runtime rollup a control node's fleet registry provides: fresh worker count, committed and bounded capacity, and cumulative warm/cold EnsureRunning counts summed across workers. Deps.FleetStats returns it (nil on a single node, where the stats handler falls back to the local Manager).

type RuntimeView added in v0.14.0

type RuntimeView interface {
	Status(k supervise.Key) string
	LastFailure(k supervise.Key) (supervise.Failure, bool)
	CrashedKeys() []supervise.Key
	Stats(ctx context.Context, k supervise.Key) *supervise.ProcessStats
	RunLog(repoName, side, hash string, attempt int, offset int64) (supervise.RunLog, error)
	Stop(k supervise.Key, reason string)
	StopRepo(repoID int64, reason string)
	// Exec bridges an interactive exec session (execstream frames on stream)
	// into the container backing k — directly on a single node, forwarded to
	// the worker holding the process on a control node.
	Exec(ctx context.Context, k supervise.Key, opts supervise.ExecOptions, stream io.ReadWriter) error
}

RuntimeView is where the dashboard's live process state comes from: status, crash detail, resource samples, run logs, and stop. On a single node it is the local *supervise.Manager; on a control node whose previews run on workers it is the fleet registry, which merges the workers' reports — the local Manager tracks nothing there, so reading it would render every preview "idle" with no stats and empty run logs.

type SSOProvider added in v0.9.0

type SSOProvider interface {
	AuthCodeURL(state string) string
	Exchange(ctx context.Context, code string) (githubsso.Identity, error)
	VerifyToken(ctx context.Context, token string) (githubsso.Identity, error)
}

SSOProvider runs the GitHub OAuth web flow and resolves a token (an OAuth code or a personal-access token) to an allowlisted identity. *githubsso.Provider implements it; tests substitute a fake so no network or GitHub app is needed.

type UploadVerifier added in v0.9.0

type UploadVerifier interface {
	Verify(ctx context.Context, rawToken string) (githuboidc.Claims, error)
}

UploadVerifier verifies an upload's bearer token and returns the GitHub Actions OIDC claims it carries. *githuboidc.Verifier implements it; tests substitute a fake so verification needs no network.

type WarmPolicy added in v0.16.0

type WarmPolicy struct {
	MaxWarm            int `json:"max_warm"`
	MinWarm            int `json:"min_warm"`
	IdleTimeoutSeconds int `json:"idle_timeout_seconds"`
}

WarmPolicy shapes the warm-process footprint at runtime, per serving node: MaxWarm is the soft *target* — beyond it the reaper prunes the least-recently-used processes that are actually idle, but never actively-used ones, so bursts are served in full and pruned back once quiet (0 = unlimited). MinWarm is the floor — that many most-recent processes are exempt from idle timeouts, keeping the previews a developer is most likely to revisit hot indefinitely. IdleTimeoutSeconds overrides every manifest's idle_timeout when > 0 (0 = per-manifest values, default 30m).

Jump to

Keyboard shortcuts

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