Fixes repo parsing

Signed-off-by: Juned Memon <junaid18183@gmail.com>
pull/8089/head
Juned Memon 5 years ago
parent af52d35fb6
commit b473f8adec
No known key found for this signature in database
GPG Key ID: B7C1868E3994DA9E

@ -34,6 +34,10 @@ var (
referenceDelimiter = regexp.MustCompile(`[:]`) referenceDelimiter = regexp.MustCompile(`[:]`)
errEmptyRepo = errors.New("parsed repo was empty") errEmptyRepo = errors.New("parsed repo was empty")
errTooManyColons = errors.New("ref may only contain a single colon character (:) unless specifying a port number") errTooManyColons = errors.New("ref may only contain a single colon character (:) unless specifying a port number")
// ErrInvalid is returned when there is an invalid reference
ErrInvalid = errors.New("invalid reference")
// ErrHostnameRequired is returned when the hostname is required
ErrHostnameRequired = errors.New("hostname required")
) )
type ( type (
@ -86,6 +90,7 @@ func (ref *Reference) FullName() string {
// validate makes sure the ref meets our criteria // validate makes sure the ref meets our criteria
func (ref *Reference) validate() error { func (ref *Reference) validate() error {
err := ref.validateRepo() err := ref.validateRepo()
if err != nil { if err != nil {
return err return err
@ -100,7 +105,15 @@ func (ref *Reference) validateRepo() error {
} }
// Makes sure the repo results in a parsable URL (similar to what is done // Makes sure the repo results in a parsable URL (similar to what is done
// with containerd reference parsing) // with containerd reference parsing)
_, err := url.Parse(ref.Repo) u, err := url.Parse("dummy://" + ref.Repo)
if u.Scheme != "dummy" {
return ErrInvalid
}
if u.Host == "" {
return ErrHostnameRequired
}
return err return err
} }

Loading…
Cancel
Save