api

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: AGPL-3.0 Imports: 41 Imported by: 0

Documentation

Overview

Package api serves the Controller's public REST API, /api/v1. The contract is api/v1/openapi.yaml: requests are validated against it before any handler runs, including which endpoints need a signed-in caller, and the handlers implement the interface generated from it (package apigen).

Index

Constants

View Source
const BasePath = "/api/v1"

BasePath is where the API is mounted.

View Source
const SessionCookie = "__Host-shardkeep_session"

SessionCookie is the session cookie's name. The __Host- prefix makes browsers insist on Secure, Path=/ and no Domain, so no other host can set or read it.

Variables

This section is empty.

Functions

func DefaultAgentImage added in v1.15.0

func DefaultAgentImage(v string) string

DefaultAgentImage is the Agent image matching a Controller version: the release image of the same version, or, for development builds, the newest release.

Types

type BackupOps added in v1.18.0

type BackupOps interface {
	CreateBackup(ctx context.Context, nodeID, serverID, backupID, destinationID uuid.UUID, trigger domain.BackupTrigger) error
	DeleteStoredBackup(ctx context.Context, nodeID, destinationID uuid.UUID, key string) error
	ReadBackup(ctx context.Context, nodeID, destinationID uuid.UUID, key string, decrypt bool) (io.ReadCloser, error)
	// DestinationsChanged sends connected Agents the new destinations.
	DestinationsChanged()
}

BackupOps carries out backups through Agents.

type CatalogSync added in v1.13.0

type CatalogSync interface {
	Status() catalogsync.Status
}

CatalogSync reports how catalog syncs went.

type Deps

type Deps struct {
	Store   *store.Store
	Hasher  *auth.Hasher
	Limiter *auth.LoginLimiter
	Logger  *slog.Logger
	// CAPin is the SHA-256 of the Controller CA's public key, carried in
	// enrollment tokens.
	CAPin []byte
	// Nodes, if set, hears about changes connected Agents must learn of.
	Nodes NodeNotifier
	// Now returns the current time; nil means time.Now.
	Now func() time.Time
	// GamePorts is where game ports are assigned from; the zero value means
	// domain.DefaultGamePorts.
	GamePorts domain.PortRange
	Catalog   *catalog.Catalog
	Artifacts *artifacts.Cache
	// Ops carries out console and file operations through Agents.
	Ops ServerOps
	// CatalogSync reports catalog syncs; nil when the Controller never
	// syncs (-offline).
	CatalogSync CatalogSync
	// AgentImage is the Agent image to enroll new Nodes with; see
	// DefaultAgentImage.
	AgentImage string
	// Backups carries out backups through Agents; Workflows is woken when a
	// restore, migration or clone starts. Without them, those endpoints
	// answer 503.
	Backups   BackupOps
	Workflows Workflows
	// SetupCode guards first-run setup; without it, setup cannot be done
	// through the API.
	SetupCode *auth.SetupCode
}

Deps are the Server's collaborators.

type NodeNotifier added in v1.7.0

type NodeNotifier interface {
	NodeAdminChanged(nodeID uuid.UUID, state domain.NodeAdminState)
	// ServerChanged is called when a server's desired spec changed.
	ServerChanged(serverID uuid.UUID)
	// NetworkChanged is called when the network's profile, its secret or
	// a Node's address changed: the proxy and every Agent follow.
	NetworkChanged()
	// RotateCertificate asks a Node's Agent to rotate its certificate; it
	// fails when the Node is not connected.
	RotateCertificate(nodeID uuid.UUID) error
}

NodeNotifier is told about Node changes after they are committed, so it can push them to the Node's live session.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server implements the API.

func New

func New(d Deps) *Server

New returns a Server.

func (*Server) AcknowledgeServerCondition added in v1.5.0

AcknowledgeServerCondition records an administrator's acknowledgement of a condition, such as a safety stop.

func (*Server) AddTeamMember added in v1.4.0

AddTeamMember adds a user to a team.

func (*Server) ChangePassword

ChangePassword replaces the caller's password after checking the current one, and ends their other sessions. It needs a session: a stolen API token must not be able to take over the account.

func (*Server) ChangeServerSoftware added in v1.14.0

ChangeServerSoftware moves a server to another version or build of its software.

func (*Server) CloneServer added in v1.18.0

