registry

package
v0.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package registry resolves a tool name to a ToolSpec by merging the user config, relgap's curated entries, mise's registry and an index of the aqua registry.

Index

Constants

View Source
const (
	UniverseReleases = "releases"
	UniverseTags     = "tags"
	// UniverseChart takes the versions a chart lookup listed, for a chart whose repository has no
	// tag per chart version. They carry no release notes.
	UniverseChart = "chart"
	// UniverseImage takes the tags an image registry listed. Notes come from the GitHub repository
	// the image's source label names, as the tool in [ToolSpec.Notes].
	UniverseImage = "image"
)

Universe values.

View Source
const (
	PlaceholderVersion   = "{version}"
	PlaceholderMajor     = "{major}"
	PlaceholderMinor     = "{minor}"
	PlaceholderTag       = "{tag}"
	PlaceholderPrevMinor = "{prev_minor}"
	PlaceholderPrevMajor = "{prev_major}"
)

Template placeholders of paths, URLs, refs and anchors.

View Source
const (
	KindTFProvider = "tfprovider"
	KindTFModule   = "tfmodule"
	KindChart      = "chart"
	KindNPM        = "npm"
	KindPyPI       = "pypi"
	KindImage      = "image"
	KindGuess      = "guess"
)

Lookup kinds: the explicit prefixes that need a package registry, and a GitHub search.

View Source
const (
	KindBitbucket = "bitbucket"
	KindGitLab    = "gitlab"
)

Explicit prefixes of repositories on other git hosts, resolved without a lookup.

View Source
const (
	RelgapSourceEmbedded = "embedded"
	RelgapSourceUpdated  = "updated"
)

Where a relgap registry entry was read from.

View Source
const (
	MiseSourceLive     = "live"
	MiseSourceSnapshot = "snapshot"
)

Where mise's registry was read from.

View Source
const (
	MiseSnapshotFile = "mise.json"
	AquaSnapshotFile = "aqua.json"
)

Snapshot file names in internal/registry/snapshot.

View Source
const (
	UpdateRepo = "sassdavid/relgap"
	UpdateRef  = "main"
	UpdatePath = "registry"
)

UpdateRepo and UpdateRef name where `relgap registry update` reads entries from.

View Source
const (
	UpdateAdded     = "added"
	UpdateChanged   = "changed"
	UpdateUnchanged = "unchanged"
	UpdateSkipped   = "skipped"
)

Update statuses of an entry, compared with the embedded one.

View Source
const ConfidenceLow = "low"

ConfidenceLow marks a resolution that `--guess` made from a GitHub search.

View Source
const KindAction = "action"

KindAction is the prefix of a GitHub Action, action:owner/repo[/path], resolved to its repository on github.com without a lookup.

View Source
const MaxSnapshotAge = 30 * day

MaxSnapshotAge is how old a snapshot's commit may be before the registry workflow fails.

Variables

View Source
var (
	ErrUnknownTool = errors.New("unknown tool")
	ErrNoRepo      = errors.New("no GitHub repository")
	ErrUnsupported = errors.New("unsupported tool syntax")
)

Resolution errors.

View Source
var ErrAmbiguous = errors.New("ambiguous name")

ErrAmbiguous is wrapped by lookup errors when a name matches more than one package.

View Source
var ErrHostNotAllowed = errors.New("host not allowed")

ErrHostNotAllowed is wrapped by CheckURL errors for hosts outside WebHosts.

View Source
var ErrInvalid = errors.New("invalid registry entry")

ErrInvalid is wrapped by every registry entry error.

View Source
var ErrSnapshotStale = errors.New("snapshot is stale")

ErrSnapshotStale reports a snapshot whose commit is older than the allowed age.

Functions

func ActionRepo added in v0.13.0

func ActionRepo(action string) (string, bool)

ActionRepo returns the repository of the action owner/repo[/path]: its first two parts. The second result is false when they don't form owner/repo.

func AquaSnapshot

func AquaSnapshot() (SnapshotMeta, []AquaEntry, error)

AquaSnapshot returns the embedded index of the aqua registry.

func ChartAt added in v0.11.0

func ChartAt(registryURL, chart string) string

ChartAt returns the name of the chart called chart in the Helm repository at registryURL: chart:<registryURL>/<chart>.

func ChartShortName added in v0.12.0

func ChartShortName(name string) string

ChartShortName returns the short form of a chart:<registryURL>/<chart> name for tables: chart:<host>/<path>/<chart> for an oci:// URL and chart:<owner>/<repo>/<chart> for a GitHub Pages site. SplitChartAt reads both. Any other name comes back unchanged.

