Skip to content

Commit 091dbc1

Browse files
author
Aaron Lehmann
committed
Update vendored distribution repo to new version
This version includes a fix that avoids checking against specific HTTP status codes. The previous behavior violated the registry API spec. Fixes moby#14975 Signed-off-by: Aaron Lehmann <[email protected]>
1 parent ae5c8e3 commit 091dbc1

11 files changed

Lines changed: 199 additions & 59 deletions

File tree

hack/vendor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ clone git github.com/coreos/go-etcd v2.0.0
3535
clone git github.com/hashicorp/consul v0.5.2
3636

3737
# get graph and distribution packages
38-
clone git github.com/docker/distribution cd8ff553b6b1911be23dfeabb73e33108bcbf147
38+
clone git github.com/docker/distribution e83345626608aa943d5c8a027fddcf54814d9545
3939
clone git github.com/vbatts/tar-split v0.9.4
4040

4141
clone git github.com/docker/notary 77bced079e83d80f40c1f0a544b1a8a3b97fb052

vendor/src/github.com/docker/distribution/blobs.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ var (
2727
// ErrBlobInvalidLength returned when the blob has an expected length on
2828
// commit, meaning mismatched with the descriptor or an invalid value.
2929
ErrBlobInvalidLength = errors.New("blob invalid length")
30+
31+
// ErrUnsupported returned when an unsupported operation is attempted
32+
ErrUnsupported = errors.New("unsupported operation")
3033
)
3134

3235
// ErrBlobInvalidDigest returned when digest check fails.
@@ -70,6 +73,11 @@ type BlobStatter interface {
7073
Stat(ctx context.Context, dgst digest.Digest) (Descriptor, error)
7174
}
7275

76+
// BlobDeleter enables deleting blobs from storage.
77+
type BlobDeleter interface {
78+
Delete(ctx context.Context, dgst digest.Digest) error
79+
}
80+
7381
// BlobDescriptorService manages metadata about a blob by digest. Most
7482
// implementations will not expose such an interface explicitly. Such mappings
7583
// should be maintained by interacting with the BlobIngester. Hence, this is
@@ -87,6 +95,9 @@ type BlobDescriptorService interface {
8795
// the restriction that the algorithm of the descriptor must match the
8896
// canonical algorithm (ie sha256) of the annotator.
8997
SetDescriptor(ctx context.Context, dgst digest.Digest, desc Descriptor) error
98+
99+
// Clear enables descriptors to be unlinked
100+
Clear(ctx context.Context, dgst digest.Digest) error
90101
}
91102

92103
// ReadSeekCloser is the primary reader type for blob data, combining
@@ -183,8 +194,9 @@ type BlobService interface {
183194
}
184195

185196
// BlobStore represent the entire suite of blob related operations. Such an
186-
// implementation can access, read, write and serve blobs.
197+
// implementation can access, read, write, delete and serve blobs.
187198
type BlobStore interface {
188199
BlobService
189200
BlobServer
201+
BlobDeleter
190202
}

vendor/src/github.com/docker/distribution/registry/api/v2/descriptors.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ var routeDescriptors = []RouteDescriptor{
398398
Description: "Fetch the tags under the repository identified by `name`.",
399399
Requests: []RequestDescriptor{
400400
{
401+
Name: "Tags",
402+
Description: "Return all tags for the repository",
401403
Headers: []ParameterDescriptor{
402404
hostHeader,
403405
authHeader,
@@ -455,6 +457,7 @@ var routeDescriptors = []RouteDescriptor{
455457
},
456458
},
457459
{
460+
Name: "Tags Paginated",
458461
Description: "Return a portion of the tags for the specified repository.",
459462
PathParameters: []ParameterDescriptor{nameParameterDescriptor},
460463
QueryParameters: paginationParameters,
@@ -483,6 +486,30 @@ var routeDescriptors = []RouteDescriptor{
483486
},
484487
},
485488
},
489+
Failures: []ResponseDescriptor{
490+
{
491+
StatusCode: http.StatusNotFound,
492+
Description: "The repository is not known to the registry.",
493+
Body: BodyDescriptor{
494+
ContentType: "application/json; charset=utf-8",
495+
Format: errorsBody,
496+
},
497+
ErrorCodes: []errcode.ErrorCode{
498+
ErrorCodeNameUnknown,
499+
},
500+
},
501+
{
502+
StatusCode: http.StatusUnauthorized,
503+
Description: "The client does not have access to the repository.",
504+
Body: BodyDescriptor{
505+
ContentType: "application/json; charset=utf-8",
506+
Format: errorsBody,
507+
},
508+
ErrorCodes: []errcode.ErrorCode{
509+
ErrorCodeUnauthorized,
510+
},
511+
},
512+
},
486513
},
487514
},
488515
},

