api

package
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 33 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 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 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 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 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
	// PrometheusHTTP is the HTTP client for Prometheus; nil uses a default with a timeout.
	PrometheusHTTP *http.Client
	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 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 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 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 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