func ChartURLName added in v0.12.0

func ChartURLName(name string) string

ChartURLName returns the chart:<registryURL>/<chart> form of a short chart name, the tool's identity. Any other name comes back unchanged.

func CheckURL

func CheckURL(raw string) error

CheckURL returns an error unless raw is an https URL on one of WebHosts.

func CompareTools added in v0.12.1

func CompareTools(a, b string) int

CompareTools orders tool names by the name a table shows, ChartShortName, then by identity.

func ImageName added in v0.11.0

func ImageName(image, prefix, suffix string) string

ImageName returns the tool name of image with the tag pattern prefix*suffix: image:<image>, or image:<image>:<prefix>*<suffix> when either is set.

func Placeholders added in v0.7.0

func Placeholders() []string

Placeholders returns every template placeholder. PlaceholderPrevMinor and PlaceholderPrevMajor work only in upgrade-guide sources.

func SplitChartAt added in v0.11.0

func SplitChartAt(rest string) (string, string, bool)

SplitChartAt splits the part of a chart:<registryURL>/<chart> name after the prefix into the repository URL and the chart, and reports whether rest is such a name. It also reads the short forms that ChartShortName writes: <host>/<path>/<chart> for an OCI registry, whose first part has a dot or a port, and <owner>/<repo>/<chart> for a GitHub Pages site.

func SplitImage added in v0.11.0

func SplitImage(rest string) (string, string, string, bool)

SplitImage splits the part of an image:<image>[:<prefix>*<suffix>] name after the prefix into the image, the tag prefix and the tag suffix, and reports whether rest is such a name. A pattern has exactly one * and no slash, so a registry port such as localhost:5000/app stays part of the image.

func SplitTagPrefix added in v0.11.0

func SplitTagPrefix(rest string) (string, string, bool)

SplitTagPrefix splits github:owner/repo@prefix, without github:, into the repository and the tag prefix, and reports whether rest has a prefix.

func WebHosts

func WebHosts() []string

WebHosts returns the hosts that web-doc, structured-json and upgrade-guide URLs may point to. Every other page comes from GitHub through the API.

Types

type AquaEntry

type AquaEntry struct {
	Name          string   `json:"name"`           // package name, such as hashicorp/terraform
	Repo          string   `json:"repo,omitempty"` // empty for packages not hosted on GitHub
	Aliases       []string `json:"aliases,omitempty"`
	VersionPrefix string   `json:"version_prefix,omitempty"`
	VersionFilter string   `json:"version_filter,omitempty"` // an expr-lang expression
	VersionSource string   `json:"version_source,omitempty"` // github_tag or github_release
}

AquaEntry is one package of the aqua registry, reduced to what resolution needs.

type ConfigLayer

type ConfigLayer struct {
	Tools       map[string]string // tool name to owner/repo, or the project path on its host
	Hosts       map[string]string // tool name to its host when it isn't github.com
	Aliases     map[string]string // raw name to tool name
	GitLabHosts []string          // self-managed GitLab hosts that gitlab:<host>/<path> may name
}

ConfigLayer is the part of the user config that takes part in resolution.

type EOL

type EOL struct {
	Product string `json:"product"         yaml:"product"`
	Cycle   string `json:"cycle,omitempty" yaml:"cycle"` // template such as {major}.{minor}
}

EOL names the endoflife.date product of a tool.

type Entry

type Entry struct {
	Name            string       `yaml:"name"`
	Aliases         []string     `yaml:"aliases"`
	Repo            string       `yaml:"repo"`
	MinRelgap       string       `yaml:"min_relgap"`
	Version         VersionSpec  `yaml:"version"`
	Sources         []Source     `yaml:"sources"`
	EOL             *EOL         `yaml:"eol"`
	OSV             []OSVPackage `yaml:"osv"`
	BreakingMarkers []string     `yaml:"breaking_markers"`
	Bin             []string     `yaml:"bin"`
}

Entry is one registry/<name>.yaml file, as defined by schemas/registry-v1.json.

func LoadUpdated added in v0.4.0

func LoadUpdated(ctx context.Context, logger *slog.Logger, l *Linter, dir, v string) []*Entry

LoadUpdated lints the entries in dir. An entry with problems, or one that needs a newer relgap than v, is logged and left out, so the embedded entry of that name stays in use.

type Finder added in v0.4.0

type Finder interface {
	Find(ctx context.Context, kind, name string) (*Found, error)
}

Finder looks a tool up in a package registry, or guesses its repository with kind KindGuess.

