Help us shape the future of Go! Take the 2026 Go Developer Survey

api

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package api serves shed's HTTP interface: the JSON API under /api, the server-sent event log streams, the GitHub App setup flow and webhook, and the dashboard single-page app.

Handlers are thin: they decode the request, call the control plane, map its errors to statuses, and encode the result as the JSON types of the design document.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthStore

func AuthStore(st *store.Store) auth.Store

AuthStore adapts the store to auth.Store.

Types

type Config

type Config struct {
	Control  Control
	Settings Settings
	// Restart shuts shed down gracefully and starts it again. The API calls
	// it after installing an update.
	Restart func()
	Auth    *auth.Auth
	// GitHub holds the GitHub client. New fills it from the stored App
	// credentials, and the setup flow fills it once the App is created.
	GitHub *GitHubHolder
	// BaseURL is the public dashboard URL.
	BaseURL string
	// Web holds the built dashboard, with index.html at its root.
	Web fs.FS
	// HTTPClient is used for GitHub API calls. Nil means a default client.
	HTTPClient *http.Client
	// MCP serves the MCP server, mounted at /mcp behind bearer tokens. Nil
	// leaves /mcp unmounted.
	MCP http.Handler
	Log *slog.Logger
}

Config configures a Server.

type Control

type Control interface {
	ListProjects(ctx context.Context) ([]control.ProjectSummary, error)
	Project(ctx context.Context, id string) (control.ProjectView, error)
	ProjectRecord(ctx context.Context, id string) (store.Project, error)
	CreateProject(ctx context.Context, name string) (control.ProjectView, error)
	RenameProject(ctx context.Context, id, name string) (control.ProjectView, error)
	DeleteProject(ctx context.Context, id string) error

	CreateService(ctx context.Context, projectID string, req control.NewService) (control.ServiceView, error)
	Service(ctx context.Context, id string) (control.ServiceView, error)
	ServiceRecord(ctx context.Context, id string) (store.Service, error)
	UpdateService(ctx context.Context, id string, patch control.ServicePatch) (control.ServiceView, error)
	DeleteService(ctx context.Context, id string) error
	StopService(ctx context.Context, id string) error
	StartService(ctx context.Context, id string) error
	RestartService(ctx context.Context, id string) error
	ClearRestoreFence(ctx context.Context, id string) error

	Variables(ctx context.Context, serviceID string) (map[string]string, error)
	SetVariables(ctx context.Context, serviceID string, vars map[string]string) (map[string]string, error)
	ResolvedVariables(ctx context.Context, serviceID string) (map[string]string, error)
	OnePasswordVariables(ctx context.Context, serviceID string) (map[string]string, error)
	LinkOnePassword(ctx context.Context, serviceID, environment, token string) (control.ServiceView, error)
	UnlinkOnePassword(ctx context.Context, serviceID string) (control.ServiceView, error)
	CreateDomain(ctx context.Context, serviceID, host string) (store.Domain, bool, error)
	DeleteDomain(ctx context.Context, id string) (bool, error)
	CreateVolume(ctx context.Context, serviceID, mountPath string) (store.Volume, error)
	DeleteVolume(ctx context.Context, id string) error

	Deployments(ctx context.Context, serviceID string, limit int) ([]control.DeploymentView, error)
	Deployment(ctx context.Context, id string) (control.DeploymentView, error)
	Deploy(ctx context.Context, serviceID string) (control.DeploymentView, error)
	Redeploy(ctx context.Context, deploymentID string) (control.DeploymentView, error)
	CancelDeployment(ctx context.Context, deploymentID string) (control.DeploymentView, error)
	FollowBuildLog(ctx context.Context, deploymentID string, line func(string), status func(store.DeploymentStatus)) error
	FollowRuntimeLogs(ctx context.Context, serviceID string, tail int, w io.Writer) error
	FollowShedLog(ctx context.Context, emit func(line string))

	ServicesForPush(ctx context.Context, repo, branch string) ([]store.Service, error)
	ReceivePush(ctx context.Context, push store.PendingPush) error
	DeployPush(ctx context.Context, serviceID string)

	ServiceMetrics(ctx context.Context, serviceID, rng string) (metrics.Series, error)
	HostMetrics(ctx context.Context, rng string) (metrics.HostSeries, error)

	ServiceBackups(ctx context.Context, serviceID string) (control.BackupList, error)
	SystemBackups(ctx context.Context) (control.BackupList, error)
	SetServiceBackupPolicy(ctx context.Context, serviceID string, in backup.PolicyInput) (backup.Policy, error)
	SetSystemBackupPolicy(ctx context.Context, in backup.PolicyInput) (backup.Policy, error)
	BackUpService(ctx context.Context, serviceID string) (control.BackupView, error)
	BackUpSystem(ctx context.Context) (control.BackupView, error)
	OpenBackup(ctx context.Context, id string) (io.ReadCloser, string, error)
	RestoreBackup(ctx context.Context, id string) (store.Restore, error)
	DeleteBackup(ctx context.Context, id string) error
	BackupSettings(ctx context.Context) (backup.Settings, error)
	SetBackupSettings(ctx context.Context, in backup.SettingsInput) (backup.Settings, error)
	TestBackupS3(ctx context.Context, in backup.S3Input) error
	BackupIdentity(ctx context.Context) (string, error)

	UpdateStatus(ctx context.Context) (update.Status, error)
	CheckUpdate(ctx context.Context) (update.Status, error)
	DownloadUpdate(ctx context.Context) (update.Status, error)
	SetAutoDownload(ctx context.Context, on bool) (update.Status, error)
	InstallUpdate(ctx context.Context) (update.Status, error)

	Repos(ctx context.Context) ([]github.Repo, error)
	Branches(ctx context.Context, owner, repo string) ([]string, error)
}

Control carries out the operations behind the API. *control.Plane implements it.

type GitHubHolder

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

GitHubHolder holds the GitHub client, which exists only once the GitHub App is configured. It is safe for concurrent use; the zero value holds nothing.

func (*GitHubHolder) Get

func (h *GitHubHolder) Get() *github.Client

Get returns the client, or nil if GitHub is not configured.

func (*GitHubHolder) Set

func (h *GitHubHolder) Set(c *github.Client)

Set installs the client.

type Server

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

Server is the HTTP interface.

func New

func New(ctx context.Context, cfg Config) (*Server, error)

New returns a Server. It loads the GitHub App from the store, or, if none is configured, generates the one-time setup token and logs it.

func (*Server) Handler

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

Handler returns the root HTTP handler.

type Settings

type Settings interface {
	Setting(ctx context.Context, key string) (string, error)
	SetSetting(ctx context.Context, key, value string) error
}

Settings stores the GitHub App credentials. *store.Store implements it.

Jump to

Keyboard shortcuts

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