api

package
v0.2.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 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 implements the REST handlers for environment-scoped resources (ADR-0006): /api/v1/environments and /api/v1/environments/{env}/...

Index

Constants

View Source
const (
	StatusConnected   = "connected"
	StatusUnavailable = "unavailable"
)

Environment statuses.

Variables

This section is empty.

Functions

func EnvFrom

func EnvFrom(ctx context.Context) *environment.Environment

EnvFrom returns the environment resolved from the {env} path parameter.

func GitWebhook added in v0.2.0

func GitWebhook(auto *gitstacks.Auto, logger *slog.Logger) http.HandlerFunc

GitWebhook handles push webhooks of Git stacks (#38): the secret token in the path selects the stack. A payload naming another ref than the stack's is ignored; otherwise the remote is checked in the background and a new commit is announced or deployed:

POST /api/v1/hooks/git/{token}

func IncomingWebhook added in v0.2.0

func IncomingWebhook(svc *webhooks.Service, logger *slog.Logger) http.HandlerFunc

IncomingWebhook runs the webhook of the secret token in the path as a job; the body is ignored (#85, #91):

POST /api/v1/hooks/{token}

func Namespace

func Namespace(r *http.Request) (string, error)

Namespace returns the containerd namespace for the request: the "namespace" query parameter, or the environment's default. Invalid names are rejected (ADR-0006).

func ReadOnlyReason

func ReadOnlyReason(st runtime.NerdctlStatus) string

ReadOnlyReason explains why an environment is read-only.

Types

type AuditLog added in v0.2.0

type AuditLog interface {
	List(ctx context.Context, f audit.Filter) ([]audit.Entry, error)
}

AuditLog reads the audit log (#79); *audit.Recorder implements it.

type AutoUpdates added in v0.2.0

type AutoUpdates interface {
	Log(ctx context.Context, env, namespace string, limit int) ([]updates.Entry, error)
	PendingFor(env string) (updates.Pending, bool)
	Approve(ctx context.Context, env *environment.Environment) (int, error)
	Settings(ctx context.Context, env string) (updates.AutoSettings, error)
	SetSettings(ctx context.Context, env string, s updates.AutoSettings) error
}

AutoUpdates is the log of automatic updates (#54, ADR-0032); *updates.Updater implements it.

type AutoUpdatesLog added in v0.2.0

type AutoUpdatesLog struct {
	Entries []updates.Entry  `json:"entries"`
	Pending *updates.Pending `json:"pending,omitempty"`
}

AutoUpdatesLog is the log and the updates waiting for approval. Keep in sync with api/openapi.yaml.

type BulkActionRequest

type BulkActionRequest struct {
	Action  runtime.Action `json:"action"`
	IDs     []string       `json:"ids"`
	Force   bool           `json:"force,omitempty"`
	Volumes bool           `json:"volumes,omitempty"`
}

BulkActionRequest is the body of POST /containers/actions. Keep in sync with api/openapi.yaml.

type BulkActionResult

type BulkActionResult struct {
	ID    string                `json:"id"`
	OK    bool                  `json:"ok"`
	Error *httpjson.ErrorDetail `json:"error,omitempty"`
}

BulkActionResult is the outcome for one container.

type CheckImageUpdatesRequest added in v0.1.1

type CheckImageUpdatesRequest struct {
	Ref string `json:"ref,omitempty"`
}

CheckImageUpdatesRequest checks one reference, or all used ones when empty.

type CreateContainerRequest

type CreateContainerRequest struct {
	runtime.CreateSpec
	// Start runs the container after creating it (like `nerdctl run -d`).
	Start bool `json:"start"`
}

CreateContainerRequest is the body of POST /containers. Keep in sync with api/openapi.yaml.

type Environment

type Environment struct {
	ID               string `json:"id"`
	Name             string `json:"name"`
	Kind             string `json:"kind"`
	DefaultNamespace string `json:"defaultNamespace"`
}

Environment is the API representation. Keep in sync with api/openapi.yaml.

type EnvironmentStatus

type EnvironmentStatus struct {
	Environment
	Status  string            `json:"status"` // connected | unavailable
	Error   string            `json:"error,omitempty"`
	Runtime *runtime.Versions `json:"runtime,omitempty"`
	// Features reports server settings the UI adapts to.
	Features Features `json:"features"`
}

EnvironmentStatus adds live connectivity information.

type EventHistory

type EventHistory interface {
	ListEvents(ctx context.Context, arg db.ListEventsParams) ([]db.Event, error)
}

EventHistory reads recorded events (#65, ADR-0021); *db.Queries implements it.

type ExecExit

type ExecExit struct {
	ExitCode int `json:"exitCode"`
}

ExecExit is the last data message of a terminal session.

type Features

type Features struct {
	// Exec is false when the web terminal is disabled (--disable-exec).
	Exec bool `json:"exec"`
	// MetricsHistory is true when a Prometheus connection is configured (#176).
	MetricsHistory bool `json:"metricsHistory"`
}

Features of the server for an environment.

type GitAutoRequest added in v0.2.0

type GitAutoRequest struct {
	AutoUpdate   string `json:"autoUpdate"`
	PollInterval int64  `json:"pollInterval"`
}

GitAutoRequest sets what happens on new commits. Keep in sync with api/openapi.yaml.

type GitStackRequest added in v0.2.0

type GitStackRequest struct {
	gitstacks.CreateRequest
	Deploy bool `json:"deploy"`
}

GitStackRequest creates a Git stack; Deploy runs `compose up` after cloning and needs stacks:deploy. Keep in sync with api/openapi.yaml.

type Handler

type Handler struct {
	Envs *environment.Registry
	Jobs *jobs.Manager
	// EventHistory serves the event feed (#65); nil when recording is disabled.
	EventHistory EventHistory
	// ExecDisabled turns off the web terminal (--disable-exec, #15).
	ExecDisabled bool
	// Settings stores per-environment settings such as the Prometheus connection (#176);
	// nil disables them.
	Settings Settings
	// Stacks finds compose stacks (#24, ADR-0008); nil disables them.
	Stacks *stacks.Service
	// GitStacks deploys stacks from Git repositories (#37, ADR-0039); nil disables them.
	GitStacks *gitstacks.Service
	// Webhooks are the incoming webhooks (#85, #91); nil disables them.
	Webhooks *webhooks.Service
	// ImageUpdates checks images for newer registry digests (#53); nil disables it.
	ImageUpdates ImageUpdates
	// AutoUpdates is the log of automatic updates (#54); nil disables it.
	AutoUpdates AutoUpdates
	// Notifications stores notification channels and Notifier sends through them (#86); nil
	// disables them.
	Notifications NotificationStore
	Notifier      *notify.Service
	// Audit serves the audit log (#79); nil disables it.
	Audit AuditLog
	// PrometheusHTTP is the HTTP client for Prometheus; nil uses a default with a timeout.
	PrometheusHTTP *http.Client
	// Backup is what an application backup contains (#89); nil disables backups.
	Backup *backup.Source
	// Schedules are the scheduled jobs (#82); nil disables them.
	Schedules *scheduler.Service
	// Variables are the global and per-stack variables (#35); nil disables them.
	Variables *variables.Service
	// VolumeBackups back up and restore volumes (#59); nil disables them.
	VolumeBackups *volbackup.Service
	// Templates are the stack templates (#33, #34); nil disables them.
	Templates *templates.Service
	// HostMetrics samples the host nerdui runs on (#64); nil disables host metrics.
	HostMetrics *hostmetrics.Sampler
	Logger      *slog.Logger
}

Handler serves environment endpoints.

func (*Handler) Routes

func (h *Handler) Routes(r chi.Router, g *authz.Guard)

Routes registers the environment endpoints under the API root.

type HistoryEvent

type HistoryEvent struct {
	ID         int64             `json:"id"`
	Timestamp  time.Time         `json:"ts"`
	Namespace  string            `json:"namespace,omitempty"`
	Topic      string            `json:"topic"`
	Kind       string            `json:"kind"`
	Action     string            `json:"action"`
	ObjectID   string            `json:"objectId,omitempty"`
	ObjectName string            `json:"objectName,omitempty"`
	Attributes map[string]string `json:"attributes,omitempty"`
}

HistoryEvent is a recorded event. Keep in sync with api/openapi.yaml.

type ImageUpdates added in v0.1.1

type ImageUpdates interface {
	Overview(ctx context.Context, env *environment.Environment, ns string) (updates.Overview, error)
	Check(ctx context.Context, env *environment.Environment, ref string) (updates.Report, error)
}

ImageUpdates checks images for newer registry digests (#53, ADR-0030); *updates.Checker implements it.

type JobFrame

type JobFrame struct {
	Job    *jobs.Job `json:"job,omitempty"`
	Output string    `json:"output,omitempty"`
	Reset  bool      `json:"reset,omitempty"`
}

JobFrame is a data message of a job stream: the job state and/or terminal output. The first frame carries the job and the stored output with reset set.

type NamespaceSpec

type NamespaceSpec struct {
	Name string `json:"name"`
}

NamespaceSpec creates a namespace (#195).

type NotificationChannelInput added in v0.2.0

type NotificationChannelInput struct {
	Name    string        `json:"name"`
	Type    string        `json:"type"`
	Config  notify.Config `json:"config"`
	Events  []string      `json:"events"`
	Enabled bool          `json:"enabled"`
}

NotificationChannelInput creates or replaces a channel. Empty secrets keep the stored ones while the type is unchanged. Keep in sync with api/openapi.yaml.

type NotificationChannelView added in v0.2.0

type NotificationChannelView struct {
	ID     int64         `json:"id"`
	Name   string        `json:"name"`
	Type   string        `json:"type"`
	Config notify.Config `json:"config"`
	// Secrets names the write-only config fields that are set.
	Secrets    []string   `json:"secrets"`
	Events     []string   `json:"events"`
	Enabled    bool       `json:"enabled"`
	LastSentAt *time.Time `json:"lastSentAt,omitempty"`
	LastError  string     `json:"lastError,omitempty"`
}

NotificationChannelView is a channel without its secrets. Keep in sync with api/openapi.yaml.

type NotificationStore added in v0.2.0

type NotificationStore interface {
	ListNotificationChannels(ctx context.Context) ([]db.NotificationChannel, error)
	GetNotificationChannel(ctx context.Context, id int64) (db.NotificationChannel, error)
	CreateNotificationChannel(ctx context.Context, arg db.CreateNotificationChannelParams) (db.NotificationChannel, error)
	UpdateNotificationChannel(ctx context.Context, arg db.UpdateNotificationChannelParams) (db.NotificationChannel, error)
	DeleteNotificationChannel(ctx context.Context, id int64) (int64, error)
}

NotificationStore stores notification channels (#86); *db.Queries implements it.

type NotificationTestInput added in v0.2.0

type NotificationTestInput struct {
	NotificationChannelInput
	ID int64 `json:"id,omitempty"`
}

NotificationTestInput sends a test through a channel's settings before they are saved; with an ID, empty secrets come from that stored channel.

type PrometheusCheck

type PrometheusCheck struct {
	Version string `json:"version,omitempty"`
	// Containers is the number of containers with containerd CPU metrics in Prometheus.
	Containers int `json:"containers"`
}

PrometheusCheck is the result of testing a connection.

type PrometheusSettings

type PrometheusSettings struct {
	Configured bool   `json:"configured"`
	URL        string `json:"url,omitempty"`
	Auth       string `json:"auth,omitempty"`
	Username   string `json:"username,omitempty"`
	HasSecret  bool   `json:"hasSecret"`
}

PrometheusSettings is the API view of an environment's Prometheus connection (#176): the secret is write-only. Keep in sync with api/openapi.yaml.

type PrometheusSettingsInput

type PrometheusSettingsInput struct {
	URL      string `json:"url"`
	Auth     string `json:"auth"`
	Username string `json:"username"`
	Secret   string `json:"secret"`
}

PrometheusSettingsInput sets the connection. An empty secret keeps the stored one when the authentication mode is unchanged.

type RecreateContainerRequest added in v0.1.1

type RecreateContainerRequest struct {
	runtime.CreateSpec
	// Pull pulls the image first: an update to the tag's newest image.
	Pull bool `json:"pull"`
}

RecreateContainerRequest replaces a container (#18). Keep in sync with api/openapi.yaml.

type RemoveImagesResult

type RemoveImagesResult struct {
	Reference string                `json:"reference"`
	OK        bool                  `json:"ok"`
	Error     *httpjson.ErrorDetail `json:"error,omitempty"`
}

RemoveImagesResult reports the removal of one reference. Keep in sync with api/openapi.yaml.

type Settings

type Settings interface {
	GetSetting(ctx context.Context, key string) (string, error)
	SetSetting(ctx context.Context, arg db.SetSettingParams) error
	DeleteSetting(ctx context.Context, key string) (int64, error)
}

Settings stores key/value settings; *db.Queries of the write connection implements it.

type StackLogLine

type StackLogLine struct {
	Service     string `json:"service"`
	Container   string `json:"container,omitempty"`
	ContainerID string `json:"containerId"`
	runtime.LogLine
}

StackLogLine is a log line of a stack's container (#30). Keep in sync with api/openapi.yaml.

type StackOperationRequest

type StackOperationRequest struct {
	runtime.ComposeOptions
	Confirm string `json:"confirm,omitempty"`
}

StackOperationRequest modifies a stack operation. Confirm must repeat the stack name when Volumes is set: `down -v` deletes the project's volumes.

type StackPathSaved added in v0.2.0

type StackPathSaved struct {
	File       stacks.PathFile `json:"file"`
	Validation StackValidation `json:"validation"`
}

StackPathSaved is the result of saving a file by its path: the file, and whether the project still loads with it. Keep in sync with api/openapi.yaml.

type StackValidation

type StackValidation struct {
	Valid    bool     `json:"valid"`
	Error    string   `json:"error,omitempty"`
	Line     int      `json:"line,omitempty"`
	Services []string `json:"services"`
}

StackValidation is the result of checking compose and .env content (#26). Line is the line of the error in the compose file when the loader reports it. Keep in sync with api/openapi.yaml.

type SummaryResponse

type SummaryResponse struct {
	runtime.Summary
	// Stacks counts stacks with known files and compose projects seen in container labels.
	Stacks int `json:"stacks"`
}

SummaryResponse is the dashboard of a host (#63). Keep in sync with api/openapi.yaml.

type TopContainer

type TopContainer struct {
	ID            string  `json:"id"`
	Name          string  `json:"name,omitempty"`
	Namespace     string  `json:"namespace"`
	CPUPercent    float64 `json:"cpuPercent"`
	MemoryUsage   uint64  `json:"memoryUsage"`
	MemoryPercent float64 `json:"memoryPercent"`
}

TopContainer is a running container's latest sample (#63).

type TopStats

type TopStats struct {
	Time    time.Time      `json:"ts"`
	Running int            `json:"running"`
	CPU     []TopContainer `json:"cpu"`
	Memory  []TopContainer `json:"memory"`
}

TopStats is one message of the top stream.

Directories

Path Synopsis
Package ws is the shared WebSocket layer for streams (ADR-0007): logs, stats, events, job progress and exec.
Package ws is the shared WebSocket layer for streams (ADR-0007): logs, stats, events, job progress and exec.

Jump to

Keyboard shortcuts

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