From d5cc235c4827e6c2f488415e41ef08fa9985094b Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Thu, 15 Dec 2016 14:58:54 -0800 Subject: [PATCH 1/2] digest: remove stuttering ParseDigest function Signed-off-by: Stephen J Day --- digest/digest.go | 8 ++++++-- digest/digest_test.go | 4 ++-- digest/set.go | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/digest/digest.go b/digest/digest.go index 65c6f7f0..67f3c875 100644 --- a/digest/digest.go +++ b/digest/digest.go @@ -63,12 +63,16 @@ var ( // ParseDigest parses s and returns the validated digest object. An error will // be returned if the format is invalid. -func ParseDigest(s string) (Digest, error) { +func Parse(s string) (Digest, error) { d := Digest(s) - return d, d.Validate() } +// ParseDigest is deprecated. Use Parse. +func ParseDigest(s string) (Digest, error) { + return Parse(s) +} + // FromReader returns the most valid digest for the underlying content using // the canonical digest algorithm. func FromReader(rd io.Reader) (Digest, error) { diff --git a/digest/digest_test.go b/digest/digest_test.go index afb4ebf6..75151e08 100644 --- a/digest/digest_test.go +++ b/digest/digest_test.go @@ -51,7 +51,7 @@ func TestParseDigest(t *testing.T) { err: ErrDigestUnsupported, }, } { - digest, err := ParseDigest(testcase.input) + digest, err := Parse(testcase.input) if err != testcase.err { t.Fatalf("error differed from expected while parsing %q: %v != %v", testcase.input, err, testcase.err) } @@ -69,7 +69,7 @@ func TestParseDigest(t *testing.T) { } // Parse string return value and check equality - newParsed, err := ParseDigest(digest.String()) + newParsed, err := Parse(digest.String()) if err != nil { t.Fatalf("unexpected error parsing input %q: %v", testcase.input, err) diff --git a/digest/set.go b/digest/set.go index 4b9313c1..6074080f 100644 --- a/digest/set.go +++ b/digest/set.go @@ -75,7 +75,7 @@ func (dst *Set) Lookup(d string) (Digest, error) { alg Algorithm hex string ) - dgst, err := ParseDigest(d) + dgst, err := Parse(d) if err == ErrDigestInvalidFormat { hex = d searchFunc = func(i int) bool { From 01dfa0fcb9af1d0c2b08e1008d8efcb95cbf5369 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Thu, 15 Dec 2016 15:07:42 -0800 Subject: [PATCH 2/2] digest: use digest.Parse over ParseDigest Signed-off-by: Stephen J Day --- reference/reference.go | 2 +- registry/client/repository.go | 6 +++--- registry/handlers/blobupload.go | 4 ++-- registry/handlers/context.go | 2 +- registry/handlers/images.go | 2 +- registry/storage/blobstore.go | 2 +- registry/storage/vacuum.go | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/reference/reference.go b/reference/reference.go index 02786628..29b949aa 100644 --- a/reference/reference.go +++ b/reference/reference.go @@ -170,7 +170,7 @@ func Parse(s string) (Reference, error) { } if matches[3] != "" { var err error - ref.digest, err = digest.ParseDigest(matches[3]) + ref.digest, err = digest.Parse(matches[3]) if err != nil { return nil, err } diff --git a/registry/client/repository.go b/registry/client/repository.go index 1ebd0b18..55dcf439 100644 --- a/registry/client/repository.go +++ b/registry/client/repository.go @@ -268,7 +268,7 @@ func descriptorFromResponse(response *http.Response) (distribution.Descriptor, e return desc, nil } - dgst, err := digest.ParseDigest(digestHeader) + dgst, err := digest.Parse(digestHeader) if err != nil { return distribution.Descriptor{}, err } @@ -475,7 +475,7 @@ func (ms *manifests) Get(ctx context.Context, dgst digest.Digest, options ...dis return nil, distribution.ErrManifestNotModified } else if SuccessStatus(resp.StatusCode) { if contentDgst != nil { - dgst, err := digest.ParseDigest(resp.Header.Get("Docker-Content-Digest")) + dgst, err := digest.Parse(resp.Header.Get("Docker-Content-Digest")) if err == nil { *contentDgst = dgst } @@ -553,7 +553,7 @@ func (ms *manifests) Put(ctx context.Context, m distribution.Manifest, options . if SuccessStatus(resp.StatusCode) { dgstHeader := resp.Header.Get("Docker-Content-Digest") - dgst, err := digest.ParseDigest(dgstHeader) + dgst, err := digest.Parse(dgstHeader) if err != nil { return "", err } diff --git a/registry/handlers/blobupload.go b/registry/handlers/blobupload.go index 3afb4739..09a86fc5 100644 --- a/registry/handlers/blobupload.go +++ b/registry/handlers/blobupload.go @@ -211,7 +211,7 @@ func (buh *blobUploadHandler) PutBlobUploadComplete(w http.ResponseWriter, r *ht return } - dgst, err := digest.ParseDigest(dgstStr) + dgst, err := digest.Parse(dgstStr) if err != nil { // no digest? return error, but allow retry. buh.Errors = append(buh.Errors, v2.ErrorCodeDigestInvalid.WithDetail("digest parsing failed")) @@ -329,7 +329,7 @@ func (buh *blobUploadHandler) blobUploadResponse(w http.ResponseWriter, r *http. // successful, the blob is linked into the blob store and 201 Created is // returned with the canonical url of the blob. func (buh *blobUploadHandler) createBlobMountOption(fromRepo, mountDigest string) (distribution.BlobCreateOption, error) { - dgst, err := digest.ParseDigest(mountDigest) + dgst, err := digest.Parse(mountDigest) if err != nil { return nil, err } diff --git a/registry/handlers/context.go b/registry/handlers/context.go index 552db2df..fb883f60 100644 --- a/registry/handlers/context.go +++ b/registry/handlers/context.go @@ -62,7 +62,7 @@ func getDigest(ctx context.Context) (dgst digest.Digest, err error) { return "", errDigestNotAvailable } - d, err := digest.ParseDigest(dgstStr) + d, err := digest.Parse(dgstStr) if err != nil { ctxu.GetLogger(ctx).Errorf("error parsing digest=%q: %v", dgstStr, err) return "", err diff --git a/registry/handlers/images.go b/registry/handlers/images.go index c51bbddb..5ed1e60c 100644 --- a/registry/handlers/images.go +++ b/registry/handlers/images.go @@ -33,7 +33,7 @@ func imageManifestDispatcher(ctx *Context, r *http.Request) http.Handler { Context: ctx, } reference := getReference(ctx) - dgst, err := digest.ParseDigest(reference) + dgst, err := digest.Parse(reference) if err != nil { // We just have a tag imageManifestHandler.Tag = reference diff --git a/registry/storage/blobstore.go b/registry/storage/blobstore.go index 4274cc9e..6ec2e66a 100644 --- a/registry/storage/blobstore.go +++ b/registry/storage/blobstore.go @@ -145,7 +145,7 @@ func (bs *blobStore) readlink(ctx context.Context, path string) (digest.Digest, return "", err } - linked, err := digest.ParseDigest(string(content)) + linked, err := digest.Parse(string(content)) if err != nil { return "", err } diff --git a/registry/storage/vacuum.go b/registry/storage/vacuum.go index 3bdfebf2..7302f733 100644 --- a/registry/storage/vacuum.go +++ b/registry/storage/vacuum.go @@ -29,7 +29,7 @@ type Vacuum struct { // RemoveBlob removes a blob from the filesystem func (v Vacuum) RemoveBlob(dgst string) error { - d, err := digest.ParseDigest(dgst) + d, err := digest.Parse(dgst) if err != nil { return err }