CloneServer starts copying parts of a server into another.

func (*Server) CompleteSetup added in v1.19.0

CompleteSetup creates the first administrator and the network, with the setup code from the Controller's machine, and signs in.

func (*Server) CreateBackupDestination added in v1.18.0

CreateBackupDestination adds a destination with a new age key pair and returns its private key, once.

func (*Server) CreateMyToken

CreateMyToken creates an API token and returns its secret, once. It needs a session, so a token can never mint another token, least of all one without its restrictions.

func (*Server) CreateNetwork added in v1.19.0

CreateNetwork sets the network up on a Controller whose first administrator was created on the command line.

func (*Server) CreateNode added in v1.5.0

CreateNode adds a Node awaiting enrollment.

func (*Server) CreateProxy added in v1.19.0

CreateProxy creates the network's Velocity proxy, published on the network's port.

func (*Server) CreateRole added in v1.4.0

CreateRole adds a custom role.

func (*Server) CreateRoleAssignment added in v1.4.0

CreateRoleAssignment gives a role to a user or a team at a scope.

func (*Server) CreateServer added in v1.5.0

CreateServer creates a server owned by a team, in PROVISIONING.

func (*Server) CreateServerBackup added in v1.18.0

CreateServerBackup asks the server's Node for a backup now.

func (*Server) CreateServerSchedule added in v1.18.0

CreateServerSchedule adds a schedule; the server's Agent runs it.

func (*Server) CreateTeam added in v1.4.0

CreateTeam adds a team.

func (*Server) CreateUser added in v1.4.0

CreateUser creates a user with a one-time password, returned once.

func (*Server) DeleteBackup added in v1.18.0

DeleteBackup deletes a stored backup and its record.

func (*Server) DeleteBackupDestination added in v1.18.0

DeleteBackupDestination removes a destination nothing uses.

func (*Server) DeleteMySession

DeleteMySession ends one of the caller's sessions.

DeleteNetworkLogo removes the logo.

func (*Server) DeleteNode added in v1.5.0

DeleteNode removes a Node no server is assigned to.

func (*Server) DeleteRole added in v1.4.0

DeleteRole deletes a custom role and its assignments.

func (*Server) DeleteRoleAssignment added in v1.4.0

DeleteRoleAssignment removes a role assignment.

func (*Server) DeleteServer added in v1.5.0

DeleteServer sets a server's desired state to DELETED.

func (*Server) DeleteServerFile added in v1.12.0

DeleteServerFile deletes a file or directory.

func (*Server) DeleteServerSchedule added in v1.18.0

DeleteServerSchedule removes a schedule; its backups stay.

func (*Server) DeleteTeam added in v1.4.0

DeleteTeam deletes a team that owns no servers.

func (*Server) DeleteUser added in v1.4.0

DeleteUser deletes a user; the audit log keeps their ID.

func (*Server) DisableNode added in v1.5.0

DisableNode cordons a Node.

func (*Server) DownloadBackup added in v1.18.0

DownloadBackup streams a backup, decrypted by a Node that can read it.

func (*Server) DownloadServerFile added in v1.12.0

DownloadServerFile returns a file's content.

func (*Server) EnableNode added in v1.5.0

EnableNode allows new placements on a Node again.

func (*Server) GetBackup added in v1.18.0

GetBackup returns a backup.

func (*Server) GetBackupDestination added in v1.18.0

GetBackupDestination returns a destination without its secrets.

func (*Server) GetCatalogPlugin added in v1.13.0

GetCatalogPlugin returns a plugin with its versions.

func (*Server) GetCatalogStatus added in v1.13.0

GetCatalogStatus describes the catalog snapshot in use and the latest sync attempt.

func (*Server) GetMe

GetMe returns the signed-in user.

func (*Server) GetMyPermissions added in v1.17.0

GetMyPermissions returns the caller's effective permissions: for an API token restricted to some permissions, only those.

func (*Server) GetNetwork added in v1.19.0

GetNetwork returns the network to any signed-in user.

GetNetworkLogo serves the logo, re-encoded as PNG when it was uploaded.

func (*Server) GetNode added in v1.5.0

GetNode returns a Node with its status and conditions.

func (*Server) GetPublicNetwork added in v1.19.0

GetPublicNetwork returns what the sign-in page shows: the name and logo.

func (*Server) GetRole added in v1.4.0

GetRole returns a role.

func (*Server) GetServer added in v1.5.0

GetServer returns a server's desired spec, observed status and convergence.

func (*Server) GetServerConsole added in v1.12.0

GetServerConsole follows a server's live console as Server-Sent Events.

func (*Server) GetServerProperties added in v1.12.0

GetServerProperties returns server.properties as key/value pairs.

func (*Server) GetSetup added in v1.19.0

GetSetup reports whether first-run setup is needed.

func (*Server) GetSystemInfo added in v1.15.0

GetSystemInfo describes this Controller.

func (*Server) GetTeam added in v1.4.0

GetTeam returns a team.

func (*Server) GetUser added in v1.4.0

GetUser returns a user.

func (*Server) GetUserPermissions added in v1.17.0

GetUserPermissions returns a user's effective permissions, as their sessions have them.

func (*Server) Handler

func (s *Server) Handler() (http.Handler, error)

Handler returns the handler for everything under BasePath. Requests pass, in order, through: cross-origin protection, a body size limit, authentication (resolving the caller, if any), the forced password change, validation against the OpenAPI contract, and the handlers.

func (*Server) InstallServerPlugin added in v1.14.0

InstallServerPlugin installs a catalog plugin and its dependencies.

func (*Server) IssueEnrollmentToken added in v1.6.0

IssueEnrollmentToken creates a one-time token an Agent uses to enroll the Node, and returns it once.

func (*Server) IssuePasswordReset added in v1.4.0

IssuePasswordReset creates a one-time reset link and returns its secret, once.

func (*Server) ListArtifacts added in v1.11.0

ListArtifacts lists the artifact cache.

func (*Server) ListAuditEvents added in v1.4.0

ListAuditEvents searches the audit log, newest first.

func (*Server) ListBackupDestinations added in v1.18.0

ListBackupDestinations lists destinations, without their secrets, to any signed-in user (to choose one).

func (*Server) ListCatalogPlugins added in v1.13.0

ListCatalogPlugins searches the plugin catalog.

func (*Server) ListMySessions

ListMySessions returns the caller's active sessions.

func (*Server) ListMyTokens

ListMyTokens returns the caller's API tokens, without their secrets.

func (*Server) ListNodes added in v1.5.0

ListNodes returns Nodes in creation order.

func (*Server) ListPermissions added in v1.4.0

ListPermissions returns the permission catalog.

func (*Server) ListRoleAssignments added in v1.4.0

ListRoleAssignments returns role assignments, optionally filtered.

func (*Server) ListRoles added in v1.4.0

ListRoles returns every role.

func (*Server) ListServerBackups added in v1.18.0

ListServerBackups lists a server's backups, newest first.

func (*Server) ListServerEvents added in v1.5.0

ListServerEvents returns a server's history, newest first.

func (*Server) ListServerFiles added in v1.12.0

ListServerFiles lists a directory of a server's files.

func (*Server) ListServerPlugins added in v1.14.0

ListServerPlugins lists a server's plugins.

func (*Server) ListServerSchedules added in v1.18.0

ListServerSchedules lists a server's schedules with their next runs.

func (*Server) ListServers added in v1.5.0

ListServers returns the servers the caller may read. A caller who may read none gets an empty list, not an error.

func (*Server) ListSoftware added in v1.11.0

ListSoftware lists the templates and their supported versions, from the catalog snapshot, or from the artifact cache before the first sync.

func (*Server) ListTeamMembers added in v1.4.0

ListTeamMembers returns a team's members.

func (*Server) ListTeams added in v1.4.0

ListTeams returns teams in creation order.

func (*Server) ListUsers added in v1.4.0

ListUsers returns users in creation order.

func (*Server) Login

Login checks a username and password and starts a session. Every failure looks the same to the client: unknown user, wrong password, disabled account or no password set.

func (*Server) Logout

Logout ends the caller's session and clears the cookie. With an API token there is no session to end; the cookie is cleared all the same.

func (*Server) MakeServerDirectory added in v1.12.0

MakeServerDirectory creates a directory.

func (*Server) MigrateServer added in v1.18.0

MigrateServer starts moving a server to another Node.

func (*Server) MoveServerFile added in v1.12.0

MoveServerFile moves or renames a file or directory.

func (*Server) PurgeExpiredSessions

func (s *Server) PurgeExpiredSessions(ctx context.Context)

PurgeExpiredSessions deletes sessions that can no longer be used.

func (*Server) RedeemPasswordReset

RedeemPasswordReset sets a new password with a one-time link and ends every session and API token of the user.

func (*Server) RemoveServerPlugin added in v1.14.0

RemoveServerPlugin removes a plugin from a server.

func (*Server) RemoveTeamMember added in v1.4.0

RemoveTeamMember removes a user from a team.

func (*Server) RestartServer added in v1.12.0

RestartServer asks the Agent to restart a running server gracefully.

func (*Server) RestoreServer added in v1.18.0

RestoreServer starts restoring one of a server's backups in place.

func (*Server) RevokeMyToken

RevokeMyToken revokes one of the caller's API tokens.

func (*Server) RevokeNode added in v1.5.0

RevokeNode revokes a Node for good.

func (*Server) RotateNodeCertificate added in v1.8.0

RotateNodeCertificate asks a connected Agent to rotate its certificate.

func (*Server) SendServerCommand added in v1.12.0

SendServerCommand types a command into a server's console.

SetNetworkLogo stores an uploaded PNG or JPEG logo. It is decoded and re-encoded as PNG, at most 256 pixels a side: no metadata or other content survives, and nothing but a bitmap is ever served back.

func (*Server) StartServer added in v1.5.0

StartServer sets a server's desired state to RUNNING.

func (*Server) StopServer added in v1.5.0

StopServer sets a server's desired state to STOPPED.

func (*Server) UpdateBackupDestination added in v1.18.0

UpdateBackupDestination changes a destination's settings.

func (*Server) UpdateNetwork added in v1.19.0

UpdateNetwork changes the network's profile and lobby.

func (*Server) UpdateNode added in v1.19.0

UpdateNode sets where other Nodes reach a Node.

func (*Server) UpdateRole added in v1.4.0

UpdateRole changes a custom role.

func (*Server) UpdateServer added in v1.12.0

UpdateServer changes a server's resources.

func (*Server) UpdateServerPlugin added in v1.14.0

UpdateServerPlugin moves a catalog plugin to another version.

func (*Server) UpdateServerProperties added in v1.12.0

UpdateServerProperties changes server.properties, keeping its comments.

func (*Server) UpdateServerSchedule added in v1.18.0

UpdateServerSchedule replaces a schedule.

func (*Server) UpdateTeam added in v1.4.0

UpdateTeam renames a team.

func (*Server) UpdateUser added in v1.4.0

UpdateUser changes a user. The audit event names the changed fields but does not copy personal data such as the email address into the log.

func (*Server) UploadArtifact added in v1.11.0

UploadArtifact stores an administrator's server jar as unverified.

func (*Server) UploadServerFile added in v1.12.0

UploadServerFile creates or replaces a file.

func (*Server) UploadServerPlugin added in v1.14.0

UploadServerPlugin installs a plugin jar a user supplied.

type ServerOps added in v1.12.0

type ServerOps interface {
	SendCommand(ctx context.Context, nodeID, serverID uuid.UUID, line string) error
	ListFiles(ctx context.Context, nodeID, serverID uuid.UUID, path string) ([]domain.FileEntry, bool, error)
	MakeDirectory(ctx context.Context, nodeID, serverID uuid.UUID, path string) error
	MoveFile(ctx context.Context, nodeID, serverID uuid.UUID, from, to string) error
	DeleteFile(ctx context.Context, nodeID, serverID uuid.UUID, path string) error
	Console(ctx context.Context, nodeID, serverID uuid.UUID, tail int) (io.ReadCloser, error)
	Download(ctx context.Context, nodeID, serverID uuid.UUID, path string) (io.ReadCloser, error)
	Upload(ctx context.Context, nodeID, serverID uuid.UUID, path string, content io.Reader) error
	ListPluginJars(ctx context.Context, nodeID, serverID uuid.UUID) (domain.PluginJars, error)
}

ServerOps carries out operations on a server through its Node's Agent.

type Workflows added in v1.18.0

type Workflows interface {
	Kick()
}

Workflows runs restores, migrations and clones.

Directories

Path Synopsis
Package apigen provides primitives to interact with the openapi HTTP API.
Package apigen provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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