working commit

This commit is contained in:
2026-03-13 19:02:42 +02:00
parent bebbf79c7a
commit 5c1da77f4c
1329 changed files with 314708 additions and 39 deletions
+6
View File
@@ -0,0 +1,6 @@
package fileoper
const (
defaultContentType = "application/octet-stream"
hcMediaType = "application/vnd.cncf.helm.chart.content.v1.tar+gzip"
)
+38 -5
View File
@@ -12,10 +12,18 @@ package fileoper
import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"path"
"strconv"
"mstore/pkg/auxtool"
"mstore/pkg/terms"
yaml "go.yaml.in/yaml/v4"
chart "helm.sh/helm/v4/pkg/chart/v2"
repo "helm.sh/helm/v4/pkg/repo/v1"
)
// GetFile
@@ -79,12 +87,37 @@ func (oper *Operator) GetFile(ctx context.Context, operatorID string, params *Ge
code := http.StatusOK
return code, res, err
}
// TODO: actual chart index
reader := io.NopCloser(bytes.NewReader(nil))
fileDescrs, err := oper.mdb.ListFilesByCollection(ctx, collection)
index := repo.NewIndexFile()
for _, descr := range fileDescrs {
if descr.Type == hcMediaType {
meta := &chart.Metadata{}
oper.logg.Debugf("=== %s", descr.HelmMeta)
err = json.Unmarshal([]byte(descr.HelmMeta), meta)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
index.MustAdd(meta, descr.Name, "aaa", descr.HelmHash)
}
}
indexdata, err := yaml.Marshal(index)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
reader := io.NopCloser(bytes.NewReader(indexdata))
now := auxtool.TimeNow()
size := int64(len(indexdata))
res = &GetFileResult{
ContentSize: strconv.FormatInt(0, 10),
ContentType: hcMimeType,
Source: reader,
ContentSize: strconv.FormatInt(size, 10),
ContentType: "application/yaml",
Source: reader,
ContentCreatedAt: now,
ContentCreatedBy: terms.ServerID,
ContentUpdatedAt: now,
ContentUpdatedBy: terms.ServerID,
}
code := http.StatusOK
return code, res, err
+2 -7
View File
@@ -31,11 +31,6 @@ type PutFileParams struct {
}
type PutFileResult struct{}
const (
defaultContentType = "application/octet-stream"
hcMimeType = "application/vnd.cncf.helm.chart.content.v1.tar+gzip"
)
// TODO: checking catalog and file names conflict
func (oper *Operator) PutFile(ctx context.Context, operatorID string, params *PutFileParams) (int, *PutFileResult, error) {
var err error
@@ -76,8 +71,8 @@ func (oper *Operator) PutFile(ctx context.Context, operatorID string, params *Pu
}
var helmHash string
var helmMeta string
if contentType == hcMimeType {
helmHash, helmMeta, err = oper.store.HelmMeta(tmpname)
if contentType == hcMediaType {
helmMeta, helmHash, err = oper.store.HelmMeta(tmpname)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
+18 -10
View File
@@ -66,7 +66,7 @@ func (oper *Operator) GetManifest(ctx context.Context, params *GetManifestParams
res.Payload = manDescr.Payload
} else {
// Create index of manifests
// Create index of manifests. Or not.
exists, manDescrs, err := oper.mdb.GetManifestsByReference(ctx, params.Name, params.Reference)
if err != nil {
return res, http.StatusInternalServerError, err
@@ -74,16 +74,24 @@ func (oper *Operator) GetManifest(ctx context.Context, params *GetManifestParams
if !exists {
return res, http.StatusNotFound, err
}
_, indexdata, err := indexFromManigestDescrs(manDescrs)
if err != nil {
return res, http.StatusInternalServerError, err
if len(manDescrs) == 1 {
res.DockerContentDigest = manDescr.Digest
size := int64(len(manDescr.Payload))
res.ContentLength = strconv.FormatInt(size, 10)
res.ContentType = manDescr.ContentType
res.Payload = manDescr.Payload
} else {
_, indexdata, err := indexFromManigestDescrs(manDescrs)
if err != nil {
return res, http.StatusInternalServerError, err
}
digobj := ocidigest.SHA256.FromBytes(indexdata)
res.DockerContentDigest = digobj.String()
size := int64(len(indexdata))
res.ContentLength = strconv.FormatInt(size, 10)
res.ContentType = oiiMediaType
res.Payload = string(indexdata)
}
digobj := ocidigest.SHA256.FromBytes(indexdata)
res.DockerContentDigest = digobj.String()
size := int64(len(indexdata))
res.ContentLength = strconv.FormatInt(size, 10)
res.ContentType = oiiMediaType
res.Payload = string(indexdata)
}
return res, http.StatusOK, err
}