type Found added in v0.4.0

type Found struct {
	Repo         string   // owner/repo on GitHub
	Name         string   // tool name to use when no registry knows the repo; empty means the repo name
	TagPrefix    string   // set for a chart in a repository with several charts, and for a Terraform module
	Layer        Layer    // the service that answered
	Alternatives []string // other repositories a guess could have picked
	// Versions are a chart's versions when its repository has no tag per chart version; the tool
	// then gets [UniverseChart].
	Versions    []version.Ref
	VersionsURL string // where Versions come from
	TagSuffix   string // an image variant, such as -alpine
	Image       string // registry/repository of an image
}

Found is what a lookup learned about a tool.

type Inputs

type Inputs struct {
	Config     ConfigLayer
	Entries    []*Entry
	Updated    []*Entry // from `relgap registry update`; each replaces the entry of the same name
	Mise       []misex.RegistryEntry
	MiseSource string
	Aqua       []AquaEntry
}

Inputs are the layers a Resolver merges.

type JSONMap

type JSONMap struct {
	Items   string `json:"items,omitempty"   yaml:"items"`   // dotted path to the array; empty means the document
	Heading string `json:"heading,omitempty" yaml:"heading"` // field whose value groups entries under a heading
	Text    string `json:"text"              yaml:"text"`    // template with {field} placeholders
	Link    string `json:"link,omitempty"    yaml:"link"`    // field holding a URL for the entry
}

JSONMap says how a structured-json document becomes Markdown entries.

type Layer

type Layer string

Layer names where a field of a ToolSpec came from, highest precedence first.

const (
	LayerExplicit Layer = "explicit"
	LayerConfig   Layer = "config"
	LayerRelgap   Layer = "relgap registry"
	LayerMise     Layer = "mise registry"
	LayerAqua     Layer = "aqua registry"
	LayerDefault  Layer = "default"

	LayerTerraform   Layer = "terraform registry"
	LayerArtifactHub Layer = "artifact hub"
	LayerHelmRepo    Layer = "helm repository"
	LayerNPM         Layer = "npm registry"
	LayerPyPI        Layer = "pypi"
	LayerImage       Layer = "image registry"
	LayerGuess       Layer = "github search"
)

Resolution layers.

type LintError

type LintError struct {
	Problems []yamlschema.Problem
}

LintError lists every problem found in one or more entries. It unwraps to ErrInvalid.

func (*LintError) Error

func (e *LintError) Error() string

func (*LintError) Header

func (*LintError) Header() string

Header introduces the problem list in error output.

func (*LintError) ProblemLines

func (e *LintError) ProblemLines() []string

ProblemLines returns one line per problem, with file:line:column.

func (*LintError) Unwrap

func (*LintError) Unwrap() error

type Linter

type Linter struct {
	// contains filtered or unexported fields
}

Linter validates registry entries against schemas/registry-v1.json and checks what the schema can't: regular expressions, scheme and extract, and the file name.

func NewLinter

func NewLinter() (*Linter, error)

NewLinter compiles the registry schema.

func (*Linter) Lint

func (l *Linter) Lint(origin string, b []byte) (*Entry, []yamlschema.Problem, error)

Lint parses one entry. origin is the file path used in problems and to check the name. It returns the entry, or the problems found.

func (*Linter) LoadFS

func (l *Linter) LoadFS(fsys fs.FS, dir string) ([]*Entry, error)

LoadFS lints and loads every *.yaml entry in fsys. Problems from all files are returned together as a LintError.

type LoadOptions added in v0.4.0

type LoadOptions struct {
	UpdatedDir string // directory of updated entries; empty or missing means none
	Version    string // relgap's version, checked against an entry's min_relgap
}

LoadOptions add the entries of `relgap registry update` to LoadWith.

type Match

type Match struct {
	By    string `json:"by"` // name, alias, config alias, env var name, repo or aqua package
	Value string `json:"value"`
	Layer Layer  `json:"layer"`
}

Match says how the input was identified.

type MiseLister

type MiseLister interface {
	Registry(ctx context.Context) ([]misex.RegistryEntry, error)
}

MiseLister lists mise's registry; misex.Client implements it.

type Name added in v0.2.0

type Name struct {
	Name  string
	Layer Layer
	Repo  string // owner/repo when the layer names one
}

Name is a tool name the resolver knows, with the layer that defines it.

type OSVPackage

type OSVPackage struct {
	Ecosystem string `json:"ecosystem" yaml:"ecosystem"`
	Name      string `json:"name"      yaml:"name"`
}

OSVPackage is a package name in an OSV ecosystem.