vendor/src/github.com/docker/distribution/registry/client/auth/session.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"sync"
1111
"time"
1212

13+
"github.com/docker/distribution/registry/client"
1314
"github.com/docker/distribution/registry/client/transport"
1415
)
1516

@@ -209,7 +210,7 @@ func (th *tokenHandler) fetchToken(params map[string]string) (token string, err
209210
}
210211
defer resp.Body.Close()
211212

212-
if resp.StatusCode != http.StatusOK {
213+
if !client.SuccessStatus(resp.StatusCode) {
213214
return "", fmt.Errorf("token auth attempt for registry: %s request failed with status: %d %s", req.URL, resp.StatusCode, http.StatusText(resp.StatusCode))
214215
}
215216

vendor/src/github.com/docker/distribution/registry/client/blob_writer.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (hbu *httpBlobUpload) ReadFrom(r io.Reader) (n int64, err error) {
4444
return 0, err
4545
}
4646

47-
if resp.StatusCode != http.StatusAccepted {
47+
if !SuccessStatus(resp.StatusCode) {
4848
return 0, hbu.handleErrorResponse(resp)
4949
}
5050

@@ -79,7 +79,7 @@ func (hbu *httpBlobUpload) Write(p []byte) (n int, err error) {
7979
return 0, err
8080
}
8181

82-
if resp.StatusCode != http.StatusAccepted {
82+
if !SuccessStatus(resp.StatusCode) {
8383
return 0, hbu.handleErrorResponse(resp)
8484
}
8585

@@ -142,7 +142,7 @@ func (hbu *httpBlobUpload) Commit(ctx context.Context, desc distribution.Descrip
142142
}
143143
defer resp.Body.Close()
144144

145-
if resp.StatusCode != http.StatusCreated {
145+
if !SuccessStatus(resp.StatusCode) {
146146
return distribution.Descriptor{}, hbu.handleErrorResponse(resp)
147147
}
148148

@@ -160,12 +160,10 @@ func (hbu *httpBlobUpload) Cancel(ctx context.Context) error {
160160
}
161161
defer resp.Body.Close()
162162

163-
switch resp.StatusCode {
164-
case http.StatusNoContent, http.StatusNotFound:
163+
if resp.StatusCode == http.StatusNotFound || SuccessStatus(resp.StatusCode) {
165164
return nil
166-
default:
167-
return hbu.handleErrorResponse(resp)
168165
}
166+
return hbu.handleErrorResponse(resp)
169167
}
170168

171169
func (hbu *httpBlobUpload) Close() error {

vendor/src/github.com/docker/distribution/registry/client/errors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ func handleErrorResponse(resp *http.Response) error {
6161
}
6262
return &UnexpectedHTTPStatusError{Status: resp.Status}
6363
}
64+
65+
// SuccessStatus returns true if the argument is a successful HTTP response
66+
// code (in the range 200 - 399 inclusive).
67+
func SuccessStatus(status int) bool {
68+
return status >= 200 && status <= 399
69+
}

0 commit comments

Comments
 (0)