Skip to content

Commit ab57d1e

Browse files
stgraceStef Graces
authored and
Stef Graces
committed
Add ignoreValidation option for ParseReference
1 parent 098045d commit ab57d1e

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

Diff for: pkg/name/options.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ const (
2626
)
2727

2828
type options struct {
29-
strict bool // weak by default
30-
insecure bool // secure by default
31-
defaultRegistry string
32-
defaultTag string
29+
strict bool // weak by default
30+
insecure bool // secure by default
31+
ignoreValidation bool // validation by default
32+
defaultRegistry string
33+
defaultTag string
3334
}
3435

3536
func makeOptions(opts ...Option) options {
@@ -59,6 +60,13 @@ func WeakValidation(opts *options) {
5960
opts.strict = false
6061
}
6162

63+
// IgnoreValidation is an Option that does not require image references to be
64+
// valid. This is useful for testing purposes, but should not be used in
65+
// production code.
66+
func IgnoreValidation(opts *options) {
67+
opts.ignoreValidation = true
68+
}
69+
6270
// Insecure is an Option that allows image references to be fetched without TLS.
6371
func Insecure(opts *options) {
6472
opts.insecure = true

Diff for: pkg/name/registry.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ func NewRegistry(name string, opts ...Option) (Registry, error) {
117117
return Registry{}, newErrBadName("strict validation requires the registry to be explicitly defined")
118118
}
119119

120-
if err := checkRegistry(name); err != nil {
121-
return Registry{}, err
120+
if !opt.ignoreValidation {
121+
if err := checkRegistry(name); err != nil {
122+
return Registry{}, err
123+
}
122124
}
123125

124126
if name == "" {

Diff for: pkg/name/repository.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ func NewRepository(name string, opts ...Option) (Repository, error) {
8686
repo = parts[1]
8787
}
8888

89-
if err := checkRepository(repo); err != nil {
90-
return Repository{}, err
89+
if !opt.ignoreValidation {
90+
if err := checkRepository(repo); err != nil {
91+
return Repository{}, err
92+
}
9193
}
9294

9395
reg, err := NewRegistry(registry, opts...)

Diff for: pkg/name/tag.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ func NewTag(name string, opts ...Option) (Tag, error) {
8686
// even when not being strict.
8787
// If we are being strict, we want to validate the tag regardless in case
8888
// it's empty.
89-
if tag != "" || opt.strict {
90-
if err := checkTag(tag); err != nil {
91-
return Tag{}, err
89+
if !opt.ignoreValidation {
90+
if tag != "" || opt.strict {
91+
if err := checkTag(tag); err != nil {
92+
return Tag{}, err
93+
}
9294
}
9395
}
9496

0 commit comments

Comments
 (0)