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
- Variables
- func AquaSnapshot() (SnapshotMeta, []AquaEntry, error)
- func CheckURL(raw string) error
- func WebHosts() []string
- type AquaEntry
- type ConfigLayer
- type EOL
- type Entry
- type Finder
- type Found
- type Inputs
- type JSONMap
- type Layer
- type LintError
- type Linter
- type LoadOptions
- type Match
- type MiseLister
- type Name
- type OSVPackage
- type RepoFiles
- type Resolution
- type ResolveOptions
- type Resolver
- type SnapshotMeta
- type Source
- type ToolSpec
- type UpdateResult
- type UpdatedEntry
- type VersionSpec
Constants ¶
const ( UniverseReleases = "releases" UniverseTags = "tags" )
Universe values.
const ( PlaceholderVersion = "{version}" PlaceholderMajor = "{major}" PlaceholderMinor = "{minor}" PlaceholderTag = "{tag}" PlaceholderPrevMinor = "{prev_minor}" PlaceholderPrevMajor = "{prev_major}" )
Template placeholders of paths, URLs, refs and anchors.
const ( KindTFProvider = "tfprovider" KindChart = "chart" KindNPM = "npm" KindPyPI = "pypi" KindGuess = "guess" )
Lookup kinds: the explicit prefixes that need a package registry, and a GitHub search.
const ( RelgapSourceEmbedded = "embedded" RelgapSourceUpdated = "updated" )
Where a relgap registry entry was read from.
const ( MiseSourceLive = "live" MiseSourceSnapshot = "snapshot" )
Where mise's registry was read from.
const ( MiseSnapshotFile = "mise.json" AquaSnapshotFile = "aqua.json" )
Snapshot file names in internal/registry/snapshot.
const ( UpdateRepo = "sassdavid/relgap" UpdateRef = "main" UpdatePath = "registry" )
UpdateRepo and UpdateRef name where `relgap registry update` reads entries from.
const ( UpdateAdded = "added" UpdateChanged = "changed" UpdateUnchanged = "unchanged" UpdateSkipped = "skipped" )
Update statuses of an entry, compared with the embedded one.
const ConfidenceLow = "low"
ConfidenceLow marks a resolution that `--guess` made from a GitHub search.
const MaxSnapshotAge = 30 * day
MaxSnapshotAge is how old a snapshot's commit may be before the registry workflow fails.
Variables ¶
var ( ErrUnknownTool = errors.New("unknown tool") ErrNoRepo = errors.New("no GitHub repository") ErrUnsupported = errors.New("unsupported tool syntax") )
Resolution errors.
var ErrAmbiguous = errors.New("ambiguous name")
ErrAmbiguous is wrapped by lookup errors when a name matches more than one package.
var ErrHostNotAllowed = errors.New("host not allowed")
ErrHostNotAllowed is wrapped by CheckURL errors for hosts outside WebHosts.
var ErrInvalid = errors.New("invalid registry entry")
ErrInvalid is wrapped by every registry entry error.
var ErrSnapshotStale = errors.New("snapshot is stale")
ErrSnapshotStale reports a snapshot whose commit is older than the allowed age.
Functions ¶
func AquaSnapshot ¶
func AquaSnapshot() (SnapshotMeta, []AquaEntry, error)
AquaSnapshot returns the embedded index of the aqua registry.
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
Aliases map[string]string // raw name to tool 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
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
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
Layer Layer // the service that answered
Alternatives []string // other repositories a guess could have picked
}
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" LayerNPM Layer = "npm registry" LayerPyPI Layer = "pypi" 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) ProblemLines ¶
ProblemLines returns one line per problem, with file:line:column.
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.
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 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:, 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 (*Resolver) Identify ¶
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
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, aqua:package, tfprovider:namespace/name, chart:repo/name, chart:name, npm:package or pypi:package.
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
Age returns how long before now the snapshot's commit was made.
func (SnapshotMeta) CheckAge ¶ added in v0.4.0
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
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"`
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
}
ToolSpec is a resolved tool: where it lives, how its versions are read and where its notes are.
func SpecFromEntry ¶
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.
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
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"`
Exclude string `json:"exclude,omitempty" yaml:"exclude"`
Universe string `json:"universe" yaml:"universe"` // releases or tags
Line string `json:"line" yaml:"line"` // none, major or minor
}
VersionSpec says how a tool's tags become versions.
Source Files
¶
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. |