Skip to content

Commit e38bc55

Browse files
author
Stef Graces
committed
Add option to ignore validation on container registry
1 parent 098045d commit e38bc55

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

pkg/name/options.go

Lines changed: 12 additions & 4 deletions
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

pkg/name/registry.go

Lines changed: 4 additions & 2 deletions
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 == "" {

pkg/name/repository.go

Lines changed: 4 additions & 2 deletions
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...)

pkg/name/tag.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ 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 {
89+
if !opt.ignoreValidation || tag != "" || opt.strict {
9090
if err := checkTag(tag); err != nil {
9191
return Tag{}, err
9292
}

0 commit comments

Comments
 (0)