diff --git a/Gopkg.lock b/Gopkg.lock index 3d7d8dd0b2..49f42fb5cd 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -142,7 +142,7 @@ [[projects]] branch = "master" - digest = "1:2241fb4f2d265698118f5397b427f3c82c558494c38dcc90376bc1778fc00909" + digest = "1:907d8921af1cd16f38bc1ab77bce658830a4b46a1e293b627cfc1d7cc66e14b3" name = "github.com/google/go-containerregistry" packages = [ "pkg/authn", @@ -161,7 +161,7 @@ "pkg/v1/v1util", ] pruneopts = "UT" - revision = "8d4083db9aa0d2fae6588c1acdbe6a1f5db461e3" + revision = "7df26a6795af089f2cac25d48650d07960b2b33d" [[projects]] branch = "master" diff --git a/pkg/publish/daemon.go b/pkg/publish/daemon.go index d18e0703ce..c8019bbc2c 100644 --- a/pkg/publish/daemon.go +++ b/pkg/publish/daemon.go @@ -50,7 +50,7 @@ func (d *demon) Publish(img v1.Image, s string) (name.Reference, error) { return nil, err } - digestTag, err := name.NewTag(fmt.Sprintf("%s/%s:%s", LocalDomain, d.namer(s), h.Hex), name.WeakValidation) + digestTag, err := name.NewTag(fmt.Sprintf("%s/%s:%s", LocalDomain, d.namer(s), h.Hex)) if err != nil { return nil, err } @@ -63,7 +63,7 @@ func (d *demon) Publish(img v1.Image, s string) (name.Reference, error) { for _, tagName := range d.tags { log.Printf("Adding tag %v", tagName) - tag, err := name.NewTag(fmt.Sprintf("%s/%s:%s", LocalDomain, d.namer(s), tagName), name.WeakValidation) + tag, err := name.NewTag(fmt.Sprintf("%s/%s:%s", LocalDomain, d.namer(s), tagName)) if err != nil { return nil, err } diff --git a/pkg/publish/default.go b/pkg/publish/default.go index 0486b9ce5a..789887e883 100644 --- a/pkg/publish/default.go +++ b/pkg/publish/default.go @@ -95,7 +95,7 @@ func (d *defalt) Publish(img v1.Image, s string) (name.Reference, error) { s = strings.ToLower(s) for _, tagName := range d.tags { - tag, err := name.NewTag(fmt.Sprintf("%s/%s:%s", d.base, d.namer(s), tagName), name.WeakValidation) + tag, err := name.NewTag(fmt.Sprintf("%s/%s:%s", d.base, d.namer(s), tagName)) if err != nil { return nil, err } @@ -112,7 +112,7 @@ func (d *defalt) Publish(img v1.Image, s string) (name.Reference, error) { if err != nil { return nil, err } - dig, err := name.NewDigest(fmt.Sprintf("%s/%s@%s", d.base, d.namer(s), h), name.WeakValidation) + dig, err := name.NewDigest(fmt.Sprintf("%s/%s@%s", d.base, d.namer(s), h)) if err != nil { return nil, err } diff --git a/pkg/publish/default_test.go b/pkg/publish/default_test.go index 24d79a1a78..9f55803b2d 100644 --- a/pkg/publish/default_test.go +++ b/pkg/publish/default_test.go @@ -67,7 +67,7 @@ func TestDefault(t *testing.T) { if err != nil { t.Fatalf("url.Parse(%v) = %v", server.URL, err) } - tag, err := name.NewTag(fmt.Sprintf("%s/%s:latest", u.Host, expectedRepo), name.WeakValidation) + tag, err := name.NewTag(fmt.Sprintf("%s/%s:latest", u.Host, expectedRepo)) if err != nil { t.Fatalf("NewTag() = %v", err) } @@ -130,7 +130,7 @@ func TestDefaultWithCustomNamer(t *testing.T) { if err != nil { t.Fatalf("url.Parse(%v) = %v", server.URL, err) } - tag, err := name.NewTag(fmt.Sprintf("%s/%s:latest", u.Host, expectedRepo), name.WeakValidation) + tag, err := name.NewTag(fmt.Sprintf("%s/%s:latest", u.Host, expectedRepo)) if err != nil { t.Fatalf("NewTag() = %v", err) } @@ -194,7 +194,7 @@ func TestDefaultWithTags(t *testing.T) { if err != nil { t.Fatalf("url.Parse(%v) = %v", server.URL, err) } - tag, err := name.NewTag(fmt.Sprintf("%s/%s:notLatest", u.Host, expectedRepo), name.WeakValidation) + tag, err := name.NewTag(fmt.Sprintf("%s/%s:notLatest", u.Host, expectedRepo)) if err != nil { t.Fatalf("NewTag() = %v", err) } diff --git a/pkg/publish/future_test.go b/pkg/publish/future_test.go index ec23b9331f..243ec87044 100644 --- a/pkg/publish/future_test.go +++ b/pkg/publish/future_test.go @@ -31,7 +31,7 @@ func makeRef() (name.Reference, error) { if err != nil { return nil, err } - return name.NewDigest(fmt.Sprintf("gcr.io/foo/bar@%s", d), name.WeakValidation) + return name.NewDigest(fmt.Sprintf("gcr.io/foo/bar@%s", d)) } func TestSameFutureSameReference(t *testing.T) { diff --git a/pkg/publish/options.go b/pkg/publish/options.go index 30c7b95d8f..1b5cfbb15d 100644 --- a/pkg/publish/options.go +++ b/pkg/publish/options.go @@ -48,7 +48,7 @@ func WithAuthFromKeychain(keys authn.Keychain) Option { // means that docker.io/mattmoor actually gets interpreted as // docker.io/library/mattmoor, which gets tricky when we start // appending things to it in the publisher. - repo, err := name.NewRepository(i.base, name.WeakValidation) + repo, err := name.NewRepository(i.base) if err != nil { return err } diff --git a/pkg/resolve/fixed_test.go b/pkg/resolve/fixed_test.go index 62e372ef74..cbe911ec11 100644 --- a/pkg/resolve/fixed_test.go +++ b/pkg/resolve/fixed_test.go @@ -26,7 +26,7 @@ import ( ) var ( - fixedBaseRepo, _ = name.NewRepository("gcr.io/asdf", name.WeakValidation) + fixedBaseRepo, _ = name.NewRepository("gcr.io/asdf") testImage, _ = random.Image(1024, 5) ) @@ -129,7 +129,7 @@ func (f *fixedPublish) Publish(_ v1.Image, s string) (name.Reference, error) { if !ok { return nil, fmt.Errorf("unsupported importpath: %q", s) } - d, err := name.NewDigest(fmt.Sprintf("%s/%s@%s", f.base, s, h), name.WeakValidation) + d, err := name.NewDigest(fmt.Sprintf("%s/%s@%s", f.base, s, h)) if err != nil { return nil, err } diff --git a/pkg/resolve/resolve_test.go b/pkg/resolve/resolve_test.go index e8a957387f..ab6b04cb1f 100644 --- a/pkg/resolve/resolve_test.go +++ b/pkg/resolve/resolve_test.go @@ -316,7 +316,7 @@ func mustRandom() v1.Image { } func mustRepository(s string) name.Repository { - n, err := name.NewRepository(s, name.WeakValidation) + n, err := name.NewRepository(s) if err != nil { panic(err) } diff --git a/vendor/github.com/google/go-containerregistry/pkg/name/check.go b/vendor/github.com/google/go-containerregistry/pkg/name/check.go index 01a25d554a..01b03e5626 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/name/check.go +++ b/vendor/github.com/google/go-containerregistry/pkg/name/check.go @@ -19,15 +19,6 @@ import ( "unicode/utf8" ) -// Strictness defines the level of strictness for name validation. -type Strictness int - -// Enums for CRUD operations. -const ( - StrictValidation Strictness = iota - WeakValidation -) - // stripRunesFn returns a function which returns -1 (i.e. a value which // signals deletion in strings.Map) for runes in 'runes', and the rune otherwise. func stripRunesFn(runes string) func(rune) rune { diff --git a/vendor/github.com/google/go-containerregistry/pkg/name/digest.go b/vendor/github.com/google/go-containerregistry/pkg/name/digest.go index dc573ef1d8..d10856de7e 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/name/digest.go +++ b/vendor/github.com/google/go-containerregistry/pkg/name/digest.go @@ -63,8 +63,8 @@ func checkDigest(name string) error { return checkElement("digest", name, digestChars, 7+64, 7+64) } -// NewDigest returns a new Digest representing the given name, according to the given strictness. -func NewDigest(name string, strict Strictness) (Digest, error) { +// NewDigest returns a new Digest representing the given name. +func NewDigest(name string, opts ...Option) (Digest, error) { // Split on "@" parts := strings.Split(name, digestDelim) if len(parts) != 2 { @@ -78,12 +78,12 @@ func NewDigest(name string, strict Strictness) (Digest, error) { return Digest{}, err } - tag, err := NewTag(base, strict) + tag, err := NewTag(base, opts...) if err == nil { base = tag.Repository.Name() } - repo, err := NewRepository(base, strict) + repo, err := NewRepository(base, opts...) if err != nil { return Digest{}, err } diff --git a/vendor/github.com/google/go-containerregistry/pkg/name/options.go b/vendor/github.com/google/go-containerregistry/pkg/name/options.go new file mode 100644 index 0000000000..98beaae110 --- /dev/null +++ b/vendor/github.com/google/go-containerregistry/pkg/name/options.go @@ -0,0 +1,49 @@ +// Copyright 2018 Google LLC All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package name + +type options struct { + strict bool // weak by default + insecure bool // secure by default +} + +func makeOptions(opts ...Option) options { + opt := options{} + for _, o := range opts { + o(&opt) + } + return opt +} + +// Option is a functional option for name parsing. +type Option func(*options) + +// StrictValidation is an Option that requires image references to be fully +// specified; i.e. no defaulting for registry (dockerhub), repo (library), +// or tag (latest). +func StrictValidation(opts *options) { + opts.strict = true +} + +// WeakValidation is an Option that sets defaults when parsing names, see +// StrictValidation. +func WeakValidation(opts *options) { + opts.strict = false +} + +// Insecure is an Option that allows image references to be fetched without TLS. +func Insecure(opts *options) { + opts.insecure = true +} diff --git a/vendor/github.com/google/go-containerregistry/pkg/name/ref.go b/vendor/github.com/google/go-containerregistry/pkg/name/ref.go index 58775daa30..cca3034053 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/name/ref.go +++ b/vendor/github.com/google/go-containerregistry/pkg/name/ref.go @@ -38,11 +38,11 @@ type Reference interface { } // ParseReference parses the string as a reference, either by tag or digest. -func ParseReference(s string, strict Strictness) (Reference, error) { - if t, err := NewTag(s, strict); err == nil { +func ParseReference(s string, opts ...Option) (Reference, error) { + if t, err := NewTag(s, opts...); err == nil { return t, nil } - if d, err := NewDigest(s, strict); err == nil { + if d, err := NewDigest(s, opts...); err == nil { return d, nil } // TODO: Combine above errors into something more useful? diff --git a/vendor/github.com/google/go-containerregistry/pkg/name/registry.go b/vendor/github.com/google/go-containerregistry/pkg/name/registry.go index ab74193080..c12dd46c2c 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/name/registry.go +++ b/vendor/github.com/google/go-containerregistry/pkg/name/registry.go @@ -114,8 +114,9 @@ func checkRegistry(name string) error { // NewRegistry returns a Registry based on the given name. // Strict validation requires explicit, valid RFC 3986 URI authorities to be given. -func NewRegistry(name string, strict Strictness) (Registry, error) { - if strict == StrictValidation && len(name) == 0 { +func NewRegistry(name string, opts ...Option) (Registry, error) { + opt := makeOptions(opts...) + if opt.strict && len(name) == 0 { return Registry{}, NewErrBadName("strict validation requires the registry to be explicitly defined") } @@ -129,16 +130,13 @@ func NewRegistry(name string, strict Strictness) (Registry, error) { name = DefaultRegistry } - return Registry{registry: name}, nil + return Registry{registry: name, insecure: opt.insecure}, nil } // NewInsecureRegistry returns an Insecure Registry based on the given name. -// Strict validation requires explicit, valid RFC 3986 URI authorities to be given. -func NewInsecureRegistry(name string, strict Strictness) (Registry, error) { - reg, err := NewRegistry(name, strict) - if err != nil { - return Registry{}, err - } - reg.insecure = true - return reg, nil +// +// Deprecated: Use the Insecure Option with NewRegistry instead. +func NewInsecureRegistry(name string, opts ...Option) (Registry, error) { + opts = append(opts, Insecure) + return NewRegistry(name, opts...) } diff --git a/vendor/github.com/google/go-containerregistry/pkg/name/repository.go b/vendor/github.com/google/go-containerregistry/pkg/name/repository.go index 43cc5b82b3..f333779884 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/name/repository.go +++ b/vendor/github.com/google/go-containerregistry/pkg/name/repository.go @@ -68,7 +68,8 @@ func checkRepository(repository string) error { } // NewRepository returns a new Repository representing the given name, according to the given strictness. -func NewRepository(name string, strict Strictness) (Repository, error) { +func NewRepository(name string, opts ...Option) (Repository, error) { + opt := makeOptions(opts...) if len(name) == 0 { return Repository{}, NewErrBadName("a repository name must be specified") } @@ -88,11 +89,11 @@ func NewRepository(name string, strict Strictness) (Repository, error) { return Repository{}, err } - reg, err := NewRegistry(registry, strict) + reg, err := NewRegistry(registry, opts...) if err != nil { return Repository{}, err } - if hasImplicitNamespace(repo, reg) && strict == StrictValidation { + if hasImplicitNamespace(repo, reg) && opt.strict { return Repository{}, NewErrBadName("strict validation requires the full repository path (missing 'library')") } return Repository{reg, repo}, nil diff --git a/vendor/github.com/google/go-containerregistry/pkg/name/tag.go b/vendor/github.com/google/go-containerregistry/pkg/name/tag.go index b8375e1f9b..e6cce34dbd 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/name/tag.go +++ b/vendor/github.com/google/go-containerregistry/pkg/name/tag.go @@ -71,7 +71,8 @@ func checkTag(name string) error { } // NewTag returns a new Tag representing the given name, according to the given strictness. -func NewTag(name string, strict Strictness) (Tag, error) { +func NewTag(name string, opts ...Option) (Tag, error) { + opt := makeOptions(opts...) base := name tag := "" @@ -87,13 +88,13 @@ func NewTag(name string, strict Strictness) (Tag, error) { // even when not being strict. // If we are being strict, we want to validate the tag regardless in case // it's empty. - if tag != "" || strict == StrictValidation { + if tag != "" || opt.strict { if err := checkTag(tag); err != nil { return Tag{}, err } } - repo, err := NewRepository(base, strict) + repo, err := NewRepository(base, opts...) if err != nil { return Tag{}, err } diff --git a/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/image.go b/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/image.go index ced18735c8..5bf4fbf2f7 100644 --- a/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/image.go +++ b/vendor/github.com/google/go-containerregistry/pkg/v1/tarball/image.go @@ -119,7 +119,7 @@ func (td tarDescriptor) findSpecifiedImageDescriptor(tag *name.Tag) (*singleImag } for _, img := range td { for _, tagStr := range img.RepoTags { - repoTag, err := name.NewTag(tagStr, name.WeakValidation) + repoTag, err := name.NewTag(tagStr) if err != nil { return nil, err }