Return "invalid parameter" (4xx) errors for distribution

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2018-08-03 16:36:43 +02:00
parent e6fe7f8f29
commit d71ed3d326
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 16 additions and 4 deletions

View File

@ -14,6 +14,7 @@ import (
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/errdefs"
"github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)
@ -42,9 +43,10 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res
image := vars["name"]
// TODO why is reference.ParseAnyReference() / reference.ParseNormalizedNamed() not using the reference.ErrTagInvalidFormat (and so on) errors?
ref, err := reference.ParseAnyReference(image)
if err != nil {
return err
return errdefs.InvalidParameter(err)
}
namedRef, ok := ref.(reference.Named)
if !ok {
@ -52,7 +54,7 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res
// full image ID
return errors.Errorf("no manifest found for full image ID")
}
return errors.Errorf("unknown image reference format: %s", image)
return errdefs.InvalidParameter(errors.Errorf("unknown image reference format: %s", image))
}
distrepo, _, err := s.backend.GetRepository(ctx, namedRef, config)
@ -66,7 +68,7 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res
taggedRef, ok := namedRef.(reference.NamedTagged)
if !ok {
return errors.Errorf("image reference not tagged: %s", image)
return errdefs.InvalidParameter(errors.Errorf("image reference not tagged: %s", image))
}
descriptor, err := distrepo.Tags(ctx).Get(ctx, taggedRef.Tag())
@ -92,6 +94,16 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res
}
mnfst, err := mnfstsrvc.Get(ctx, distributionInspect.Descriptor.Digest)
if err != nil {
switch err {
case reference.ErrReferenceInvalidFormat,
reference.ErrTagInvalidFormat,
reference.ErrDigestInvalidFormat,
reference.ErrNameContainsUppercase,
reference.ErrNameEmpty,
reference.ErrNameTooLong,
reference.ErrNameNotCanonical:
return errdefs.InvalidParameter(err)
}
return err
}

View File

@ -92,7 +92,7 @@ func (i *ImageService) GetRepository(ctx context.Context, ref reference.Named, a
// get repository info
repoInfo, err := i.registryService.ResolveRepository(ref)
if err != nil {
return nil, false, err
return nil, false, errdefs.InvalidParameter(err)
}
// makes sure name is not empty or `scratch`
if err := distribution.ValidateRepoName(repoInfo.Name); err != nil {