mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
registry: remove ErrInvalidRepositoryName
This error was only returned in a single location, and not used anywhere as a specific type. The error returned by `validateNoScheme()` also appeared to only be used in one case; in all other cases, the error itself was ignored, and replaced with a custom error. Because of this, this patch also replace `validateNoScheme()` with a `hasScheme()` function that returns a boolean, to better match how it's used. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
273dca4e3c
commit
98202c86ad
2 changed files with 6 additions and 15 deletions
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
registrytypes "github.com/docker/docker/api/types/registry"
|
registrytypes "github.com/docker/docker/api/types/registry"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -58,10 +57,6 @@ var (
|
||||||
Host: DefaultRegistryHost,
|
Host: DefaultRegistryHost,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrInvalidRepositoryName is an error returned if the repository name did
|
|
||||||
// not have the correct form
|
|
||||||
ErrInvalidRepositoryName = errors.New("Invalid repository name (ex: \"registry.domain.tld/myrepos\")")
|
|
||||||
|
|
||||||
emptyServiceConfig, _ = newServiceConfig(ServiceOptions{})
|
emptyServiceConfig, _ = newServiceConfig(ServiceOptions{})
|
||||||
validHostPortRegex = regexp.MustCompile(`^` + reference.DomainRegexp.String() + `$`)
|
validHostPortRegex = regexp.MustCompile(`^` + reference.DomainRegexp.String() + `$`)
|
||||||
|
|
||||||
|
@ -101,7 +96,7 @@ func (config *serviceConfig) loadAllowNondistributableArtifacts(registries []str
|
||||||
if _, err := ValidateIndexName(r); err != nil {
|
if _, err := ValidateIndexName(r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if validateNoScheme(r) != nil {
|
if hasScheme(r) {
|
||||||
return fmt.Errorf("allow-nondistributable-artifacts registry %s should not contain '://'", r)
|
return fmt.Errorf("allow-nondistributable-artifacts registry %s should not contain '://'", r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +183,7 @@ skip:
|
||||||
} else if strings.HasPrefix(strings.ToLower(r), "https://") {
|
} else if strings.HasPrefix(strings.ToLower(r), "https://") {
|
||||||
logrus.Warnf("insecure registry %s should not contain 'https://' and 'https://' has been removed from the insecure registry config", r)
|
logrus.Warnf("insecure registry %s should not contain 'https://' and 'https://' has been removed from the insecure registry config", r)
|
||||||
r = r[8:]
|
r = r[8:]
|
||||||
} else if validateNoScheme(r) != nil {
|
} else if hasScheme(r) {
|
||||||
// Insecure registry should not contain '://'
|
// Insecure registry should not contain '://'
|
||||||
// before returning err, roll back to original data
|
// before returning err, roll back to original data
|
||||||
config.ServiceConfig.InsecureRegistryCIDRs = originalCIDRs
|
config.ServiceConfig.InsecureRegistryCIDRs = originalCIDRs
|
||||||
|
@ -343,12 +338,8 @@ func ValidateIndexName(val string) (string, error) {
|
||||||
return val, nil
|
return val, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateNoScheme(reposName string) error {
|
func hasScheme(reposName string) bool {
|
||||||
if strings.Contains(reposName, "://") {
|
return strings.Contains(reposName, "://")
|
||||||
// It cannot contain a scheme!
|
|
||||||
return ErrInvalidRepositoryName
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateHostPort(s string) error {
|
func validateHostPort(s string) error {
|
||||||
|
|
|
@ -161,8 +161,8 @@ func splitReposSearchTerm(reposName string) (string, string) {
|
||||||
// search terms, and returns the results.
|
// search terms, and returns the results.
|
||||||
func (s *defaultService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error) {
|
func (s *defaultService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error) {
|
||||||
// TODO Use ctx when searching for repositories
|
// TODO Use ctx when searching for repositories
|
||||||
if err := validateNoScheme(term); err != nil {
|
if hasScheme(term) {
|
||||||
return nil, err
|
return nil, errors.New(`invalid repository name (ex: "registry.domain.tld/myrepos")`)
|
||||||
}
|
}
|
||||||
|
|
||||||
indexName, remoteName := splitReposSearchTerm(term)
|
indexName, remoteName := splitReposSearchTerm(term)
|
||||||
|
|
Loading…
Add table
Reference in a new issue