working commit
This commit is contained in:
+72
-10
@@ -128,26 +128,88 @@ func (oper *Operator) PatchUpload(ctx context.Context, params *PatchUploadParams
|
||||
err = fmt.Errorf("Wrong Conten-Type header: %s", params.ContentType)
|
||||
return res, http.StatusBadRequest, err
|
||||
}
|
||||
if params.ContentLength == "" {
|
||||
err = fmt.Errorf("Empty Content-length header")
|
||||
return res, http.StatusBadRequest, err
|
||||
}
|
||||
contentLength, err := strconv.ParseInt(params.ContentLength, 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Wrong Content-length header")
|
||||
return res, http.StatusBadRequest, err
|
||||
var contentLength int64
|
||||
// podman & github.com/containers/image don't set Content-length header for docker transport
|
||||
if params.ContentLength != "" {
|
||||
contentLength, err = strconv.ParseInt(params.ContentLength, 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Wrong Content-length header")
|
||||
return res, http.StatusBadRequest, err
|
||||
}
|
||||
}
|
||||
|
||||
recsize, err := oper.store.WriteUpload(params.Reference, params.Reader)
|
||||
if err != nil {
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
if recsize != contentLength {
|
||||
if contentLength != 0 && recsize != contentLength {
|
||||
oper.store.RemoveUpload(params.Reference)
|
||||
err = fmt.Errorf("Mismatch upload recorded size and content length")
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
res.Location = fmt.Sprintf("/v2/%s/uploads/%s", params.Name, params.Reference)
|
||||
|
||||
return res, http.StatusAccepted, err // http.StatusCreated
|
||||
return res, http.StatusAccepted, err
|
||||
}
|
||||
|
||||
type PutUploadParams struct {
|
||||
ContentType string
|
||||
ContentLength string
|
||||
ContentRange string
|
||||
Name string
|
||||
Reference string
|
||||
Digest string
|
||||
Reader io.Reader
|
||||
}
|
||||
type PutUploadResult struct {
|
||||
Location string
|
||||
}
|
||||
|
||||
func (oper *Operator) PutUpload(ctx context.Context, params *PutUploadParams) (*PutUploadResult, int, error) {
|
||||
var err error
|
||||
res := &PutUploadResult{}
|
||||
oper.logg.Debugf("Call PutUpload")
|
||||
|
||||
if params.Reference == "" {
|
||||
err = fmt.Errorf("Empty reference")
|
||||
return res, http.StatusBadRequest, err
|
||||
}
|
||||
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
|
||||
}
|
||||
if params.ContentType != "application/octet-stream" {
|
||||
err = fmt.Errorf("Wrong conten type: %s", params.ContentType)
|
||||
return res, http.StatusBadRequest, err
|
||||
}
|
||||
|
||||
var contentLength int64
|
||||
if params.ContentLength != "" {
|
||||
contentLength, err = strconv.ParseInt(params.ContentLength, 10, 64)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Cannot convert Content-Length=%s to integer: %v", params.ContentLength, err)
|
||||
return res, http.StatusBadRequest, err
|
||||
}
|
||||
|
||||
}
|
||||
if contentLength != 0 {
|
||||
// TODO
|
||||
err = fmt.Errorf("Unexpected Content-Length header: %s", params.ContentLength)
|
||||
return res, http.StatusInternalServerError, err
|
||||
|
||||
Content - Range
|
||||
}
|
||||
|
||||
err = oper.store.LinkUpload(params.Reference, params.Digest)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Failed to link upload %s, err: %v", params.Reference, err)
|
||||
return res, http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
res.Location = fmt.Sprintf("/v2/%s/blobs/%s", params.Name, params.Digest)
|
||||
return res, http.StatusCreated, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user