diff --git a/pkg/name/options.go b/pkg/name/options.go index d14fedcda..8047506e5 100644 --- a/pkg/name/options.go +++ b/pkg/name/options.go @@ -26,10 +26,11 @@ const ( ) type options struct { - strict bool // weak by default - insecure bool // secure by default - defaultRegistry string - defaultTag string + strict bool // weak by default + insecure bool // secure by default + ignoreValidation bool // validation by default + defaultRegistry string + defaultTag string } func makeOptions(opts ...Option) options { @@ -59,6 +60,13 @@ func WeakValidation(opts *options) { opts.strict = false } +// IgnoreValidation is an Option that does not require image references to be +// valid. This is useful for testing purposes, but should not be used in +// production code. +func IgnoreValidation(opts *options) { + opts.ignoreValidation = true +} + // Insecure is an Option that allows image references to be fetched without TLS. func Insecure(opts *options) { opts.insecure = true diff --git a/pkg/name/registry.go b/pkg/name/registry.go index 5e6b6e62a..4b714a223 100644 --- a/pkg/name/registry.go +++ b/pkg/name/registry.go @@ -124,8 +124,10 @@ func NewRegistry(name string, opts ...Option) (Registry, error) { return Registry{}, newErrBadName("strict validation requires the registry to be explicitly defined") } - if err := checkRegistry(name); err != nil { - return Registry{}, err + if !opt.ignoreValidation { + if err := checkRegistry(name); err != nil { + return Registry{}, err + } } if name == "" { diff --git a/pkg/name/repository.go b/pkg/name/repository.go index 290797575..bf11f464c 100644 --- a/pkg/name/repository.go +++ b/pkg/name/repository.go @@ -93,8 +93,10 @@ func NewRepository(name string, opts ...Option) (Repository, error) { repo = parts[1] } - if err := checkRepository(repo); err != nil { - return Repository{}, err + if !opt.ignoreValidation { + if err := checkRepository(repo); err != nil { + return Repository{}, err + } } reg, err := NewRegistry(registry, opts...) diff --git a/pkg/name/tag.go b/pkg/name/tag.go index 3848dc201..5562f3b63 100644 --- a/pkg/name/tag.go +++ b/pkg/name/tag.go @@ -91,9 +91,11 @@ func NewTag(name string, opts ...Option) (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 != "" || opt.strict { - if err := checkTag(tag); err != nil { - return Tag{}, err + if !opt.ignoreValidation { + if tag != "" || opt.strict { + if err := checkTag(tag); err != nil { + return Tag{}, err + } } }