ref

package
v1.15.29 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ref provides functionality for interpreting and manipulating OCI references, including delineated data for scheme, registry, repository, name, tag, and digest that identifies an OCI object (or bottle). Additionally, facilities for indexing a repository to retrieve a list of tags is included.

Index

Constants

View Source
const (
	// SchemeHTTP is the standard non-tls http url reference.
	SchemeHTTP = "http"
	// SchemeHTTPS is the standard tls http url reference.
	SchemeHTTPS = "https"
	// SchemeBottle defines a scheme for querying bottle location from a telemetry server.
	SchemeBottle = "bottle"
	// SchemeHash defines a scheme for querying bottle location from a telemetry server using hash uri format.
	SchemeHash = "hash"
)
View Source
const (
	// AnnotationSrcRef is an annotation key for a record containing the original source reference for a manifest.
	// This is what the user requested verbatim.
	AnnotationSrcRef = "vnd.act3-ace.manifest.source" // There is no OCI Spec annotation for this

	// AnnotationRefName is an annotation key for denoting the fully qualified name of an image.
	AnnotationRefName = ocispec.AnnotationRefName
)

Variables

View Source
var ErrRefListEmpty = errors.New("repository not found")

ErrRefListEmpty is an error returned when querying a list of registries, repositories, or refs that indicates that the resulting list was empty (Versus another kind of error).

Functions

func ExtractScheme

func ExtractScheme(procstr string) (string, string)

ExtractScheme looks for a transfer scheme prefix in the provided string, and returns the appropriate scheme string if found. Additionally, the portion of the string not including any scheme value is returned.

func ResolveRegistry

func ResolveRegistry(inReg string) string

ResolveRegistry resolves a registry hostname to a fully specified one, for instance docker.io to index.docker.io. this utilizes a configured map of registry hostnames accessed through ace-dt config. If no matching hostnames are discovered the input string is returned.

Types

type DeclRef

type DeclRef struct {
	Ref
	// contains filtered or unexported fields
}

DeclRef is an extension of Ref that adds tracking for a declaration string.

func (DeclRef) GetDecl

func (dr DeclRef) GetDecl() string

GetDecl implements SourceRef interface, and returns the stored declaration string.

func (DeclRef) GetRef

func (dr DeclRef) GetRef() Ref

GetRef implements SourceRef interface, and returns the internal Ref object.

type ListProvider

type ListProvider interface {
	RepositoryListProvider

	// RefList accepts a Ref defining a registry and a list of Repositories, and return a list of Ref that contains
	// full references for all matching repositories on the registry, including all known tags. If repoList is empty
	// a list of all known repositories is first obtained using the RepositoryListProvider.
	RefList(ctx context.Context, registry Ref, repoList []string) ([]Ref, error)
}

ListProvider defines an interface for retrieving a full list of references based on a provided registry and list of repositories. An empty repository list should be interpreted as "all" repositories. The registry info is provided as a Ref in order to also include the communication scheme if necessary.

type MatchType

type MatchType uint8

MatchType is a bitfield type that provides flags for what parts of a Ref object to match during a Match call.

const (
	// RefMatchRepo indicates that a match should consider the repo portion of the reference.
	RefMatchRepo MatchType = 1 << iota
	// RefMatchReg indicates that a match should consider the registry portion of the reference.
	RefMatchReg
	// RefMatchTag Indicates that a match should consider the tag portion of the reference.
	RefMatchTag
	// RefMatchDigest indicates that a match should consider the digest portion of the reference.
	RefMatchDigest
	// RefMatchScheme indicates that a match should consider the scheme portion of the reference.
	RefMatchScheme
	// RefMatchRegRepo combines RefMatchRepo and RefMatchReg options.
	RefMatchRegRepo = RefMatchReg | RefMatchRepo
	// RefMatchAll combines RefMatchReg and RefMatchRepo and RefMatchTag options.
	RefMatchAll = RefMatchReg | RefMatchRepo | RefMatchTag
)

type Ref

type Ref struct {
	Scheme    string
	Reg       string
	Repo      string
	Name      string
	Tag       string
	Digest    string
	Query     string
	Selectors []string
}

Ref is a bottle location reference, including scheme, registry, repository Name, and tag. The Query and Fragment members allows additional uri query terms to be parsed and stored.

func DefaultRefValidator

func DefaultRefValidator(r Ref) (Ref, error)

DefaultRefValidator is the default validation function for parsed references, validating character sets appropriate for use with OCI spec references. Characters outside of the spec cause an error and empty Ref to be returned.

func FromString

func FromString(inref string, validator ...Validator) (Ref, error)

FromString parses a string representing a data bottle and returns a Ref object that identifies registry, repository, name, and tag. By default, each element is validated using a regular expression using DefaultRefValidator, but this behavior can be optionally overridden by supplying a RefValidator function. Note, the validator argument is specified as a variadic list to allow the default argument, only the first element of the list will be called.

