|
@@ -70,8 +70,7 @@ func (r *registry) Repositories(ctx context.Context, entries []string, last stri
|
|
}
|
|
}
|
|
defer resp.Body.Close()
|
|
defer resp.Body.Close()
|
|
|
|
|
|
- switch resp.StatusCode {
|
|
|
|
- case http.StatusOK:
|
|
|
|
|
|
+ if SuccessStatus(resp.StatusCode) {
|
|
var ctlg struct {
|
|
var ctlg struct {
|
|
Repositories []string `json:"repositories"`
|
|
Repositories []string `json:"repositories"`
|
|
}
|
|
}
|
|
@@ -90,8 +89,7 @@ func (r *registry) Repositories(ctx context.Context, entries []string, last stri
|
|
if link == "" {
|
|
if link == "" {
|
|
returnErr = io.EOF
|
|
returnErr = io.EOF
|
|
}
|
|
}
|
|
-
|
|
|
|
- default:
|
|
|
|
|
|
+ } else {
|
|
return 0, handleErrorResponse(resp)
|
|
return 0, handleErrorResponse(resp)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -199,8 +197,7 @@ func (ms *manifests) Tags() ([]string, error) {
|
|
}
|
|
}
|
|
defer resp.Body.Close()
|
|
defer resp.Body.Close()
|
|
|
|
|
|
- switch resp.StatusCode {
|
|
|
|
- case http.StatusOK:
|
|
|
|
|
|
+ if SuccessStatus(resp.StatusCode) {
|
|
b, err := ioutil.ReadAll(resp.Body)
|
|
b, err := ioutil.ReadAll(resp.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
@@ -214,11 +211,10 @@ func (ms *manifests) Tags() ([]string, error) {
|
|
}
|
|
}
|
|
|
|
|
|
return tagsResponse.Tags, nil
|
|
return tagsResponse.Tags, nil
|
|
- case http.StatusNotFound:
|
|
|
|
|
|
+ } else if resp.StatusCode == http.StatusNotFound {
|
|
return nil, nil
|
|
return nil, nil
|
|
- default:
|
|
|
|
- return nil, handleErrorResponse(resp)
|
|
|
|
}
|
|
}
|
|
|
|
+ return nil, handleErrorResponse(resp)
|
|
}
|
|
}
|
|
|
|
|
|
func (ms *manifests) Exists(dgst digest.Digest) (bool, error) {
|
|
func (ms *manifests) Exists(dgst digest.Digest) (bool, error) {
|
|
@@ -238,14 +234,12 @@ func (ms *manifests) ExistsByTag(tag string) (bool, error) {
|
|
return false, err
|
|
return false, err
|
|
}
|
|
}
|
|
|
|
|
|
- switch resp.StatusCode {
|
|
|
|
- case http.StatusOK:
|
|
|
|
|
|
+ if SuccessStatus(resp.StatusCode) {
|
|
return true, nil
|
|
return true, nil
|
|
- case http.StatusNotFound:
|
|
|
|
|
|
+ } else if resp.StatusCode == http.StatusNotFound {
|
|
return false, nil
|
|
return false, nil
|
|
- default:
|
|
|
|
- return false, handleErrorResponse(resp)
|
|
|
|
}
|
|
}
|
|
|
|
+ return false, handleErrorResponse(resp)
|
|
}
|
|
}
|
|
|
|
|
|
func (ms *manifests) Get(dgst digest.Digest) (*manifest.SignedManifest, error) {
|
|
func (ms *manifests) Get(dgst digest.Digest) (*manifest.SignedManifest, error) {
|
|
@@ -254,13 +248,14 @@ func (ms *manifests) Get(dgst digest.Digest) (*manifest.SignedManifest, error) {
|
|
return ms.GetByTag(dgst.String())
|
|
return ms.GetByTag(dgst.String())
|
|
}
|
|
}
|
|
|
|
|
|
-// AddEtagToTag allows a client to supply an eTag to GetByTag which will
|
|
|
|
-// be used for a conditional HTTP request. If the eTag matches, a nil
|
|
|
|
-// manifest and nil error will be returned.
|
|
|
|
-func AddEtagToTag(tagName, dgst string) distribution.ManifestServiceOption {
|
|
|
|
|
|
+// AddEtagToTag allows a client to supply an eTag to GetByTag which will be
|
|
|
|
+// used for a conditional HTTP request. If the eTag matches, a nil manifest
|
|
|
|
+// and nil error will be returned. etag is automatically quoted when added to
|
|
|
|
+// this map.
|
|
|
|
+func AddEtagToTag(tag, etag string) distribution.ManifestServiceOption {
|
|
return func(ms distribution.ManifestService) error {
|
|
return func(ms distribution.ManifestService) error {
|
|
if ms, ok := ms.(*manifests); ok {
|
|
if ms, ok := ms.(*manifests); ok {
|
|
- ms.etags[tagName] = dgst
|
|
|
|
|
|
+ ms.etags[tag] = fmt.Sprintf(`"%s"`, etag)
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
return fmt.Errorf("etag options is a client-only option")
|
|
return fmt.Errorf("etag options is a client-only option")
|
|
@@ -293,8 +288,9 @@ func (ms *manifests) GetByTag(tag string, options ...distribution.ManifestServic
|
|
}
|
|
}
|
|
defer resp.Body.Close()
|
|
defer resp.Body.Close()
|
|
|
|
|
|
- switch resp.StatusCode {
|
|
|
|
- case http.StatusOK:
|
|
|
|
|
|
+ if resp.StatusCode == http.StatusNotModified {
|
|
|
|
+ return nil, nil
|
|
|
|
+ } else if SuccessStatus(resp.StatusCode) {
|
|
var sm manifest.SignedManifest
|
|
var sm manifest.SignedManifest
|
|
decoder := json.NewDecoder(resp.Body)
|
|
decoder := json.NewDecoder(resp.Body)
|
|
|
|
|
|
@@ -302,11 +298,8 @@ func (ms *manifests) GetByTag(tag string, options ...distribution.ManifestServic
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
return &sm, nil
|
|
return &sm, nil
|
|
- case http.StatusNotModified:
|
|
|
|
- return nil, nil
|
|
|
|
- default:
|
|
|
|
- return nil, handleErrorResponse(resp)
|
|
|
|
}
|
|
}
|
|
|
|
+ return nil, handleErrorResponse(resp)
|
|
}
|
|
}
|
|
|
|
|
|
func (ms *manifests) Put(m *manifest.SignedManifest) error {
|
|
func (ms *manifests) Put(m *manifest.SignedManifest) error {
|
|
@@ -328,13 +321,11 @@ func (ms *manifests) Put(m *manifest.SignedManifest) error {
|
|
}
|
|
}
|
|
defer resp.Body.Close()
|
|
defer resp.Body.Close()
|
|
|
|
|
|
- switch resp.StatusCode {
|
|
|
|
- case http.StatusAccepted:
|
|
|
|
|
|
+ if SuccessStatus(resp.StatusCode) {
|
|
// TODO(dmcgowan): make use of digest header
|
|
// TODO(dmcgowan): make use of digest header
|
|
return nil
|
|
return nil
|
|
- default:
|
|
|
|
- return handleErrorResponse(resp)
|
|
|
|
}
|
|
}
|
|
|
|
+ return handleErrorResponse(resp)
|
|
}
|
|
}
|
|
|
|
|
|
func (ms *manifests) Delete(dgst digest.Digest) error {
|
|
func (ms *manifests) Delete(dgst digest.Digest) error {
|
|
@@ -353,12 +344,10 @@ func (ms *manifests) Delete(dgst digest.Digest) error {
|
|
}
|
|
}
|
|
defer resp.Body.Close()
|
|
defer resp.Body.Close()
|
|
|
|
|
|
- switch resp.StatusCode {
|
|
|
|
- case http.StatusOK:
|
|
|
|
|
|
+ if SuccessStatus(resp.StatusCode) {
|
|
return nil
|
|
return nil
|
|
- default:
|
|
|
|
- return handleErrorResponse(resp)
|
|
|
|
}
|
|
}
|
|
|
|
+ return handleErrorResponse(resp)
|
|
}
|
|
}
|
|
|
|
|
|
type blobs struct {
|
|
type blobs struct {
|
|
@@ -366,7 +355,8 @@ type blobs struct {
|
|
ub *v2.URLBuilder
|
|
ub *v2.URLBuilder
|
|
client *http.Client
|
|
client *http.Client
|
|
|
|
|
|
- statter distribution.BlobStatter
|
|
|
|
|
|
+ statter distribution.BlobDescriptorService
|
|
|
|
+ distribution.BlobDeleter
|
|
}
|
|
}
|
|
|
|
|
|
func sanitizeLocation(location, source string) (string, error) {
|
|
func sanitizeLocation(location, source string) (string, error) {
|
|
@@ -459,8 +449,7 @@ func (bs *blobs) Create(ctx context.Context) (distribution.BlobWriter, error) {
|
|
}
|
|
}
|
|
defer resp.Body.Close()
|
|
defer resp.Body.Close()
|
|
|
|
|
|
- switch resp.StatusCode {
|
|
|
|
- case http.StatusAccepted:
|
|
|
|
|
|
+ if SuccessStatus(resp.StatusCode) {
|
|
// TODO(dmcgowan): Check for invalid UUID
|
|
// TODO(dmcgowan): Check for invalid UUID
|
|
uuid := resp.Header.Get("Docker-Upload-UUID")
|
|
uuid := resp.Header.Get("Docker-Upload-UUID")
|
|
location, err := sanitizeLocation(resp.Header.Get("Location"), u)
|
|
location, err := sanitizeLocation(resp.Header.Get("Location"), u)
|
|
@@ -475,15 +464,18 @@ func (bs *blobs) Create(ctx context.Context) (distribution.BlobWriter, error) {
|
|
startedAt: time.Now(),
|
|
startedAt: time.Now(),
|
|
location: location,
|
|
location: location,
|
|
}, nil
|
|
}, nil
|
|
- default:
|
|
|
|
- return nil, handleErrorResponse(resp)
|
|
|
|
}
|
|
}
|
|
|
|
+ return nil, handleErrorResponse(resp)
|
|
}
|
|
}
|
|
|
|
|
|
func (bs *blobs) Resume(ctx context.Context, id string) (distribution.BlobWriter, error) {
|
|
func (bs *blobs) Resume(ctx context.Context, id string) (distribution.BlobWriter, error) {
|
|
panic("not implemented")
|
|
panic("not implemented")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (bs *blobs) Delete(ctx context.Context, dgst digest.Digest) error {
|
|
|
|
+ return bs.statter.Clear(ctx, dgst)
|
|
|
|
+}
|
|
|
|
+
|
|
type blobStatter struct {
|
|
type blobStatter struct {
|
|
name string
|
|
name string
|
|
ub *v2.URLBuilder
|
|
ub *v2.URLBuilder
|
|
@@ -502,8 +494,7 @@ func (bs *blobStatter) Stat(ctx context.Context, dgst digest.Digest) (distributi
|
|
}
|
|
}
|
|
defer resp.Body.Close()
|
|
defer resp.Body.Close()
|
|
|
|
|
|
- switch resp.StatusCode {
|
|
|
|
- case http.StatusOK:
|
|
|
|
|
|
+ if SuccessStatus(resp.StatusCode) {
|
|
lengthHeader := resp.Header.Get("Content-Length")
|
|
lengthHeader := resp.Header.Get("Content-Length")
|
|
length, err := strconv.ParseInt(lengthHeader, 10, 64)
|
|
length, err := strconv.ParseInt(lengthHeader, 10, 64)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -515,11 +506,10 @@ func (bs *blobStatter) Stat(ctx context.Context, dgst digest.Digest) (distributi
|
|
Size: length,
|
|
Size: length,
|
|
Digest: dgst,
|
|
Digest: dgst,
|
|
}, nil
|
|
}, nil
|
|
- case http.StatusNotFound:
|
|
|
|
|
|
+ } else if resp.StatusCode == http.StatusNotFound {
|
|
return distribution.Descriptor{}, distribution.ErrBlobUnknown
|
|
return distribution.Descriptor{}, distribution.ErrBlobUnknown
|
|
- default:
|
|
|
|
- return distribution.Descriptor{}, handleErrorResponse(resp)
|
|
|
|
}
|
|
}
|
|
|
|
+ return distribution.Descriptor{}, handleErrorResponse(resp)
|
|
}
|
|
}
|
|
|
|
|
|
func buildCatalogValues(maxEntries int, last string) url.Values {
|
|
func buildCatalogValues(maxEntries int, last string) url.Values {
|
|
@@ -535,3 +525,30 @@ func buildCatalogValues(maxEntries int, last string) url.Values {
|
|
|
|
|
|
return values
|
|
return values
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (bs *blobStatter) Clear(ctx context.Context, dgst digest.Digest) error {
|
|
|
|
+ blobURL, err := bs.ub.BuildBlobURL(bs.name, dgst)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ req, err := http.NewRequest("DELETE", blobURL, nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resp, err := bs.client.Do(req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ defer resp.Body.Close()
|
|
|
|
+
|
|
|
|
+ if SuccessStatus(resp.StatusCode) {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ return handleErrorResponse(resp)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (bs *blobStatter) SetDescriptor(ctx context.Context, dgst digest.Digest, desc distribution.Descriptor) error {
|
|
|
|
+ return nil
|
|
|
|
+}
|