Documentation
¶
Overview ¶
Package update checks whether a newer Caprock release exists and works out the command that would install it.
This is the ONE place in Caprock that talks to the network, and it is off until the user turns it on. Engineering rule 4 ("no outbound calls") is not bent quietly: the check is opt-in, asked for once, visible in the UI with the time of the last check, and revocable. The request carries no body, no identifiers, and no usage data — GitHub learns an IP asked for a release tag, which is what any `brew update` already tells it.
Caprock deliberately does NOT install the update itself. Upgrading means replacing the running binary, so the daemon would be killing the process executing the command — a race whose failure mode is a user left with no working Caprock. Running a package manager on the user's behalf from a web page is also exactly the surface a local tool should not open. Instead we name the exact command for how this copy was installed, and the user runs it.
Index ¶
Constants ¶
const ReleasesPage = "https://github.com/dspv/caprock/releases/latest"
ReleasesPage is where a user without a package manager goes.
Variables ¶
var LatestURL = "https://api.github.com/repos/dspv/caprock/releases/latest"
LatestURL is the release endpoint. Overridable in tests.
Functions ¶
func InstallCommand ¶
func InstallCommand() string
InstallCommand returns the upgrade command for how this copy was installed, inferred from the executable's path. When we cannot tell, we say nothing rather than suggest a command that might do the wrong thing — an empty result means the UI offers the release page instead.
Types ¶
type Checker ¶
type Checker struct {
// Now is injectable for tests.
Now func() time.Time
// HTTPClient is injectable for tests.
HTTPClient *http.Client
// MinInterval throttles checks (default 24h). GitHub's tag does not change
// often enough to justify asking more, and asking more is more exposure.
MinInterval time.Duration
// contains filtered or unexported fields
}
Checker holds the cached result. It never checks on its own: the caller decides when, so "opt-in" is enforced at the call site as well as here.
type Status ¶
type Status struct {
// Enabled reports whether the user turned checking on.
Enabled bool `json:"enabled"`
// Current is the running version.
Current string `json:"current"`
// Latest is the newest published version, "" if never checked.
Latest string `json:"latest,omitempty"`
// UpdateAvailable is true only when Latest is genuinely newer than Current.
UpdateAvailable bool `json:"update_available"`
// Command is how to install it, given how this copy was installed.
Command string `json:"command,omitempty"`
// URL is the release page, always safe to offer.
URL string `json:"url,omitempty"`
// CheckedAt is the last successful check (unix ms), 0 if never.
CheckedAt int64 `json:"checked_at,omitempty"`
// Error is the last failure, if any. A failed check is never fatal.
Error string `json:"error,omitempty"`
// Notes is the published release's own description of what changed, as
// written on GitHub. It arrives in the same response as the tag — asking
// for the version and then asking again for the notes would be a second
// request for something we already had.
Notes string `json:"notes,omitempty"`
// NotesFor is the version Notes describes. Without it a stale note could
// be shown beside a different version after a failed check.
NotesFor string `json:"notes_for,omitempty"`
}
Status is what the UI renders.