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
+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)