name

package
v0.0.0-...-a72880a Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package name provides a general type to represent any way of referencing images within the registry. Its main purpose is to abstract tags and digests (content-addressable hash).

Grammar

reference                       := name [ ":" tag ] [ "@" digest ]
name                            := [domain '/'] remote-name
domain                          := host [':' port-number]
host                            := domain-name | IPv4address | \[ IPv6address \]	; rfc3986 appendix-A
domain-name                     := domain-component ['.' domain-component]*
domain-component                := /([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])/
port-number                     := /[0-9]+/
path-component                  := alpha-numeric [separator alpha-numeric]*
path (or "remote-name")         := path-component ['/' path-component]*
alpha-numeric                   := /[a-z0-9]+/
separator                       := /[_.]|__|[-]*/

tag                             := /[\w][\w.-]{0,127}/

digest                          := digest-algorithm ":" digest-hex
digest-algorithm                := digest-algorithm-component [ digest-algorithm-separator digest-algorithm-component ]*
digest-algorithm-separator      := /[+.-_]/
digest-algorithm-component      := /[A-Za-z][A-Za-z0-9]*/
digest-hex                      := /[0-9a-fA-F]{32,}/ ; At least 128 bit digest value

identifier                      := /[a-f0-9]{64}/

NOTE

This package is draw inspiration deeply from the follow repositories:

  • github.com/docker/distribution/reference
  • oras.land/oras-go/v2/registry/reference.go
  • github.com/google/go-containerregistry/pkg/name

Index

Constants

View Source
const (
	// DefaultRegistry is the registry name that will be used if no registry
	// provided and the default is not overridden.
	DefaultRegistry = "registry-1.docker.io"

	// DefaultNamespace is the top-level repository path that will be used
	// if no namespace provided.
	DefaultNamespace = "library"

	// DefaultTag is the tag name that will be used if no tag provided and the
	// default is not overridden.
	DefaultTag = "latest"

	// DockerIOHostname is the hostname of DockerHub server.
	DockerIOHostname = "docker.io"

	// IndexHostname is the index hostname of DockerHub server.
	DockerIndexHostname = "index.docker.io"

	// DockerIndexServer is used for user auth and image search.
	DockerIndexServer = "https://" + DockerIndexHostname + "/v1/"
)

Variables

View Source
var (
	// ErrBadName is an error for when a bad name is supplied.
	ErrBadName = errors.New("bad name")
)

Functions

func Hostname

func Hostname(addr string) string

Hostname trys to parse the hostname from the given address.

func Namespace

func Namespace(path string) string

Namespace returns the top-level path-component in the path separated by "/", if not exists returns the default namespace "library".

func ValidateDigest

func ValidateDigest(dgst digest.Digest) error

ValidateDigest checks whether the digest is valid.

func ValidateReference

func ValidateReference(r Reference) error

ValidateReference checks whether the reference is valid.

func ValidateRegistry

func ValidateRegistry(r Registry) error

ValidateRegistry checks whether the Registry is valid.

func ValidateRegistryScheme

func ValidateRegistryScheme(scheme string) error

ValidateRegistryScheme checks whether the scheme provided is valid. Only "http", "https" or "" is allowed.

func ValidateRepository

func ValidateRepository(r Repository) error

ValidateRepository checks whether the Repository is valid.

func ValidateRepositoryPath

func ValidateRepositoryPath(path string) error

ValidateRepositoryPath checks whether the path provided is valid.

func ValidateTag

func ValidateTag(tag string) error

ValidateTag checks whether the tag is valid.

Types

type Digested

type Digested interface {
	Reference
	// Digest returns the digest of the reference.
	Digest() digest.Digest
}

Digested is an object which has a digest in which it can be referenced by.

func MustWithDigest

func MustWithDigest(r Repository, dgst digest.Digest) Digested

MustWithDigest wraps WithDigest with error panic.

func WithDigest

func WithDigest(r Repository, dgst digest.Digest) (Digested, error)

WithDigest combines the repository and the digest to a Digested reference.

type Option

type Option func(*options)

Option is a functional option for name parsing.

func WithDefaultRegistry

func WithDefaultRegistry(registry string) Option

WithDefaultRegistry sets the default registry that will be used if one is not provided. If not set, "registry-1.docker.io" will be used as default.

func WithDefaultTag

func WithDefaultTag(tag string) Option

WithDefaultTag sets the default tag that will be used if one is not provided. If not set, "latest" will be used as default.

func WithStrict

func WithStrict(strict bool) Option

WithStrict sets the parse mode. When set to "true", it enforces strict parsing rules, requiring image references to be fully specified. This disables default behavior and returns an error if any inconsistencies are found during parsing.

type Reference

type Reference interface {
	fmt.Stringer
	// Repository returns the name component as a Repository object.
	Repository() Repository
}

Reference is an opaque object reference identifier that may include modifiers such as a hostname, name, tag, and digest.

func NewReference

func NewReference(name string, opts ...Option) (Reference, error)

NewReference parses the string as a reference, either by tag or digest.

type Registry

type Registry interface {
	fmt.Stringer

	// Scheme returns the scheme ("http" or "https") of the registry. The
	// scheme may including by the raw domain string, or guessed by the
	// hostname such as "localhost" represents to "http", or set by user.
	// Otherwise it will return empty string "".
	Scheme() string

	// Hostname returns the hostname of the registry. A hostname can be
	// formatted as a domain-name, IPv4 address, or IPv6 address. More to
	// see RFC3986 appendix-A.
	Hostname() string

	// WithScheme returns a copy of Registry and overwrites with the scheme
	// provided.
	WithScheme(scheme string) Registry
}

Registry is a reference to a registry domain. A Registry has both scheme and hostname components.

func NewRegistry

func NewRegistry(name string, opts ...Option) (Registry, error)

NewRegistry returns a Registry based on the given name. If set strict as true, explicit and valid RFC 3986 URI authority is required to be given.

type Repository

type Repository interface {
	fmt.Stringer

	// Domain returns the domain component as a Registry object.
	Domain() Registry

	// Path returns the path (or "remote-name") component.
	Path() string
}

Repository is a reference to a repository with a name. A Repository has both domain and path components.

func MustWithPath

func MustWithPath(r Registry, path string) Repository

MustWithPath wraps WithPath with error panic.

func NewRepository

func NewRepository(name string, opts ...Option) (Repository, error)

NewRepository returns a Repository representing the given name.

func WithPath

func WithPath(r Registry, path string) (Repository, error)

WithPath combines the registry and the path to a Repository.

type Tagged

type Tagged interface {
	Reference
	// Tag returns the tag of the reference.
	Tag() string
}

Tagged is an object which has a tag.

func MustWithTag

func MustWithTag(r Repository, tag string) Tagged

MustWithTag wraps WithTag with error panic.

func WithTag

func WithTag(r Repository, tag string) (Tagged, error)

WithTag combines the repository and the tag to a Tagged reference.

Directories

Path Synopsis
Package internal provides private methods to process image name.
Package internal provides private methods to process image name.
xregexp
Package xregexp provides helpers to process regexp expressions.
Package xregexp provides helpers to process regexp expressions.

Jump to

Keyboard shortcuts

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