Documentation
¶
Overview ¶
Package update downloads and replaces the Mihari binary (self-update).
Index ¶
- Constants
- func LoadChannel(path string) (string, error)
- func RecheckReplacement(p ReplacementPreview, c ReplacementCandidate, s ReplacementSnapshot) error
- func ReplacementConfirmationError(p ReplacementPreview) error
- func ReplacementWarning(p ReplacementPreview) string
- func SaveChannel(path, channel string) error
- func ValidateReplacementConsent(p ReplacementPreview, c ReplacementConsent) error
- type Asset
- type CheckResult
- type ExecVersionRunner
- type OfficialReleaseSource
- type PreparedUpdate
- type Release
- type ReplacementCandidate
- type ReplacementConsent
- type ReplacementObserver
- type ReplacementPreview
- type ReplacementRisk
- type ReplacementSnapshot
- type ReplacementTarget
- type Result
- type SelfUpdater
- func (u SelfUpdater) ApplyPrepared(ctx context.Context, p PreparedUpdate) (result Result, err error)
- func (u SelfUpdater) Check(ctx context.Context, currentVersion, channel string) (CheckResult, error)
- func (u SelfUpdater) Prepare(ctx context.Context, binaryPath, currentVersion, channel string) (PreparedUpdate, error)
- func (u SelfUpdater) Update(ctx context.Context, binaryPath, currentVersion, channel string) (result Result, err error)
- type VersionRunner
Constants ¶
const ( // ChannelMain tracks official GitHub latest releases. ChannelMain = "main" // ChannelDev tracks canonical prerelease tags vX.Y.Z-dev.N. ChannelDev = "dev" )
Variables ¶
This section is empty.
Functions ¶
func LoadChannel ¶ added in v0.9.0
LoadChannel reads the Mihari release channel from path. A missing file defaults to ChannelMain. An invalid first line is an error.
func RecheckReplacement ¶ added in v0.9.3
func RecheckReplacement(p ReplacementPreview, c ReplacementCandidate, s ReplacementSnapshot) error
RecheckReplacement rejects a changed candidate or installation.
func ReplacementConfirmationError ¶ added in v0.9.3
func ReplacementConfirmationError(p ReplacementPreview) error
ReplacementConfirmationError returns the existing usage error with safe risk details.
func ReplacementWarning ¶ added in v0.9.3
func ReplacementWarning(p ReplacementPreview) string
ReplacementWarning renders safe compatibility information, without file paths.
func SaveChannel ¶ added in v0.9.0
SaveChannel atomically writes channel to path. Only main and dev are accepted.
func ValidateReplacementConsent ¶ added in v0.9.3
func ValidateReplacementConsent(p ReplacementPreview, c ReplacementConsent) error
ValidateReplacementConsent enforces the public confirmation contract.
Types ¶
type Asset ¶
type Asset struct {
Name string `json:"name"`
URL string `json:"browser_download_url"`
Size int64 `json:"size"`
}
Asset is a GitHub release asset.
type CheckResult ¶ added in v0.4.0
CheckResult describes the latest Mihari release relative to the running version.
type ExecVersionRunner ¶ added in v0.9.3
type ExecVersionRunner struct{}
ExecVersionRunner queries an already trusted executable without a shell.
func (ExecVersionRunner) RunVersion ¶ added in v0.9.3
RunVersion runs self version in an isolated temporary environment.
type OfficialReleaseSource ¶ added in v0.9.3
type OfficialReleaseSource struct {
Client *http.Client
// Reporter borrows an existing diagnostic outlet; nil skips close warnings.
Reporter diagnostics.Reporter
}
OfficialReleaseSource obtains independent fixed-tag evidence from the project release origin. Client permits an injected transport; URLs are never inputs.
func (OfficialReleaseSource) Checksum ¶ added in v0.9.3
Checksum returns the unique digest in the official fixed-tag manifest.
func (OfficialReleaseSource) Download ¶ added in v0.9.3
func (s OfficialReleaseSource) Download(ctx context.Context, tag, asset string, limit int64) (result []byte, resultErr error)
Download retrieves a bounded asset from the immutable release URL. Callers must verify its independent checksum before trusting executable/resource bytes.
type PreparedUpdate ¶ added in v0.9.3
type PreparedUpdate struct {
Version, CandidatePath, SHA256, Channel string
Available, Ahead bool
TargetPath string
Preview ReplacementPreview
Consent ReplacementConsent
// contains filtered or unexported fields
}
PreparedUpdate owns a verified download until Apply or Close consumes it. Fields describe a candidate, not authority for privileged installation.
func (*PreparedUpdate) Close ¶ added in v0.9.3
func (p *PreparedUpdate) Close() error
Close releases the prepared candidate. It is safe to call repeatedly.
type Release ¶
type Release struct {
TagName string `json:"tag_name"`
Draft bool `json:"draft"`
Assets []Asset `json:"assets"`
}
Release is a GitHub release document.
type ReplacementCandidate ¶ added in v0.9.3
type ReplacementCandidate struct{ Version, SHA256, Channel string }
ReplacementCandidate identifies verified candidate bytes independently of staging paths.
type ReplacementConsent ¶ added in v0.9.3
type ReplacementConsent struct {
Yes bool
ExpectedPreview string
// Warn reports safe compatibility text for this call; it is never fingerprinted.
Warn func(string) error `json:"-"`
}
ReplacementConsent is scoped to one replacement attempt.
type ReplacementObserver ¶ added in v0.9.3
type ReplacementObserver func(context.Context, string) (ReplacementSnapshot, error)
ReplacementObserver discovers only files the current operation will replace.
type ReplacementPreview ¶ added in v0.9.3
type ReplacementPreview struct {
Candidate ReplacementCandidate
Snapshot ReplacementSnapshot
Risk ReplacementRisk
ID string
}
ReplacementPreview owns a normalized snapshot and its opaque confirmation identifier.
func NewReplacementPreview ¶ added in v0.9.3
func NewReplacementPreview(c ReplacementCandidate, s ReplacementSnapshot) (ReplacementPreview, error)
NewReplacementPreview copies and normalizes observations before hashing them.
type ReplacementRisk ¶ added in v0.9.3
type ReplacementRisk string
ReplacementRisk describes compatibility risk when replacing installed bytes.
const ( // ReplacementNone means no known compatibility risk. ReplacementNone ReplacementRisk = "none" // ReplacementDowngrade means at least one installed version is newer. ReplacementDowngrade ReplacementRisk = "downgrade" // ReplacementUnknown means compatibility cannot be determined. ReplacementUnknown ReplacementRisk = "unknown" )
func ClassifyReplacementVersion ¶ added in v0.9.3
func ClassifyReplacementVersion(current, target string) ReplacementRisk
ClassifyReplacementVersion compares installed and candidate versions.
type ReplacementSnapshot ¶ added in v0.9.3
type ReplacementSnapshot struct {
Targets []ReplacementTarget
ServiceDefinitionSHA256 string
}
ReplacementSnapshot binds actual targets and the persistent service definition.
type ReplacementTarget ¶ added in v0.9.3
type ReplacementTarget struct {
Roles []string
Path, FileID, SHA256 string
Exists bool
Version string
// UnrecognizedVersion is bounded display evidence for the TUI only.
// It never participates in version comparison, JSON or the preview ID.
UnrecognizedVersion string `json:"-"`
// contains filtered or unexported fields
}
ReplacementTarget describes one actual file to be overwritten. Never render it directly.
func ObserveReplacementTarget ¶ added in v0.9.3
func ObserveReplacementTarget(ctx context.Context, role, path string, runner VersionRunner) (ReplacementTarget, error)
ObserveReplacementTarget binds a trusted version query to file observations.
type SelfUpdater ¶
type SelfUpdater struct {
// Reporter borrows the current execution owner's diagnostic outlet.
Reporter diagnostics.Reporter
HTTPClient *http.Client
APIBase string
Repository string
GOOS string
GOARCH string
// AfterReplace is optional; used to restart the OS service after a successful replace.
AfterReplace func(ctx context.Context, version string) error
// ObserveTargets discovers every installation copy replaced by this operation.
ObserveTargets ReplacementObserver
// AfterReplacePrepared takes precedence over AfterReplace when configured.
AfterReplacePrepared func(context.Context, PreparedUpdate) error
// contains filtered or unexported fields
}
SelfUpdater installs a newer Mihari binary from GitHub Releases.
func (SelfUpdater) ApplyPrepared ¶ added in v0.9.3
func (u SelfUpdater) ApplyPrepared(ctx context.Context, p PreparedUpdate) (result Result, err error)
ApplyPrepared validates and installs the fixed candidate without querying releases.
func (SelfUpdater) Check ¶ added in v0.4.0
func (u SelfUpdater) Check(ctx context.Context, currentVersion, channel string) (CheckResult, error)
Check reports whether GitHub Releases contains a newer Mihari version for channel.
func (SelfUpdater) Prepare ¶ added in v0.9.3
func (u SelfUpdater) Prepare(ctx context.Context, binaryPath, currentVersion, channel string) (PreparedUpdate, error)
Prepare downloads and verifies a fixed release without replacing binaryPath.