Skip to content

Add ignoreValidation option for ParseReference #2087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pkg/name/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions pkg/name/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
6 changes: 4 additions & 2 deletions pkg/name/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
8 changes: 5 additions & 3 deletions pkg/name/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down