Documentation
¶
Overview ¶
Package admin serves the hub's own admin API under /api/home: plugins and their tools, admin tool calls with progress, jobs, the activity log, the settings, the tunnel, the system info and the event stream (server-sent events, with a long-poll fallback for a quick tunnel, which carries no SSE). People, invites, connections, sessions and passkeys are MCP Gatekeeper's (packages auth and people), and so is the audit of admin actions, which this package writes to (core.AuditEntry in the store's Audit).
A Server lives as long as homed; Routes gives its routes behind the session layer of one gatekeeper stack (the public URL's), so a quick tunnel's new URL rebuilds only that layer. Commands are the admin socket's plugin, tool and update commands (`homed plugin …`, `homed tool …`, `homed update`).
Who may call what: "owner" is a person of role owner (the superadmin and a co-owner alike); "session" is anyone signed in. A member sees their own activity and nothing of the devices here (GET /api/account lists the devices they may use).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("admin: not found")
ErrNotFound is what an Installer returns from Preview when the repo or release does not exist.
Functions ¶
This section is empty.
Types ¶
type HubRelease ¶
HubRelease is the latest hub release.
type Installer ¶
type Installer interface {
Preview(ctx context.Context, repo, version string) (PluginPreview, error)
Install(ctx context.Context, repo, version, id string, report Reporter) (pluginID string, err error)
Update(ctx context.Context, id, version string, allowDowngrade bool, report Reporter) error
Remove(ctx context.Context, id string, keepData bool, report Reporter) error
// LatestVersion returns the latest release version of a plugin repo.
LatestVersion(ctx context.Context, repo string) (string, error)
// LatestHub returns the latest hub release.
LatestHub(ctx context.Context) (HubRelease, error)
// UpdateHub replaces the homed binary; homed exits afterwards and the service manager restarts it.
UpdateHub(ctx context.Context, version string, allowDowngrade bool, report Reporter) error
}
Installer is the plugin installer and self-updater as the admin sees it. Install, Update, Remove and UpdateHub run inside a job: they report steps through the Reporter and do every store and runtime change themselves (store row, atomic switch, start, rollback). Errors other than *JobError and ErrNotFound count as upstream failures where GitHub is involved. Update and UpdateHub refuse a release older than the installed one (job error "downgrade") unless allowDowngrade, which only the admin socket passes.
type JobError ¶
JobError is an installer error with a stable code: checksum_mismatch, no_asset, incompatible, start_failed, rolled_back, downgrade, job_running, upstream, internal. Other errors end a job with code "internal".
type JobReport ¶
type JobReport struct {
Step string // one of the job's steps; empty keeps the current one
Done int64 // bytes or items done; with Total, shown as progress
Total int64
Message string // short English text, e.g. "homie-tv 0.2.0"
}
JobReport is one progress report of a running job.
type Options ¶
type Options struct {
Store *store.Store
Host PluginHost
Runtime PluginRuntime // optional
Installer Installer // optional: install, update and update checks answer 503 home_not_ready without it
Tunnel Tunnel // optional: the tunnel endpoints answer 503 home_not_ready without it
// Activity records the tool calls of the admin and the CLI, and its stored records become "activity" events.
// Optional: nothing is recorded without it.
Activity *audit.Writer
// OwnerReady reports whether the superadmin has a passkey of the current public URL (bootstrap's ownerReady).
// Nil answers false.
OwnerReady func(ctx context.Context) (bool, error)
// TunnelMode is the mode the bootstrap tells the SPA (quick: poll instead of SSE); nil reads Tunnel's status.
TunnelMode func() string
// OnHomeName is called after the home was renamed (the gateway's MCP title and instructions follow it).
OnHomeName func(name string)
// WithProgress returns a context that makes PluginHost.Call report the plugin's progress notifications to fn. Nil
// means plugins.WithProgress, which is what plugins.Host understands; tests replace it.
WithProgress func(ctx context.Context, fn func(plugins.Progress)) context.Context
Version string // hub version, e.g. "0.2.0"; empty means "dev"
Commit string
StartedAt time.Time
// LocalName names the admin socket's caller in the activity log (the OS user name).
LocalName string
Log *slog.Logger
}
Options configures the admin API. Store and Host are required.
type PluginHost ¶
type PluginHost interface {
hub.ToolHost
// Logs returns the last stderr lines of a plugin, oldest first; nil for an unknown id.
Logs(id string) []string
}
PluginHost is the plugin host as the admin sees it: hub.ToolHost plus the plugin logs (plugins.Host has both). A host that also has PluginInstructions(id string) string fills PluginDetail.instructions.
type PluginPreview ¶
type PluginPreview struct {
Repo string `json:"repo"`
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
Version string `json:"version"`
PublishedAt *time.Time `json:"publishedAt,omitempty"`
Homepage string `json:"homepage,omitempty"`
MinHubVersion string `json:"minHubVersion,omitempty"`
Compatible bool `json:"compatible"`
AssetFound bool `json:"assetFound"`
Installed *struct {
Version string `json:"version"`
} `json:"installed,omitempty"` // set by the admin from the store
}
PluginPreview is the GET /plugins/preview answer, built from a release's homie-plugin.json.
type PluginRuntime ¶
type PluginRuntime interface {
// Apply makes the running plugins match store.Plugins: start new and enabled ones, stop disabled and removed ones.
Apply(ctx context.Context) error
// Restart stops and starts one plugin.
Restart(ctx context.Context, id string) error
}
PluginRuntime starts and stops plugins after the admin changed store.Plugins. Nil means the store change takes effect at the next start of homed.
type Reporter ¶
type Reporter func(JobReport)
Reporter receives a job's progress. It is safe to call from any goroutine.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the admin API. Create it with New, serve Routes, and Close it at shutdown.
func New ¶
New returns the admin API. It starts the event watchers; Close stops them and cancels running calls and jobs.
func (*Server) AccessReset ¶
AccessReset records that reset-access ran on the admin socket (review GK-5: on a desktop any program of the user reaches the socket, so the owner is told): the overview shows it for seven days, and an "attention" event says it now. by names the program that asked, when the socket knew it.
func (*Server) Close ¶
func (s *Server) Close()
Close stops the watchers, cancels running calls and jobs, and closes the event streams.
func (*Server) Commands ¶
Commands are the admin socket's commands over the admin API's own functions (`homed <command>` while homed runs; the caller is the home box's operator, via "cli"):
plugin add --id <id> -- <absolute path> [args…] add a plugin from this machine; homed starts it plugin list the plugins and their state plugin remove [--delete-data] <id> stop and remove a plugin (its data stays unless --delete-data) tool list every tool, admin ones included tool call <name> [<json arguments> | -] call a tool; "-" reads the arguments from the standard input update [--version <v>] [--allow-downgrade] replace homed with a release; homed restarts
type Tunnel ¶
type Tunnel interface {
// Status reports the tunnel.
Status() tunnel.Status
// Check runs the self-check through the tunnel now.
Check(ctx context.Context) tunnel.Status
// Restart starts cloudflared again; a quick tunnel gets a new URL.
Restart() error
}
Tunnel is homed's tunnel as the admin sees it (internal/tunnel.Manager).