From df1c58e788faa638f3b8ead70b49437425aab1d6 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Fri, 13 Jan 2017 11:22:55 -0800 Subject: [PATCH] Update distribution vendor Signed-off-by: Derek McGowan (github: dmcgowan) Upstream-commit: 24698a07cba89a08ac6fcc2c6e4097491b922883 Component: engine --- components/engine/vendor.conf | 2 +- .../docker/distribution/manifests.go | 20 ++++++------ .../docker/distribution/reference/helpers.go | 16 ++++++++-- .../distribution/reference/normalize.go | 26 +++++++++------- .../distribution/reference/reference.go | 31 +++++++------------ .../docker/distribution/registry.go | 2 +- .../registry/storage/cache/memory/memory.go | 2 +- 7 files changed, 52 insertions(+), 47 deletions(-) diff --git a/components/engine/vendor.conf b/components/engine/vendor.conf index 288f2aa243..04984f11f3 100644 --- a/components/engine/vendor.conf +++ b/components/engine/vendor.conf @@ -43,7 +43,7 @@ github.com/boltdb/bolt fff57c100f4dea1905678da7e90d92429dff2904 github.com/miekg/dns 75e6e86cc601825c5dbcd4e0c209eab180997cd7 # get graph and distribution packages -github.com/docker/distribution 129ad8ea0c3760d878b34cffdb9c3be874a7b2f7 +github.com/docker/distribution 545102ea07aa9796f189d82f606b7c27d7aa3ed3 github.com/vbatts/tar-split v0.10.1 github.com/opencontainers/go-digest a6d0ee40d4207ea02364bd3b9e8e77b9159ba1eb diff --git a/components/engine/vendor/github.com/docker/distribution/manifests.go b/components/engine/vendor/github.com/docker/distribution/manifests.go index d68e71db70..2c99f25d39 100644 --- a/components/engine/vendor/github.com/docker/distribution/manifests.go +++ b/components/engine/vendor/github.com/docker/distribution/manifests.go @@ -22,8 +22,8 @@ type Manifest interface { References() []Descriptor // Payload provides the serialized format of the manifest, in addition to - // the mediatype. - Payload() (mediatype string, payload []byte, err error) + // the media type. + Payload() (mediaType string, payload []byte, err error) } // ManifestBuilder creates a manifest allowing one to include dependencies. @@ -94,20 +94,20 @@ var mappings = make(map[string]UnmarshalFunc, 0) func UnmarshalManifest(ctHeader string, p []byte) (Manifest, Descriptor, error) { // Need to look up by the actual media type, not the raw contents of // the header. Strip semicolons and anything following them. - var mediatype string + var mediaType string if ctHeader != "" { var err error - mediatype, _, err = mime.ParseMediaType(ctHeader) + mediaType, _, err = mime.ParseMediaType(ctHeader) if err != nil { return nil, Descriptor{}, err } } - unmarshalFunc, ok := mappings[mediatype] + unmarshalFunc, ok := mappings[mediaType] if !ok { unmarshalFunc, ok = mappings[""] if !ok { - return nil, Descriptor{}, fmt.Errorf("unsupported manifest mediatype and no default available: %s", mediatype) + return nil, Descriptor{}, fmt.Errorf("unsupported manifest media type and no default available: %s", mediaType) } } @@ -116,10 +116,10 @@ func UnmarshalManifest(ctHeader string, p []byte) (Manifest, Descriptor, error) // RegisterManifestSchema registers an UnmarshalFunc for a given schema type. This // should be called from specific -func RegisterManifestSchema(mediatype string, u UnmarshalFunc) error { - if _, ok := mappings[mediatype]; ok { - return fmt.Errorf("manifest mediatype registration would overwrite existing: %s", mediatype) +func RegisterManifestSchema(mediaType string, u UnmarshalFunc) error { + if _, ok := mappings[mediaType]; ok { + return fmt.Errorf("manifest media type registration would overwrite existing: %s", mediaType) } - mappings[mediatype] = u + mappings[mediaType] = u return nil } diff --git a/components/engine/vendor/github.com/docker/distribution/reference/helpers.go b/components/engine/vendor/github.com/docker/distribution/reference/helpers.go index a8f46cedda..978df7eabb 100644 --- a/components/engine/vendor/github.com/docker/distribution/reference/helpers.go +++ b/components/engine/vendor/github.com/docker/distribution/reference/helpers.go @@ -1,5 +1,7 @@ package reference +import "path" + // IsNameOnly returns true if reference only contains a repo name. func IsNameOnly(ref Named) bool { if _, ok := ref.(NamedTagged); ok { @@ -14,7 +16,7 @@ func IsNameOnly(ref Named) bool { // FamiliarName returns the familiar name string // for the given named, familiarizing if needed. func FamiliarName(ref Named) string { - if nn, ok := ref.(NormalizedNamed); ok { + if nn, ok := ref.(normalizedNamed); ok { return nn.Familiar().Name() } return ref.Name() @@ -23,8 +25,18 @@ func FamiliarName(ref Named) string { // FamiliarString returns the familiar string representation // for the given reference, familiarizing if needed. func FamiliarString(ref Reference) string { - if nn, ok := ref.(NormalizedNamed); ok { + if nn, ok := ref.(normalizedNamed); ok { return nn.Familiar().String() } return ref.String() } + +// FamiliarMatch reports whether ref matches the specified pattern. +// See https://godoc.org/path#Match for supported patterns. +func FamiliarMatch(pattern string, ref Reference) (bool, error) { + matched, err := path.Match(pattern, FamiliarString(ref)) + if namedRef, isNamed := ref.(Named); isNamed && !matched { + matched, _ = path.Match(pattern, FamiliarName(namedRef)) + } + return matched, err +} diff --git a/components/engine/vendor/github.com/docker/distribution/reference/normalize.go b/components/engine/vendor/github.com/docker/distribution/reference/normalize.go index da797b705b..2d71fc5e9f 100644 --- a/components/engine/vendor/github.com/docker/distribution/reference/normalize.go +++ b/components/engine/vendor/github.com/docker/distribution/reference/normalize.go @@ -12,16 +12,16 @@ import ( var ( legacyDefaultDomain = "index.docker.io" defaultDomain = "docker.io" - defaultRepoPrefix = "library/" + officialRepoName = "library" defaultTag = "latest" ) -// NormalizedNamed represents a name which has been +// normalizedNamed represents a name which has been // normalized and has a familiar form. A familiar name // is what is used in Docker UI. An example normalized // name is "docker.io/library/ubuntu" and corresponding // familiar name of "ubuntu". -type NormalizedNamed interface { +type normalizedNamed interface { Named Familiar() Named } @@ -30,7 +30,7 @@ type NormalizedNamed interface { // transforming a familiar name from Docker UI to a fully // qualified reference. If the value may be an identifier // use ParseAnyReference. -func ParseNormalizedNamed(s string) (NormalizedNamed, error) { +func ParseNormalizedNamed(s string) (Named, error) { if ok := anchoredIdentifierRegexp.MatchString(s); ok { return nil, fmt.Errorf("invalid repository name (%s), cannot specify 64-byte hexadecimal strings", s) } @@ -49,7 +49,7 @@ func ParseNormalizedNamed(s string) (NormalizedNamed, error) { if err != nil { return nil, err } - named, isNamed := ref.(NormalizedNamed) + named, isNamed := ref.(Named) if !isNamed { return nil, fmt.Errorf("reference %s has no name", ref.String()) } @@ -70,7 +70,7 @@ func splitDockerDomain(name string) (domain, remainder string) { domain = defaultDomain } if domain == defaultDomain && !strings.ContainsRune(remainder, '/') { - remainder = defaultRepoPrefix + remainder + remainder = officialRepoName + "/" + remainder } return } @@ -89,7 +89,10 @@ func familiarizeName(named namedRepository) repository { if repo.domain == defaultDomain { repo.domain = "" - repo.path = strings.TrimPrefix(repo.path, defaultRepoPrefix) + // Handle official repositories which have the pattern "library/" + if split := strings.Split(repo.path, "/"); len(split) == 2 && split[0] == officialRepoName { + repo.path = split[1] + } } return repo } @@ -120,11 +123,10 @@ func (c canonicalReference) Familiar() Named { } } -// EnsureTagged adds the default tag "latest" to a reference if it only has +// TagNameOnly adds the default tag "latest" to a reference if it only has // a repo name. -func EnsureTagged(ref Named) NamedTagged { - namedTagged, ok := ref.(NamedTagged) - if !ok { +func TagNameOnly(ref Named) Named { + if IsNameOnly(ref) { namedTagged, err := WithTag(ref, defaultTag) if err != nil { // Default tag must be valid, to create a NamedTagged @@ -134,7 +136,7 @@ func EnsureTagged(ref Named) NamedTagged { } return namedTagged } - return namedTagged + return ref } // ParseAnyReference parses a reference string as a possible identifier, diff --git a/components/engine/vendor/github.com/docker/distribution/reference/reference.go b/components/engine/vendor/github.com/docker/distribution/reference/reference.go index 888e9b6d32..fd3510e9ee 100644 --- a/components/engine/vendor/github.com/docker/distribution/reference/reference.go +++ b/components/engine/vendor/github.com/docker/distribution/reference/reference.go @@ -20,14 +20,13 @@ // 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}/ -// short-identifier := /[a-f0-9]{6,64}/ +// identifier := /[a-f0-9]{64}/ +// short-identifier := /[a-f0-9]{6,64}/ package reference import ( "errors" "fmt" - "path" "strings" "github.com/opencontainers/go-digest" @@ -56,6 +55,9 @@ var ( // ErrNameTooLong is returned when a repository name is longer than NameTotalLengthMax. ErrNameTooLong = fmt.Errorf("repository name must not be more than %v characters", NameTotalLengthMax) + + // ErrNameNotCanonical is returned when a name is not canonical. + ErrNameNotCanonical = errors.New("repository name must be canonical") ) // Reference is an opaque object reference identifier that may include @@ -232,18 +234,17 @@ func Parse(s string) (Reference, error) { } // ParseNamed parses s and returns a syntactically valid reference implementing -// the Named interface. The reference must have a name, otherwise an error is -// returned. +// the Named interface. The reference must have a name and be in the canonical +// form, otherwise an error is returned. // If an error was encountered it is returned, along with a nil Reference. // NOTE: ParseNamed will not handle short digests. func ParseNamed(s string) (Named, error) { - ref, err := Parse(s) + named, err := ParseNormalizedNamed(s) if err != nil { return nil, err } - named, isNamed := ref.(Named) - if !isNamed { - return nil, fmt.Errorf("reference %s has no name", ref.String()) + if named.String() != s { + return nil, ErrNameNotCanonical } return named, nil } @@ -317,16 +318,6 @@ func WithDigest(name Named, digest digest.Digest) (Canonical, error) { }, nil } -// Match reports whether ref matches the specified pattern. -// See https://godoc.org/path#Match for supported patterns. -func Match(pattern string, ref Reference) (bool, error) { - matched, err := path.Match(pattern, ref.String()) - if namedRef, isNamed := ref.(Named); isNamed && !matched { - matched, _ = path.Match(pattern, namedRef.Name()) - } - return matched, err -} - // TrimNamed removes any tag or digest from the named reference. func TrimNamed(ref Named) Named { domain, path := SplitHostname(ref) @@ -408,7 +399,7 @@ func (r repository) Path() string { type digestReference digest.Digest func (d digestReference) String() string { - return d.String() + return digest.Digest(d).String() } func (d digestReference) Digest() digest.Digest { diff --git a/components/engine/vendor/github.com/docker/distribution/registry.go b/components/engine/vendor/github.com/docker/distribution/registry.go index 1ede31ebb6..1da1d533ff 100644 --- a/components/engine/vendor/github.com/docker/distribution/registry.go +++ b/components/engine/vendor/github.com/docker/distribution/registry.go @@ -35,7 +35,7 @@ type Namespace interface { // reference. Repository(ctx context.Context, name reference.Named) (Repository, error) - // Repositories fills 'repos' with a lexigraphically sorted catalog of repositories + // Repositories fills 'repos' with a lexicographically sorted catalog of repositories // up to the size of 'repos' and returns the value 'n' for the number of entries // which were filled. 'last' contains an offset in the catalog, and 'err' will be // set to io.EOF if there are no more entries to obtain. diff --git a/components/engine/vendor/github.com/docker/distribution/registry/storage/cache/memory/memory.go b/components/engine/vendor/github.com/docker/distribution/registry/storage/cache/memory/memory.go index a0be5ea029..b2fcaf4e8b 100644 --- a/components/engine/vendor/github.com/docker/distribution/registry/storage/cache/memory/memory.go +++ b/components/engine/vendor/github.com/docker/distribution/registry/storage/cache/memory/memory.go @@ -26,7 +26,7 @@ func NewInMemoryBlobDescriptorCacheProvider() cache.BlobDescriptorCacheProvider } func (imbdcp *inMemoryBlobDescriptorCacheProvider) RepositoryScoped(repo string) (distribution.BlobDescriptorService, error) { - if _, err := reference.ParseNamed(repo); err != nil { + if _, err := reference.ParseNormalizedNamed(repo); err != nil { return nil, err }