type RepoFiles added in v0.4.0

type RepoFiles interface {
	Dir(ctx context.Context, repo, ref, dir string) ([]string, error)
	File(ctx context.Context, repo, ref, path string) ([]byte, error)
}

RepoFiles reads the registry directory of relgap's repository.

type Resolution

type Resolution struct {
	Input        string             `json:"input"`
	Match        Match              `json:"match"`
	Tool         ToolSpec           `json:"tool"`
	Provenance   map[string][]Layer `json:"provenance"` // field path to layers
	MiseSource   string             `json:"mise_source"`
	RelgapSource string             `json:"relgap_source,omitempty"` // set when a relgap entry took part
	Confidence   string             `json:"confidence,omitempty"`    // low for a guess
	Alternatives []string           `json:"alternatives,omitempty"`  // other repositories a guess matched
}

Resolution is a resolved tool with the layer that supplied each field.

type ResolveOptions added in v0.4.0

type ResolveOptions struct {
	Finder Finder // nil resolves offline: tfprovider:, tfmodule:, chart:, npm: and pypi: then resolve only from registries
	Guess  bool   // search GitHub for an unknown name; needs Finder
}

ResolveOptions say what Resolver.Resolve may do beyond the embedded registries.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver maps tool names to [ToolSpec]s.

func Load

func Load(ctx context.Context, logger *slog.Logger, mise MiseLister, cfg ConfigLayer) (*Resolver, error)

Load builds a resolver from the embedded entries and snapshots. With a non-nil mise, the live `mise registry --json` replaces the mise snapshot when it works.

func LoadWith added in v0.4.0

func LoadWith(
	ctx context.Context,
	logger *slog.Logger,
	mise MiseLister,
	cfg ConfigLayer,
	o LoadOptions,
) (*Resolver, error)

LoadWith is Load with the updated entries in o.UpdatedDir on top of the embedded ones.

func NewResolver

func NewResolver(in Inputs) *Resolver

NewResolver indexes the layers in in.

func (*Resolver) Alias added in v0.12.0

func (r *Resolver) Alias(input string) (string, bool)

Alias returns the tool that the config alias input points to, and false when input isn't a config alias or its tool is unknown.

func (*Resolver) Identify

func (r *Resolver) Identify(input string) (string, bool)

Identify returns the name `relgap digest` accepts for input without merging layers: the registry name when a registry knows the tool, otherwise the github: or aqua: form itself.

func (*Resolver) Names added in v0.2.0

func (r *Resolver) Names() []Name

Names lists the tool names of the relgap registry, the config and mise's registry, without aliases. A name in several layers is listed once, from the first.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, input string, opts ResolveOptions) (*Resolution, error)

Resolve identifies input and merges every layer that knows the tool. input is a name, an alias, a NAME_VERSION variable, github:owner/repo, bitbucket:workspace/repo, gitlab:path, aqua:package, tfprovider:namespace/name, tfmodule:namespace/name/provider, chart:repo/name, chart:name, chart:url/name, npm:package, pypi:package, image:name or action:owner/repo[/path].

type SnapshotMeta

type SnapshotMeta struct {
	Source     string `json:"source"`
	Commit     string `json:"commit"`
	CommitDate string `json:"commit_date"` // RFC 3339
}

SnapshotMeta records where a snapshot came from.

func MiseSnapshot

func MiseSnapshot() (SnapshotMeta, []misex.RegistryEntry, error)

MiseSnapshot returns the embedded copy of mise's registry.

func (SnapshotMeta) Age added in v0.4.0

func (m SnapshotMeta) Age(now time.Time) (time.Duration, error)

Age returns how long before now the snapshot's commit was made.

func (SnapshotMeta) CheckAge added in v0.4.0

func (m SnapshotMeta) CheckAge(now time.Time, maxAge time.Duration) error

CheckAge returns ErrSnapshotStale when the snapshot's commit is older than maxAge at now.

type Source

