vendor: github.com/distribution/reference v0.6.0
full diff: https://github.com/distribution/reference/compare/v0.5.0...v0.6.0 - remove deprecated SplitHostname - refactor splitDockerDomain to include more documentation - fix typo in readme - Exclude domain from name length check Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Родитель
28836375b3
Коммит
d11fbda360
|
@ -10,7 +10,7 @@ require (
|
|||
dario.cat/mergo v1.0.0
|
||||
github.com/containerd/platforms v0.2.0
|
||||
github.com/creack/pty v1.1.21
|
||||
github.com/distribution/reference v0.5.0
|
||||
github.com/distribution/reference v0.6.0
|
||||
github.com/docker/distribution v2.8.3+incompatible
|
||||
github.com/docker/docker v26.1.1-0.20240607121412-59996a493cfc+incompatible // master (v27.0.0-dev)
|
||||
github.com/docker/docker-credential-helpers v0.8.2
|
||||
|
|
|
@ -54,8 +54,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
|||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20191128021309-1d7a30a10f73/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
||||
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
|
||||
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
|
||||
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
|
||||
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
|
||||
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
|
||||
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||
|
|
|
@ -10,7 +10,7 @@ Go library to handle references to container images.
|
|||
[![codecov](https://codecov.io/gh/distribution/reference/branch/main/graph/badge.svg)](https://codecov.io/gh/distribution/reference)
|
||||
[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B162%2Fgithub.com%2Fdistribution%2Freference.svg?type=shield)](https://app.fossa.com/projects/custom%2B162%2Fgithub.com%2Fdistribution%2Freference?ref=badge_shield)
|
||||
|
||||
This repository contains a library for handling refrences to container images held in container registries. Please see [godoc](https://pkg.go.dev/github.com/distribution/reference) for details.
|
||||
This repository contains a library for handling references to container images held in container registries. Please see [godoc](https://pkg.go.dev/github.com/distribution/reference) for details.
|
||||
|
||||
## Contribution
|
||||
|
||||
|
|
|
@ -123,20 +123,51 @@ func ParseDockerRef(ref string) (Named, error) {
|
|||
// splitDockerDomain splits a repository name to domain and remote-name.
|
||||
// If no valid domain is found, the default domain is used. Repository name
|
||||
// needs to be already validated before.
|
||||
func splitDockerDomain(name string) (domain, remainder string) {
|
||||
i := strings.IndexRune(name, '/')
|
||||
if i == -1 || (!strings.ContainsAny(name[:i], ".:") && name[:i] != localhost && strings.ToLower(name[:i]) == name[:i]) {
|
||||
domain, remainder = defaultDomain, name
|
||||
} else {
|
||||
domain, remainder = name[:i], name[i+1:]
|
||||
func splitDockerDomain(name string) (domain, remoteName string) {
|
||||
maybeDomain, maybeRemoteName, ok := strings.Cut(name, "/")
|
||||
if !ok {
|
||||
// Fast-path for single element ("familiar" names), such as "ubuntu"
|
||||
// or "ubuntu:latest". Familiar names must be handled separately, to
|
||||
// prevent them from being handled as "hostname:port".
|
||||
//
|
||||
// Canonicalize them as "docker.io/library/name[:tag]"
|
||||
|
||||
// FIXME(thaJeztah): account for bare "localhost" or "example.com" names, which SHOULD be considered a domain.
|
||||
return defaultDomain, officialRepoPrefix + name
|
||||
}
|
||||
if domain == legacyDefaultDomain {
|
||||
domain = defaultDomain
|
||||
|
||||
switch {
|
||||
case maybeDomain == localhost:
|
||||
// localhost is a reserved namespace and always considered a domain.
|
||||
domain, remoteName = maybeDomain, maybeRemoteName
|
||||
case maybeDomain == legacyDefaultDomain:
|
||||
// canonicalize the Docker Hub and legacy "Docker Index" domains.
|
||||
domain, remoteName = defaultDomain, maybeRemoteName
|
||||
case strings.ContainsAny(maybeDomain, ".:"):
|
||||
// Likely a domain or IP-address:
|
||||
//
|
||||
// - contains a "." (e.g., "example.com" or "127.0.0.1")
|
||||
// - contains a ":" (e.g., "example:5000", "::1", or "[::1]:5000")
|
||||
domain, remoteName = maybeDomain, maybeRemoteName
|
||||
case strings.ToLower(maybeDomain) != maybeDomain:
|
||||
// Uppercase namespaces are not allowed, so if the first element
|
||||
// is not lowercase, we assume it to be a domain-name.
|
||||
domain, remoteName = maybeDomain, maybeRemoteName
|
||||
default:
|
||||
// None of the above: it's not a domain, so use the default, and
|
||||
// use the name input the remote-name.
|
||||
domain, remoteName = defaultDomain, name
|
||||
}
|
||||
if domain == defaultDomain && !strings.ContainsRune(remainder, '/') {
|
||||
remainder = officialRepoPrefix + remainder
|
||||
|
||||
if domain == defaultDomain && !strings.ContainsRune(remoteName, '/') {
|
||||
// Canonicalize "familiar" names, but only on Docker Hub, not
|
||||
// on other domains:
|
||||
//
|
||||
// "docker.io/ubuntu[:tag]" => "docker.io/library/ubuntu[:tag]"
|
||||
remoteName = officialRepoPrefix + remoteName
|
||||
}
|
||||
return
|
||||
|
||||
return domain, remoteName
|
||||
}
|
||||
|
||||
// familiarizeName returns a shortened version of the name familiar
|
||||
|
|
|
@ -35,8 +35,13 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// RepositoryNameTotalLengthMax is the maximum total number of characters in a repository name.
|
||||
RepositoryNameTotalLengthMax = 255
|
||||
|
||||
// NameTotalLengthMax is the maximum total number of characters in a repository name.
|
||||
NameTotalLengthMax = 255
|
||||
//
|
||||
// Deprecated: use [RepositoryNameTotalLengthMax] instead.
|
||||
NameTotalLengthMax = RepositoryNameTotalLengthMax
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -55,8 +60,8 @@ var (
|
|||
// ErrNameEmpty is returned for empty, invalid repository names.
|
||||
ErrNameEmpty = errors.New("repository name must have at least one component")
|
||||
|
||||
// ErrNameTooLong is returned when a repository name is longer than NameTotalLengthMax.
|
||||
ErrNameTooLong = fmt.Errorf("repository name must not be more than %v characters", NameTotalLengthMax)
|
||||
// ErrNameTooLong is returned when a repository name is longer than RepositoryNameTotalLengthMax.
|
||||
ErrNameTooLong = fmt.Errorf("repository name must not be more than %v characters", RepositoryNameTotalLengthMax)
|
||||
|
||||
// ErrNameNotCanonical is returned when a name is not canonical.
|
||||
ErrNameNotCanonical = errors.New("repository name must be canonical")
|
||||
|
@ -165,6 +170,9 @@ func Path(named Named) (name string) {
|
|||
return path
|
||||
}
|
||||
|
||||
// splitDomain splits a named reference into a hostname and path string.
|
||||
// If no valid hostname is found, the hostname is empty and the full value
|
||||
// is returned as name
|
||||
func splitDomain(name string) (string, string) {
|
||||
match := anchoredNameRegexp.FindStringSubmatch(name)
|
||||
if len(match) != 3 {
|
||||
|
@ -173,19 +181,6 @@ func splitDomain(name string) (string, string) {
|
|||
return match[1], match[2]
|
||||
}
|
||||
|
||||
// SplitHostname splits a named reference into a
|
||||
// hostname and name string. If no valid hostname is
|
||||
// found, the hostname is empty and the full value
|
||||
// is returned as name
|
||||
//
|
||||
// Deprecated: Use [Domain] or [Path].
|
||||
func SplitHostname(named Named) (string, string) {
|
||||
if r, ok := named.(namedRepository); ok {
|
||||
return r.Domain(), r.Path()
|
||||
}
|
||||
return splitDomain(named.Name())
|
||||
}
|
||||
|
||||
// Parse parses s and returns a syntactically valid Reference.
|
||||
// If an error was encountered it is returned, along with a nil Reference.
|
||||
func Parse(s string) (Reference, error) {
|
||||
|
@ -200,10 +195,6 @@ func Parse(s string) (Reference, error) {
|
|||
return nil, ErrReferenceInvalidFormat
|
||||
}
|
||||
|
||||
if len(matches[1]) > NameTotalLengthMax {
|
||||
return nil, ErrNameTooLong
|
||||
}
|
||||
|
||||
var repo repository
|
||||
|
||||
nameMatch := anchoredNameRegexp.FindStringSubmatch(matches[1])
|
||||
|
@ -215,6 +206,10 @@ func Parse(s string) (Reference, error) {
|
|||
repo.path = matches[1]
|
||||
}
|
||||
|
||||
if len(repo.path) > RepositoryNameTotalLengthMax {
|
||||
return nil, ErrNameTooLong
|
||||
}
|
||||
|
||||
ref := reference{
|
||||
namedRepository: repo,
|
||||
tag: matches[2],
|
||||
|
@ -253,14 +248,15 @@ func ParseNamed(s string) (Named, error) {
|
|||
// WithName returns a named object representing the given string. If the input
|
||||
// is invalid ErrReferenceInvalidFormat will be returned.
|
||||
func WithName(name string) (Named, error) {
|
||||
if len(name) > NameTotalLengthMax {
|
||||
return nil, ErrNameTooLong
|
||||
}
|
||||
|
||||
match := anchoredNameRegexp.FindStringSubmatch(name)
|
||||
if match == nil || len(match) != 3 {
|
||||
return nil, ErrReferenceInvalidFormat
|
||||
}
|
||||
|
||||
if len(match[2]) > RepositoryNameTotalLengthMax {
|
||||
return nil, ErrNameTooLong
|
||||
}
|
||||
|
||||
return repository{
|
||||
domain: match[1],
|
||||
path: match[2],
|
||||
|
|
|
@ -36,7 +36,7 @@ github.com/containerd/platforms
|
|||
# github.com/creack/pty v1.1.21
|
||||
## explicit; go 1.13
|
||||
github.com/creack/pty
|
||||
# github.com/distribution/reference v0.5.0
|
||||
# github.com/distribution/reference v0.6.0
|
||||
## explicit; go 1.20
|
||||
github.com/distribution/reference
|
||||
# github.com/docker/distribution v2.8.3+incompatible
|
||||
|
|
Загрузка…
Ссылка в новой задаче