mirror of
https://github.com/ko-build/ko.git
synced 2025-03-26 21:12:45 +02:00
Drop name.WeakValidation
This commit is contained in:
parent
f0a367da93
commit
86a2d43f43
4
Gopkg.lock
generated
4
Gopkg.lock
generated
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
9
vendor/github.com/google/go-containerregistry/pkg/name/check.go
generated
vendored
9
vendor/github.com/google/go-containerregistry/pkg/name/check.go
generated
vendored
@ -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 {
|
||||
|
8
vendor/github.com/google/go-containerregistry/pkg/name/digest.go
generated
vendored
8
vendor/github.com/google/go-containerregistry/pkg/name/digest.go
generated
vendored
@ -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
|
||||
}
|
||||
|
49
vendor/github.com/google/go-containerregistry/pkg/name/options.go
generated
vendored
Normal file
49
vendor/github.com/google/go-containerregistry/pkg/name/options.go
generated
vendored
Normal file
@ -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
|
||||
}
|
6
vendor/github.com/google/go-containerregistry/pkg/name/ref.go
generated
vendored
6
vendor/github.com/google/go-containerregistry/pkg/name/ref.go
generated
vendored
@ -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?
|
||||
|
20
vendor/github.com/google/go-containerregistry/pkg/name/registry.go
generated
vendored
20
vendor/github.com/google/go-containerregistry/pkg/name/registry.go
generated
vendored
@ -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...)
|
||||
}
|
||||
|
7
vendor/github.com/google/go-containerregistry/pkg/name/repository.go
generated
vendored
7
vendor/github.com/google/go-containerregistry/pkg/name/repository.go
generated
vendored
@ -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
|
||||
|
7
vendor/github.com/google/go-containerregistry/pkg/name/tag.go
generated
vendored
7
vendor/github.com/google/go-containerregistry/pkg/name/tag.go
generated
vendored
@ -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
|
||||
}
|
||||
|
2
vendor/github.com/google/go-containerregistry/pkg/v1/tarball/image.go
generated
vendored
2
vendor/github.com/google/go-containerregistry/pkg/v1/tarball/image.go
generated
vendored
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user