type Source struct {
	Kind           string   `json:"kind"                      yaml:"kind"`
	PathTemplate   string   `json:"path_template,omitempty"   yaml:"path_template"`
	URLTemplate    string   `json:"url_template,omitempty"    yaml:"url_template"`
	Ref            string   `json:"ref,omitempty"             yaml:"ref"`
	Heading        string   `json:"heading,omitempty"         yaml:"heading"`
	IgnoreSections []string `json:"ignore_sections,omitempty" yaml:"ignore_sections"`
	FromHeading    string   `json:"from_heading,omitempty"    yaml:"from_heading"`
	Content        string   `json:"content,omitempty"         yaml:"content"`     // web-doc: selector of the element to convert
	Strip          []string `json:"strip,omitempty"           yaml:"strip"`       // web-doc: selectors of elements to drop
	Anchor         string   `json:"anchor,omitempty"          yaml:"anchor"`      // web-doc: id template of a version's element
	SiteURL        string   `json:"site_url,omitempty"        yaml:"site_url"`    // changelog-file: base URL of the Hugo site
	ContentDir     string   `json:"content_dir,omitempty"     yaml:"content_dir"` // changelog-file: Hugo content directory
	JSON           *JSONMap `json:"json,omitempty"            yaml:"json"`
}

Source is one changelog source of a tool.

type ToolSpec

type ToolSpec struct {
	Name            string        `json:"name"`
	Aliases         []string      `json:"aliases"`
	Repo            string        `json:"repo"`            // owner/repo, or the project path on Host
	Host            string        `json:"host,omitempty"`  // bitbucket.org, gitlab.com or a GitLab host; empty means github.com
	Image           string        `json:"image,omitempty"` // registry/repository of a [UniverseImage] tool
	Notes           *ToolSpec     `json:"notes,omitempty"` // the tool whose notes an image's digest reads
	Version         VersionSpec   `json:"version"`
	Sources         []Source      `json:"sources"` // empty means auto-discovery
	EOL             *EOL          `json:"eol,omitempty"`
	OSV             []OSVPackage  `json:"osv"`
	BreakingMarkers []string      `json:"breaking_markers"`
	Bin             []string      `json:"bin"` // executable names; empty means the tool name
	Backend         string        `json:"-"`   // the input's npm: or pypi: name, else the first backend of its mise entry
	Versions        []version.Ref `json:"-"`   // the versions of a [UniverseChart] or [UniverseImage] tool
	UserRepo        bool          `json:"-"`   // Repo comes from the input, the config or a GitHub search, not a registry
}

ToolSpec is a resolved tool: where it lives, how its versions are read and where its notes are.

func SpecFromEntry

func SpecFromEntry(e *Entry) ToolSpec

SpecFromEntry returns the tool spec of one entry on its own, with defaults for the fields it leaves out, as `relgap registry test` runs a file that isn't embedded yet.

func (ToolSpec) Listed added in v0.11.0

func (t ToolSpec) Listed() bool

Listed reports whether the tool's versions come from a lookup instead of its repository.

type UpdateResult added in v0.4.0

type UpdateResult struct {
	Repo    string         `json:"repo"`
	Ref     string         `json:"ref"`
	Dir     string         `json:"dir"`
	Entries []UpdatedEntry `json:"entries"`
}

UpdateResult is what `relgap registry update` did.

func Update added in v0.4.0

func Update(ctx context.Context, files RepoFiles, dir, v string) (*UpdateResult, error)

Update downloads the entries of relgap's repository and writes the ones that differ from the embedded entries and pass the checks of LoadUpdated to dir, replacing what dir had.

type UpdatedEntry added in v0.4.0

type UpdatedEntry struct {
	Name   string `json:"name"`
	Status string `json:"status"`
	Reason string `json:"reason,omitempty"` // why it was skipped
}

UpdatedEntry is one file `relgap registry update` downloaded.

type VersionSpec

type VersionSpec struct {
	Scheme    string `json:"scheme"               yaml:"scheme"`
	Extract   string `json:"extract,omitempty"    yaml:"extract"`
	TagPrefix string `json:"tag_prefix,omitempty" yaml:"tag_prefix"`
	TagSuffix string `json:"tag_suffix,omitempty" yaml:"-"` // an image variant such as -alpine
	Exclude   string `json:"exclude,omitempty"    yaml:"exclude"`
	Universe  string `json:"universe"             yaml:"universe"` // releases or tags; chart and image only from a lookup
	Line      string `json:"line"                 yaml:"line"`     // none, major or minor
	// VersionsURL is where a chart universe's versions come from: an Artifact Hub package page
	// or a Helm repository index.
	VersionsURL string `json:"versions_url,omitempty" yaml:"-"`
}

VersionSpec says how a tool's tags become versions.

func (VersionSpec) Rules

func (v VersionSpec) Rules() (version.Rules, error)

Rules builds the version rules for this spec.

Directories

Path Synopsis
Package remote looks tools up in the Terraform registry, Artifact Hub, npm, PyPI and the GitHub search API, for the resolver in package registry.
Package remote looks tools up in the Terraform registry, Artifact Hub, npm, PyPI and the GitHub search API, for the resolver in package registry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL