Round 2
Make Errors a []Error Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
parent
f565d6abb7
commit
00b1e8fca0
13 changed files with 98 additions and 116 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
ctxu "github.com/docker/distribution/context"
|
||||
"github.com/docker/distribution/digest"
|
||||
"github.com/docker/distribution/manifest"
|
||||
"github.com/docker/distribution/registry/api/errcode"
|
||||
"github.com/docker/distribution/registry/api/v2"
|
||||
"github.com/gorilla/handlers"
|
||||
"golang.org/x/net/context"
|
||||
|
@ -63,7 +64,7 @@ func (imh *imageManifestHandler) GetImageManifest(w http.ResponseWriter, r *http
|
|||
}
|
||||
|
||||
if err != nil {
|
||||
imh.Errors.Push(v2.ErrorCodeManifestUnknown, err)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeManifestUnknown, err))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -71,7 +72,7 @@ func (imh *imageManifestHandler) GetImageManifest(w http.ResponseWriter, r *http
|
|||
if imh.Digest == "" {
|
||||
dgst, err := digestManifest(imh, sm)
|
||||
if err != nil {
|
||||
imh.Errors.Push(v2.ErrorCodeDigestInvalid, err)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeDigestInvalid, err))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -92,13 +93,13 @@ func (imh *imageManifestHandler) PutImageManifest(w http.ResponseWriter, r *http
|
|||
|
||||
var manifest manifest.SignedManifest
|
||||
if err := dec.Decode(&manifest); err != nil {
|
||||
imh.Errors.Push(v2.ErrorCodeManifestInvalid, err)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeManifestInvalid, err))
|
||||
return
|
||||
}
|
||||
|
||||
dgst, err := digestManifest(imh, &manifest)
|
||||
if err != nil {
|
||||
imh.Errors.Push(v2.ErrorCodeDigestInvalid, err)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeDigestInvalid, err))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -106,7 +107,7 @@ func (imh *imageManifestHandler) PutImageManifest(w http.ResponseWriter, r *http
|
|||
if imh.Tag != "" {
|
||||
if manifest.Tag != imh.Tag {
|
||||
ctxu.GetLogger(imh).Errorf("invalid tag on manifest payload: %q != %q", manifest.Tag, imh.Tag)
|
||||
imh.Errors.Push(v2.ErrorCodeTagInvalid)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeTagInvalid))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -114,11 +115,11 @@ func (imh *imageManifestHandler) PutImageManifest(w http.ResponseWriter, r *http
|
|||
} else if imh.Digest != "" {
|
||||
if dgst != imh.Digest {
|
||||
ctxu.GetLogger(imh).Errorf("payload digest does match: %q != %q", dgst, imh.Digest)
|
||||
imh.Errors.Push(v2.ErrorCodeDigestInvalid)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeDigestInvalid))
|
||||
return
|
||||
}
|
||||
} else {
|
||||
imh.Errors.Push(v2.ErrorCodeTagInvalid, "no tag or digest specified")
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeTagInvalid, "no tag or digest specified"))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -130,19 +131,19 @@ func (imh *imageManifestHandler) PutImageManifest(w http.ResponseWriter, r *http
|
|||
for _, verificationError := range err {
|
||||
switch verificationError := verificationError.(type) {
|
||||
case distribution.ErrManifestBlobUnknown:
|
||||
imh.Errors.Push(v2.ErrorCodeBlobUnknown, verificationError.Digest)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeBlobUnknown, verificationError.Digest))
|
||||
case distribution.ErrManifestUnverified:
|
||||
imh.Errors.Push(v2.ErrorCodeManifestUnverified)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeManifestUnverified))
|
||||
default:
|
||||
if verificationError == digest.ErrDigestInvalidFormat {
|
||||
imh.Errors.Push(v2.ErrorCodeDigestInvalid)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeDigestInvalid))
|
||||
} else {
|
||||
imh.Errors.PushErr(verificationError)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(errcode.ErrorCodeUnknown, verificationError))
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
imh.Errors.PushErr(err)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(errcode.ErrorCodeUnknown, err))
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -171,7 +172,7 @@ func (imh *imageManifestHandler) DeleteImageManifest(w http.ResponseWriter, r *h
|
|||
// tag index entries a serious problem in eventually consistent storage.
|
||||
// Once we work out schema version 2, the full deletion system will be
|
||||
// worked out and we can add support back.
|
||||
imh.Errors.Push(v2.ErrorCodeUnsupported)
|
||||
imh.Errors = append(imh.Errors, errcode.NewError(v2.ErrorCodeUnsupported))
|
||||
}
|
||||
|
||||
// digestManifest takes a digest of the given manifest. This belongs somewhere
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue