Documentation
¶
Overview ¶
Package updatecheck asks GitHub which release of Mediarium is the newest, so the app can tell an administrator that an update is out.
It only reads. The request goes to the public GitHub Releases API of the official repository and carries no identifying data: no account, no install id, no settings, only a User-Agent of the form "Mediarium/<version>". Nothing is downloaded or installed by this package; installing is up to the person.
Index ¶
- Constants
- Variables
- func ArchiveName(version, goos, goarch string) string
- func Installable(rel Release, goos, goarch string) (ok bool, reason string)
- func Newer(running string, rel Release) bool
- func ParsePublicKey(b64 string) (ed25519.PublicKey, error)
- func PlainNotes(body string, maxLines int) (notes string, more bool)
- func SumFor(sums []byte, name string) (string, error)
- func ValidRepo(s string) bool
- func VerifySignature(pub ed25519.PublicKey, data []byte, sigBase64 string) error
- type Asset
- type Checker
- type Download
- type Fetcher
- type Release
Constants ¶
const ( SumsName = "sha256sums.txt" SigName = "sha256sums.txt.sig" )
The files a release carries (see .github/workflows/release.yml and docs/RELEASING.md). sha256sums.txt lists the SHA-256 of every archive and is signed with the maintainer's private key; the signature is the only thing Mediarium trusts, so a changed file on GitHub or a changed download cannot pass for a real release.
const ( MaxArchive = 300 << 20 // the archive as downloaded // MaxBinary is the biggest program file we unpack from an archive. MaxBinary = 200 << 20 )
The sizes we are willing to read. The program is about 45 MB.
const DefaultBaseURL = "https://api.github.com"
DefaultBaseURL is the GitHub API.
const DownloadTimeout = 15 * time.Minute
Timeout for a whole release download (a slow line is fine, a hung one is not).
const (
// NotesLines is how many lines of the release notes are kept.
NotesLines = 10
)
Variables ¶
var ( ErrNoSignature = errors.New("the release has no signature file") ErrBadSignature = errors.New("the signature does not match") ErrBadChecksum = errors.New("the downloaded file does not match the signed checksum") ErrNoArchive = errors.New("the release has no program file for this system") ErrHostNotAllowed = errors.New("the download was sent to a host that is not allowed") ErrNoProgram = errors.New("the archive does not contain the program") ErrKeyMissing = errors.New("no signing key is built into this version") )
Problems the caller turns into plain sentences.
var ( ErrRateLimited = errors.New("GitHub is limiting requests right now") )
Errors a check can end in. Callers show the same plain "couldn't check just now" for all of them; the difference is only for the log.
var DefaultRepo = "rdborg/Mediarium"
DefaultRepo is the official repository, as owner/name. A build for another fork can change it with
-ldflags "-X github.com/rdborg/mediarium/internal/updatecheck.DefaultRepo=owner/name"
Functions ¶
func ArchiveName ¶
ArchiveName is the file the release pipeline makes for a system: mediarium_1.2.0_linux_amd64.tar.gz (a .zip on Windows).
func Installable ¶
Installable says whether a release can be installed by the app on this system: it must have the signature file, the list of checksums and the program file for goos/goarch. reason is a plain sentence when it cannot. Only Linux can install itself, because only the container images know how to start an installed update (see docs/INSTALL.md).
func Newer ¶
Newer reports whether rel is a newer version than running. A running version that is not a version number (a "dev" build) is never told to update.
func ParsePublicKey ¶
ParsePublicKey reads the base64 text of a raw 32-byte ed25519 public key.
func PlainNotes ¶
PlainNotes turns release notes (Markdown from GitHub) into a few lines of plain text: at most maxLines lines, headings and emphasis marks removed, links reduced to their words, HTML tags and control characters dropped. The result is text only. The page shows it as text, never as HTML. more says whether there was more than was kept.
Types ¶
type Checker ¶
type Checker struct {
Repo string // owner/name; DefaultRepo when empty
Version string // the running version, for the User-Agent
BaseURL string // DefaultBaseURL when empty (tests point it at a fake server)
Client *http.Client // netguard client with a timeout when nil
// contains filtered or unexported fields
}
Checker fetches the release list. It remembers the last answer and its ETag, so asking again costs nothing against GitHub's rate limit while nothing has changed.
func (*Checker) Latest ¶
Latest returns the newest release that applies to a running version: a stable release when running is a normal release, and the newest of either kind when running is itself a pre-release. It does not say whether that release is newer than the running one (see Newer). ok is false when the repository has no usable release yet.
type Download ¶
type Download struct {
Path string // the unpacked program, in the folder that was given
SHA256 string // hex SHA-256 of that program file
Bytes int64
}
Download is what Fetch returns.
func ExtractProgram ¶
ExtractProgram unpacks the "mediarium" program file from a release .tar.gz into dir and returns where it is. Only a regular file named mediarium, at most one folder deep, is taken; every other entry is ignored, so an archive cannot write anywhere else.
type Fetcher ¶
type Fetcher struct {
Repo string // owner/name
Base string // "https://github.com" unless a test says otherwise
Version string // running version, for the User-Agent
Client *http.Client // built by NewFetcher
// contains filtered or unexported fields
}
Fetcher downloads a release and checks it. Only the official repository's release files are ever fetched, from GitHub's own hosts.
func NewFetcher ¶
NewFetcher returns a Fetcher for the official repository.
func NewFetcherForTest ¶
NewFetcherForTest returns a Fetcher that downloads from base (a local test server, plain HTTP allowed) and accepts redirects only to the given hosts. Real code uses NewFetcher, which is fixed to GitHub.
func (*Fetcher) Fetch ¶
func (f *Fetcher) Fetch(ctx context.Context, rel Release, goos, goarch string, pub ed25519.PublicKey, dir string) (*Download, error)
Fetch downloads the release's checksum list and signature, checks the signature against pub, downloads the archive for goos/goarch, checks its SHA-256 against the signed list, and unpacks the program file into dir. It removes everything it made if it fails. Nothing is installed here.
type Release ¶
type Release struct {
Version string `json:"version"` // 1.2.0, without a leading v
Name string `json:"name,omitempty"` // the title of the release
Notes string `json:"notes,omitempty"` // the first lines of the notes, plain text
MoreNotes bool `json:"moreNotes,omitempty"` // the notes go on past what is shown
URL string `json:"url"` // the release page on GitHub
Prerelease bool `json:"prerelease,omitempty"`
PublishedAt time.Time `json:"publishedAt,omitempty"`
Tag string `json:"tag,omitempty"` // the git tag, used to build download addresses
Assets []Asset `json:"assets,omitempty"` // the files attached to the release
}
Release is the newest release that applies to this install.