func RepoFromString

func RepoFromString(inref string) (outRef Ref)

RepoFromString parses a string representing a data bottle and returns a Ref object that identifies registry and repository. This is similar to RefFromString, but is more tolerant of missing components, and doesn't treat name different from repository.

func SkipRefValidation

func SkipRefValidation(r Ref) (Ref, error)

SkipRefValidation is a helper validator that simply returns the provided ref, allowing validation to be skipped.

func (Ref) API

func (r Ref) API() string

API returns a ref formatted as an API appropriate URL (no tag info, but including api version `v2`).

func (Ref) APIString

func (r Ref) APIString() string

APIString for Ref returns an API string representation of a reference, including the 'v2' path element Note, this leaves off the scheme if defined.

func (Ref) AuthURL

func (r Ref) AuthURL() string

AuthURL returns a ref formatted as the base url used to authenticate a user with a registry. Example: https://us-central1-docker.pkg.dev

func (Ref) CombineRepoName

func (r Ref) CombineRepoName() string

CombineRepoName combines the repo and name values into one, unless repo and name are already the same.

func (Ref) IsEmpty

func (r Ref) IsEmpty() bool

IsEmpty will iterate over the fields in the given Ref struct r and return false if any field is a non-zero value.

func (Ref) IsInsecure

func (r Ref) IsInsecure() bool

IsInsecure returns true iff the reference scheme is set to "http".

func (Ref) Match

func (r Ref) Match(other Ref, matchType MatchType) bool

Match compares the selector Ref to the provided other Ref and returns true if they match. matchType provides options that determine what portions of the Ref are considered.

func (Ref) MountRef

func (r Ref) MountRef() string

MountRef returns a reference used by oras to discover cross-repo mount locations. https://github.com/opencontainers/distribution-spec/blob/main/spec.md#mounting-a-blob-from-another-repository.

func (Ref) RepoString

func (r Ref) RepoString() string

RepoString returns the full repository value, including repo and name as appropriate.

func (Ref) RepoStringWithScheme

func (r Ref) RepoStringWithScheme() string

RepoStringWithScheme returns the full repository value, including repo and name as appropriate, and including scheme for registry name.

func (Ref) String

func (r Ref) String() string

String for Ref returns a string representation of a reference Note, this leaves off the scheme if defined.

func (Ref) StringWithScheme

func (r Ref) StringWithScheme() string

StringWithScheme for Ref returns a string representation of a reference including the scheme if defined.

func (Ref) TagOrDigest

func (r Ref) TagOrDigest() string

TagOrDigest returns the tag or digest of a ref.

func (Ref) URL

func (r Ref) URL() string

URL returns a ref formatted as a URL (including the scheme).

type RepositoryListProvider

type RepositoryListProvider interface {
	// RepositoryList retrieves a list of known repositories based on a ref containing a registry and transfer scheme
	RepositoryList(registry Ref) ([]string, error)
}

RepositoryListProvider defines an interface for retrieving a string array list of repositories for a registry, as implemented by RegistryRepos. The registry info is provided as a Ref in order to also include the communication scheme if necessary.

type Set

type Set interface {
	Refs() []SourceRef

	// RefByReg should return a map associating a list of SourceRef to a registry or other association
	RefByReg() map[string][]SourceRef
}

Set defines an interface for retrieving a list of refs from a source provider. The Set is not a strict set, duplicates are possible and can be differentiated by retrieving the declaration matching the index of a given ref using the Decl function.

type SourceRef

type SourceRef interface {
	// GetRef returns the translated and parsed Ref structure for a SourceRef
	GetRef() Ref

	// GetDecl returns a string representing the original declaration of a reference (before translation to Ref)
	GetDecl() string
}

SourceRef is an interface that provides a Ref object for a source, as well as a custom string that is intended to be an initial declaration. This enables a Ref to be resolved from a declaration, but have the original information preserved for additional purposes, such as maintaining a record of processed references.

func NewDeclaredRef

func NewDeclaredRef(resolvedRef Ref, declaration string) SourceRef

NewDeclaredRef generates a SourceRef (internally, DeclRef) from a resolved bottle ref and an original declaration string.

func NewStringDeclaredRef

func NewStringDeclaredRef(declaration string) SourceRef

NewStringDeclaredRef returns a SourceRef (internally, DeclRef) based on the string form declaration of a Ref. This function assumes that the declaration can be parsed to a Ref. If unsure, resolve the reference elsewhere and use NewDeclaredRef.

type Validator

type Validator func(Ref) (Ref, error)

Validator defines a function that can examine a parsed reference and return an error or transformed Ref. Note, if no transform is done or there's no error, the supplied ref should be returned.

Jump to

Keyboard shortcuts

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