Documentation
¶
Overview ¶
Package server provides Boxy's REST API and optional web dashboard.
Package server provides the HTTP server that serves both the JSON REST API and the optional web dashboard for Boxy.
The server takes a store.Store as its data source and exposes the Boxy REST API for pools, resources, and sandboxes. Sandbox creation/deletion is served here, while the web UI (Go templates + HTMX) can be toggled via the UIEnabled option.
Index ¶
- Variables
- type APIRoute
- type AgentAdmin
- type CatalogPackage
- type CatalogPool
- type CatalogSnapshot
- type CatalogSource
- type CatalogSourceEntry
- type CatalogStore
- type CatalogTemplate
- type OIDCOptions
- type PoolMaintenance
- type PoolResourceMaintenance
- type ResourceCleanup
- type SandboxExecutor
- type Server
- type ServerOptions
- type SessionSweeper
Constants ¶
This section is empty.
Variables ¶
var ErrResourceBusy = errors.New("resource has an active execution")
ErrResourceBusy is returned before a second execution can be persisted for the same provider resource.
Functions ¶
This section is empty.
Types ¶
type APIRoute ¶ added in v0.1.34
APIRoute describes a documented REST route. Keep this catalog adjacent to route registration and regenerate docs/api.md after changing the API.
func APIRouteCatalog ¶ added in v0.1.34
func APIRouteCatalog() []APIRoute
APIRouteCatalog is the source of truth for the checked-in REST reference.
type AgentAdmin ¶
type AgentAdmin interface {
ListAgents() []pool.AgentSummary
Revoke(ctx context.Context, agentID, reason string, forceOrphanResources bool) error
RequestAgentLogs(ctx context.Context, agentID string, since time.Time, limit int) (string, error)
WaitForAgentLogs(ctx context.Context, requestID string) error
}
AgentAdmin exposes operator actions against the agent transport for API handlers — a narrow seam (same pattern as PoolMaintenance) implemented by internal/agentserver.Server.
type CatalogPackage ¶ added in v0.1.55
type CatalogPool ¶ added in v0.1.55
type CatalogSnapshot ¶ added in v0.1.55
type CatalogSnapshot struct {
Templates []CatalogTemplate
Packages []CatalogPackage
Sources []CatalogSourceEntry
Stores []CatalogStore
Pools []CatalogPool
}
CatalogSnapshot contains only fields that are safe and useful to render in the operator catalog. Sensitive configuration (credentials, secret references, arbitrary config maps, and source metadata) deliberately has no field in this view model.
type CatalogSource ¶ added in v0.1.55
type CatalogSource interface {
LoadCatalog(ctx context.Context) (CatalogSnapshot, error)
}
CatalogSource is the narrow, read-only seam between daemon configuration and the dashboard catalog. Implementations should return a startup snapshot rather than exposing mutable configuration or provider objects.
func NewStaticCatalogSource ¶ added in v0.1.55
func NewStaticCatalogSource(snapshot CatalogSnapshot) CatalogSource
NewStaticCatalogSource wraps an immutable copy of snapshot for daemon wiring and tests. Every load returns another copy so neither the server nor a caller can mutate the stored startup snapshot through shared slices.
type CatalogSourceEntry ¶ added in v0.1.55
type CatalogStore ¶ added in v0.1.55
type CatalogTemplate ¶ added in v0.1.55
type OIDCOptions ¶ added in v0.1.53
type OIDCOptions struct {
// Issuer is the provider's issuer URL, exposed to the CLI (via
// GET /auth/cli-config) so `boxy login --oidc` can run its own
// discovery -- the CLI talks to the provider directly for the
// device-code grant, it does not proxy through this server.
Issuer string
OAuth2 oauth2.Config
// Verifier checks the audience against the confidential web client
// (OAuth2.ClientID) -- used only by the browser callback.
Verifier *oidc.IDTokenVerifier
// RoleClaim names the ID token claim whose value(s) are looked up in
// RoleMapping. May be a single string or an array of strings.
RoleClaim string
// RoleMapping maps a RoleClaim value to a Boxy role.
RoleMapping map[string]string
// DefaultRole is used when no RoleClaim value matches RoleMapping.
// Empty fails closed (login rejected).
DefaultRole model.APIKeyRole
// CLIClientID, if set, is the public (no-secret) OAuth2 client ID
// `boxy login --oidc` uses for the device-code grant. Empty means
// CLI OIDC login is unavailable (GET /auth/cli-config 404s).
CLIClientID string
// CLIVerifier checks the audience against CLIClientID rather than the
// web client -- an ID token minted for the CLI's own device-flow
// client carries that audience, not the web client's, so reusing
// Verifier here would always fail with an audience mismatch. Set
// only when CLIClientID is.
CLIVerifier *oidc.IDTokenVerifier
// PersonalKeyMaxTTL bounds how long a self-service personal API key
// minted via POST /api/v1/api-keys/oidc-exchange may live.
PersonalKeyMaxTTL time.Duration
// LoginLabel and LoginIcon customize the browser SSO login button.
LoginLabel string
LoginIcon string
// HideLocalLogin hides the local username/password form when true.
HideLocalLogin bool
}
OIDCOptions configures browser login against an external OpenID Connect provider. Built by the caller (internal/cli/serve.go, from config.ServerSpec.OIDC) since constructing OAuth2/Verifier requires a live discovery fetch against the issuer -- this package stays free of any config-file decoding concern, the same separation ServerOptions already keeps for TLS material and guest secrets.
type PoolMaintenance ¶
type PoolMaintenance interface {
Drain(ctx context.Context, poolName model.PoolName) (model.Pool, error)
Fill(ctx context.Context, poolName model.PoolName) (model.Pool, error)
}
PoolMaintenance performs operator pool maintenance actions for API handlers.
type PoolResourceMaintenance ¶ added in v0.1.65
type PoolResourceMaintenance interface {
DestroyResource(context.Context, model.Resource) error
RetryResource(context.Context, model.Resource) error
}
PoolResourceMaintenance performs provider-backed mutations for one tracked pool resource. Jobs use the resource's origin pool as their lock target.
type ResourceCleanup ¶ added in v0.1.59
type ResourceCleanup interface {
Purge(ctx context.Context, request pool.CleanupRequest) (pool.CleanupReport, error)
}
ResourceCleanup performs the shared, confirmation-protected resource purge workflow used by the REST API and web dashboard.
type SandboxExecutor ¶ added in v0.1.34
type SandboxExecutor interface {
ExecuteSandbox(ctx context.Context, resource model.Resource, operation providersdk.ExecOperation, sink eventstream.Sink) (*providersdk.Result, error)
}
SandboxExecutor is the application seam used by the REST exec endpoint. Implementations own provider-specific operation construction and agent routing; the server owns request validation and HTTP event encoding.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the HTTP server for the Boxy REST API and optional web UI.
func New ¶
func New(st store.Store, sm *sandbox.Manager, pm PoolMaintenance, aa AgentAdmin, addr string, uiEnabled bool) *Server
New creates a Server that will listen on addr. It retains the in-process, unauthenticated HTTP behavior used by tests and embedded callers; the daemon uses NewWithOptions to enable authenticated TLS by default. If uiEnabled is true, the web dashboard is served at /.
func NewWithOptions ¶ added in v0.1.34
func NewWithOptions(st store.Store, sm *sandbox.Manager, pm PoolMaintenance, aa AgentAdmin, addr string, uiEnabled bool, opts ServerOptions) *Server
NewWithOptions creates a daemon-configured HTTP server.
type ServerOptions ¶ added in v0.1.34
type ServerOptions struct {
AuthRequired bool
InsecureHTTP bool
TLSCertPEM []byte
TLSKeyPEM []byte
Executor SandboxExecutor
JobRunner *jobs.Runner
ResourceCleanup ResourceCleanup
GuestSecrets boxysecrets.Store
// Catalog is an immutable, startup-time view of configured templates,
// packages, sources, stores, and pool relationships for the UI.
Catalog CatalogSource
// Diagnostics is the bounded, redacted operational log store. When nil,
// the diagnostics endpoint reports that diagnostics are unavailable.
Diagnostics diagnostics.Store
// DiagnosticsAudit receives safe metadata for every diagnostics query.
DiagnosticsAudit diagnostics.AuditSink
// OIDC enables provider login on the web UI's /login page. nil (the
// default) means only the bootstrapped local admin account can log
// in -- see docs/superpowers/specs/2026-08-28-oidc-ui-and-cli-auth-design.md.
OIDC *OIDCOptions
// SessionTTL bounds how long a web-UI login session lasts, regardless
// of how it was established (OIDC or the local-admin account). Zero
// defaults to 12h (see session.go's defaultSessionTTL).
SessionTTL time.Duration
// Version is displayed in the dashboard footer. Empty defaults to dev.
Version string
}
ServerOptions controls transport security and API authentication.
type SessionSweeper ¶ added in v0.1.53
type SessionSweeper struct {
// contains filtered or unexported fields
}
SessionSweeper deletes expired sessions from the store. Without this, state.json would grow every session record ever minted for the life of the daemon, and AuthenticateSession's ListSessions-plus-linear-scan (the same pattern as API-key auth) would keep scanning stale entries on every UI request forever. Wired into the daemon's existing 10s reconcile tick (internal/cli/serve.go's serveLoop) alongside the sandbox deletion reconciler, rather than as a new standalone ticker.
func NewSessionSweeper ¶ added in v0.1.53
func NewSessionSweeper(st store.Store) *SessionSweeper
NewSessionSweeper returns a SessionSweeper backed by st.
func (*SessionSweeper) Reconcile ¶ added in v0.1.53
func (sw *SessionSweeper) Reconcile(ctx context.Context) error
Reconcile deletes every session past its ExpiresAt. Matches the Reconcile(ctx) error shape internal/cli/serve.go's serveSandboxReconciler interface already expects, so it plugs into the existing reconcile pass with no new interface.
Source Files
¶
- api_agents.go
- api_catalog.go
- api_diagnostics.go
- api_exec.go
- api_jobs.go
- api_keys.go
- api_oidc.go
- api_pool_configuration.go
- api_pools.go
- api_resources.go
- api_sandboxes.go
- auth.go
- catalog.go
- doc.go
- execution_manager.go
- oidc.go
- profile.go
- server.go
- session.go
- ui.go
- ui_csrf.go
- ui_diagnostics.go
- ui_diagnostics_timeline.go
- ui_pools.go