working commit

This commit is contained in:
2026-02-04 22:55:48 +02:00
parent 3900d93559
commit afeab061e9
6 changed files with 117 additions and 65 deletions
+12 -1
View File
@@ -104,6 +104,7 @@ type PatchUploadParams struct {
}
type PatchUploadResult struct {
Location string
Range string
}
// The response for each successful chunk upload MUST be 202 Accepted, and MUST have the following headers:
@@ -125,6 +126,16 @@ func (oper *Operator) PatchUpload(ctx context.Context, params *PatchUploadParams
return res, http.StatusBadRequest, err
}
exists, uploadSize, err := oper.store.UploadExists(params.Name, params.Reference)
if err != nil {
return res, http.StatusInternalServerError, err
}
if exists {
res.Location = fmt.Sprintf("/v2/%s/uploads/%s", params.Name, params.Reference)
res.Range = fmt.Sprintf("0-%d", uploadSize-1)
return res, http.StatusNoContent, err
}
if params.ContentType != "application/octet-stream" {
err = fmt.Errorf("Wrong Conten-Type header: %s", params.ContentType)
return res, http.StatusBadRequest, err
@@ -150,7 +161,7 @@ func (oper *Operator) PatchUpload(ctx context.Context, params *PatchUploadParams
return res, http.StatusInternalServerError, err
}
res.Location = fmt.Sprintf("/v2/%s/uploads/%s", params.Name, params.Reference)
res.Range = fmt.Sprintf("0-%d", recsize-1)
return res, http.StatusAccepted, err
}
+25 -8
View File
@@ -80,10 +80,11 @@ func (oper *Operator) ManifestExists(ctx context.Context, params *ManifestExists
}
type PutManifestParams struct {
ContentType string
Name string
Reference string
Reader io.Reader
ContentType string
ContentLength string
Name string
Reference string
Reader io.Reader
}
type PutManifestResult struct {
Location string
@@ -109,6 +110,17 @@ func (oper *Operator) PutManifest(ctx context.Context, params *PutManifestParams
err = fmt.Errorf("Unknown or empty Content-Type: %s", params.ContentType)
return res, http.StatusNotFound, err
}
if params.ContentLength == "" {
code := http.StatusLengthRequired
err = fmt.Errorf("Content-Length is empty")
return res, code, err
}
contentLength, err := strconv.ParseInt(params.ContentLength, 10, 64)
if err != nil {
err = fmt.Errorf("Cannot parse Content-Length value [%s]: %v", params.ContentLength, err)
code := http.StatusLengthRequired
return res, code, err
}
// Copy manifest data
buffer := bytes.NewBuffer(nil)
@@ -117,6 +129,13 @@ func (oper *Operator) PutManifest(ctx context.Context, params *PutManifestParams
return res, http.StatusInternalServerError, err
}
incomingManifestBytes := buffer.Bytes()
if int64(len(incomingManifestBytes)) != contentLength {
err = fmt.Errorf("Mismatch Content-Length and received manifest size: %d vs %d",
contentLength, len(incomingManifestBytes))
code := http.StatusInternalServerError
return res, code, err
}
oper.logg.Debugf("Manifest data: [%s]", string(incomingManifestBytes))
incomingManifest, err := auxoci.ParseOCIManifest(incomingManifestBytes)
@@ -124,10 +143,8 @@ func (oper *Operator) PutManifest(ctx context.Context, params *PutManifestParams
err = fmt.Errorf("Parsing OCI manifest error: %v", err)
return res, http.StatusInternalServerError, err
}
if incomingManifest.MediaType != params.ContentType {
err := fmt.Errorf("Mismatch Content-Type header and manifest MediaType: %s vs %s",
params.ContentType, incomingManifest.MediaType)
return res, http.StatusInternalServerError, err
if incomingManifest.MediaType == "" {
incomingManifest.MediaType = params.ContentType
}
manifestExists, _, err := oper.mdb.GetManifestByReference(ctx, params.Name, params.Reference)