Documentation
¶
Overview ¶
Package api implements the REST handlers for environment-scoped resources (ADR-0006): /api/v1/environments and /api/v1/environments/{env}/...
Index ¶
- Constants
- func EnvFrom(ctx context.Context) *environment.Environment
- func GitWebhook(auto *gitstacks.Auto, logger *slog.Logger) http.HandlerFunc
- func IncomingWebhook(svc *webhooks.Service, logger *slog.Logger) http.HandlerFunc
- func Namespace(r *http.Request) (string, error)
- func ReadOnlyReason(st runtime.NerdctlStatus) string
- type AuditLog
- type AutoUpdates
- type AutoUpdatesLog
- type BuildRequest
- type BulkActionRequest
- type BulkActionResult
- type CheckImageUpdatesRequest
- type CreateContainerRequest
- type Environment
- type EnvironmentStatus
- type EventHistory
- type ExecExit
- type Features
- type GitAutoRequest
- type GitStackRequest
- type Handler
- type HistoryEvent
- type ImageUpdates
- type JobFrame
- type NamespaceSpec
- type NotificationChannelInput
- type NotificationChannelView
- type NotificationStore
- type NotificationTestInput
- type PrometheusCheck
- type PrometheusSettings
- type PrometheusSettingsInput
- type RecreateContainerRequest
- type RemoveImagesResult
- type Settings
- type StackLogLine
- type StackOperationRequest
- type StackPathSaved
- type StackValidation
- type SummaryResponse
- type TopContainer
- type TopStats
Constants ¶
const ( StatusConnected = "connected" )
Environment statuses.
const ( BuildFromDockerfile = "dockerfile" BuildFromGit = "git" BuildFromArchive = "archive" )
Sources of an image build.
const AllNamespaces = "*"
AllNamespaces lists the containers of every namespace (#276), as the event stream already accepts.
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
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
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 ¶
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 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 BuildRequest ¶
type BuildRequest struct {
// Source is dockerfile, git or archive.
Source string `json:"source"`
// Dockerfile is the text of the Dockerfile (dockerfile); it builds with an empty context.
Dockerfile string `json:"dockerfile,omitempty"`
// URL, Ref and CredentialID select a Git repository (git), as for Git stacks.
URL string `json:"url,omitempty"`
Ref string `json:"ref,omitempty"`
CredentialID *int64 `json:"credentialId,omitempty"`
// Context is the directory of the context inside the repository (git); empty is its root.
Context string `json:"context,omitempty"`
// File is the Dockerfile's path inside the context (git, archive); empty is "Dockerfile".
File string `json:"file,omitempty"`
Tags []string `json:"tags"`
Args map[string]string `json:"args,omitempty"`
Target string `json:"target,omitempty"`
Platform string `json:"platform,omitempty"`
NoCache bool `json:"noCache,omitempty"`
Pull bool `json:"pull,omitempty"`
// Push pushes every tag after the build.
Push bool `json:"push,omitempty"`
}
BuildRequest builds an image (#45, ADR-0061). 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"`
// Warnings are host problems the runtime does not report (ADR-0060); local hosts only.
Warnings []hostcheck.Warning `json:"warnings,omitempty"`
}
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
// HostPaths are where the local host's settings are read for warnings (ADR-0060); empty
// means /proc and /sys.
HostPaths hostcheck.Paths
// 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. Image
// builds from Git use it too.
GitStacks *gitstacks.Service
// BuildDir holds the contexts of image builds while they run (#45, ADR-0061); empty uses
// the system's temporary directory.
BuildDir string
// 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.
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.
Source Files
¶
- audit.go
- backup.go
- container_actions.go
- container_create.go
- container_exec.go
- container_logs.go
- container_stats.go
- container_top.go
- containers.go
- environments.go
- event_history.go
- events.go
- git_auto.go
- git_stacks.go
- host_metrics.go
- image_archive.go
- image_build.go
- image_history.go
- image_updates.go
- images.go
- jobs.go
- metrics_history.go
- namespaces.go
- networks.go
- notifications.go
- ports.go
- prune.go
- registries.go
- schedules.go
- stack_files.go
- stack_logs.go
- stack_services.go
- stack_tree.go
- stacks.go
- summary.go
- templates.go
- variables.go
- volume_backups.go
- volume_files.go
- volumes.go
- webhooks.go