fileoverride

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package fileoverride redirects the file downloads a distro definition declares to an internal mirror or to a directory of pre-staged assets, the way images.RegistryOverride redirects image pulls.

It differs from the registry case in one way worth knowing. A registry override matches on a raw string prefix, which is survivable for a registry reference but not for a URL: an override for "https://github.com" would otherwise also capture "https://github.com.example.invalid/...". Matching here is done on the parsed URL, and the prefix has to end on a path-segment boundary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToMap

func ToMap(overrides []Override) map[string]string

ToMap flattens overrides into the source-to-target form the config file and the package build metadata both use. Ordering is not preserved, which is why it is not used for matching.

Types

type Match

type Match struct {
	// Override is the entry that matched.
	Override Override
	// Resolved is the effective source: a rewritten URL, or an absolute local path.
	Resolved string
}

Match is a resolved override: which Override applied, and the source to actually read.

func Resolve

func Resolve(overrides []Override, src string) (Match, bool, error)

Resolve returns the effective source for src under the first override that matches it. ok is false when no override applies, in which case src should be used unchanged.

A non-URL src never matches: a distro definition that already points at a local file has nothing to redirect.

type Override

type Override struct {
	// Source is the URL prefix a file source is matched against, for example
	// "https://rpm.rancher.io" or "https://github.com/rancher".
	Source string
	// Target is the replacement as it was written: either an http/https URL prefix, or a
	// path to a local directory of pre-staged files.
	Target string
	// LocalDir is set, and absolute, when Target names a directory rather than a URL. It is
	// resolved once at parse time so a rewritten source can never be taken for a relative
	// path and re-resolved against the distro definition directory.
	LocalDir string
}

Override redirects every file source under Source to Target.

func Parse

func Parse(overrides []string) ([]Override, error)

Parse converts "source=target" pairs into a structured type. The result is sorted in descending order by Source, which puts the longest prefix first -- so an override for "https://github.com/rancher" wins over a broader "https://github.com" -- matching how cmd.ParseRegistryOverrides orders registry overrides for the same reason.

Input is of the following form: []string{"https://github.com/rancher=https://mirror.example.com/rancher", "https://rpm.rancher.io=/srv/staged"}

func (Override) IsLocal

func (o Override) IsLocal() bool

IsLocal reports whether this override redirects to a local directory rather than a URL.

Jump to

Keyboard shortcuts

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