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 ¶
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)
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)
OnePassword(ctx context.Context) (control.OnePasswordStatus, error)
ConnectOnePassword(ctx context.Context, token string) (control.OnePasswordStatus, error)
DisconnectOnePassword(ctx context.Context) 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.