working commit
This commit is contained in:
@@ -24,6 +24,7 @@ func (oper *Operator) BlobExists(ctx context.Context, params *BlobExistsParams)
|
||||
var err error
|
||||
res := &BlobExistsResult{}
|
||||
oper.logg.Debugf("Call BlobExists")
|
||||
|
||||
if params.Digest == "" {
|
||||
err = fmt.Errorf("Empty reference")
|
||||
return res, http.StatusBadRequest, err
|
||||
@@ -224,3 +225,90 @@ func (oper *Operator) PutUpload(ctx context.Context, params *PutUploadParams) (*
|
||||
res.Location = fmt.Sprintf("/v2/%s/blobs/%s", params.Name, params.Digest)
|
||||
return res, http.StatusCreated, err
|
||||
}
|
||||
|
||||
type GetBlobParams struct {
|
||||
Name string
|
||||
Digest string
|
||||
}
|
||||
type GetBlobResult struct {
|
||||
ContentLength string
|
||||
ContentType string
|
||||
DockerContentDigest string
|
||||
ReadCloser io.ReadCloser
|
||||
}
|
||||
|
||||
func (oper *Operator) GetBlob(ctx context.Context, params *GetBlobParams) (*GetBlobResult, int, error) {
|
||||
var err error
|
||||
res := &GetBlobResult{}
|
||||
oper.logg.Debugf("Calling GetBlob %s:%s", params.Name, params.Digest)
|
||||
|
||||
if params.Name == "" {
|
||||
err = fmt.Errorf("Empty name")
|
||||
return res, http.StatusBadRequest, err
|
||||
}
|
||||
if params.Digest == "" {
|
||||
err = fmt.Errorf("Empty digest")
|
||||
return res, http.StatusBadRequest, err
|
||||
}
|
||||
|
||||
blobExists, blobSize, err := oper.store.BlobExists(params.Digest)
|
||||
if err != nil {
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
if !blobExists {
|
||||
oper.logg.Debugf("Blob %s:%s not exists", params.Name, params.Digest)
|
||||
return res, http.StatusNotFound, err
|
||||
}
|
||||
|
||||
_, readCloser, err := oper.store.BlobReader(params.Digest)
|
||||
if err != nil {
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
res.ContentLength = strconv.FormatInt(blobSize, 10)
|
||||
res.DockerContentDigest = params.Digest
|
||||
res.ReadCloser = readCloser
|
||||
return res, http.StatusOK, err
|
||||
}
|
||||
|
||||
type DeleteBlobParams struct {
|
||||
Name string
|
||||
Digest string
|
||||
}
|
||||
type DeleteBlobResult struct{}
|
||||
|
||||
func (oper *Operator) DeleteBlob(ctx context.Context, params *DeleteBlobParams) (*DeleteBlobResult, int, error) {
|
||||
var err error
|
||||
res := &DeleteBlobResult{}
|
||||
oper.logg.Debugf("DeleteBlob")
|
||||
|
||||
if params.Digest == "" {
|
||||
err = fmt.Errorf("Empty digest")
|
||||
return res, http.StatusBadRequest, err
|
||||
}
|
||||
if params.Name == "" {
|
||||
err = fmt.Errorf("Empty name")
|
||||
return res, http.StatusBadRequest, err
|
||||
}
|
||||
// Check namespace record
|
||||
exists, _, err := oper.mdb.GetBlobByNameDigest(ctx, params.Name, params.Digest)
|
||||
if err != nil {
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
if !exists {
|
||||
return res, http.StatusNotFound, err
|
||||
}
|
||||
err = oper.mdb.DeleteBlobByNameDigest(ctx, params.Name, params.Digest)
|
||||
if err != nil {
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
// Removing blob file if usage == 0
|
||||
blobUsage, err := oper.mdb.GetBlobUsage(ctx, params.Digest)
|
||||
if err != nil {
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
if blobUsage == 0 {
|
||||
oper.store.DeleteBlob(params.Digest)
|
||||
}
|
||||
return res, http.StatusOK, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user