working commit

This commit is contained in:
2026-03-16 20:55:36 +02:00
parent 5c1da77f4c
commit 13b1905e05
31 changed files with 177 additions and 151 deletions
-1
View File
@@ -77,7 +77,6 @@ func (oper *Operator) CreateGrant(ctx context.Context, operatorID string, params
err := fmt.Errorf("Grant with this right already exists")
return res, err
}
oper.logg.Debugf("Call CreateGrant")
now := auxtool.TimeNow()
grantDescr := &descr.Grant{
ID: auxuuid.NewUUID(),
+1 -1
View File
@@ -52,7 +52,7 @@ func NewConfig() *Config {
logfile := fmt.Sprintf("%s.log", srvname)
logpath := filepath.Join(logdir, logfile)
runfile := fmt.Sprintf("%s.run", srvname)
runfile := fmt.Sprintf("%s.pid", srvname)
runpath := filepath.Join(rundir, runfile)
//certpath := fmt.Sprintf("%s.crt", srvname)
+4 -4
View File
@@ -1,10 +1,10 @@
package config
const (
confdir = "/home/ziggi/Projects/mstore/etc/mstore"
rundir = "/home/ziggi/Projects/mstore/tmp/run"
logdir = "/home/ziggi/Projects/mstore/tmp/log"
datadir = "/home/ziggi/Projects/mstore/tmp/data"
confdir = "/etc/mstore"
rundir = "/var/run/mstore"
logdir = "/var/log/mstore"
datadir = "/var/lib/mstore"
version = "0.2.0"
srvname = "mstored"
)
-1
View File
@@ -92,7 +92,6 @@ func (oper *Operator) GetFile(ctx context.Context, operatorID string, params *Ge
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
+1 -1
View File
@@ -54,7 +54,7 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
//hand.logg.Debugf("URL: %s", rctx.URL().String())
authHeader := rctx.GetHeader("Authorization")
hand.logg.Debugf("Authorization: %s", authHeader)
hand.logg.Debugf("Authorization: [%s]", authHeader)
if authHeader != "" {
username, password, err = auxhttp.ParseBasicAuth(authHeader)
if err != nil {
-2
View File
@@ -25,7 +25,6 @@ func (hand *Handler) BlobExists(rctx *router.Context) {
digest, _ := rctx.GetSubpath("digest")
//hand.DumpHeaders("BlobExists", rctx)
params := &imageoper.BlobExistsParams{
Name: name,
Digest: digest,
@@ -63,7 +62,6 @@ func (hand *Handler) PostUpload(rctx *router.Context) {
name, _ := rctx.GetSubpath("name")
//hand.DumpHeaders("PostUploads", rctx)
authorization := rctx.GetHeader("Authorization")
if authorization == "" {
rctx.SetHeader("WWW-Authenticate", `Basic realm="mstore"`)
+1 -2
View File
@@ -24,7 +24,6 @@ type BlobExistsResult struct {
DockerContentDigest string
ContentLength string
ContentType string
//Exists bool
}
func (oper *Operator) BlobExists(ctx context.Context, operatorID string, params *BlobExistsParams) (*BlobExistsResult, int, error) {
@@ -45,7 +44,7 @@ func (oper *Operator) BlobExists(ctx context.Context, operatorID string, params
defer oper.iLock.Done(resName)
// Check blob descriptor
descrExists, blobDescr, err := oper.mdb.GetBlobByNameDigest(ctx, params.Digest, params.Digest)
descrExists, blobDescr, err := oper.mdb.GetBlobByNameDigest(ctx, params.Name, params.Digest)
if err != nil {
return res, http.StatusInternalServerError, err
}
+5 -3
View File
@@ -50,8 +50,8 @@ func (oper *Operator) GetManifest(ctx context.Context, params *GetManifestParams
manDescr := descr.Manifest{}
var exists bool
digobj, err := ocidigest.Parse(params.Reference)
if err == nil {
digobj, parseErr := ocidigest.Parse(params.Reference)
if parseErr == nil {
exists, manDescr, err = oper.mdb.GetManifestByDigest(ctx, params.Name, digobj.String())
if err != nil {
return res, http.StatusInternalServerError, err
@@ -75,6 +75,7 @@ func (oper *Operator) GetManifest(ctx context.Context, params *GetManifestParams
return res, http.StatusNotFound, err
}
if len(manDescrs) == 1 {
manDescr = manDescrs[0]
res.DockerContentDigest = manDescr.Digest
size := int64(len(manDescr.Payload))
res.ContentLength = strconv.FormatInt(size, 10)
@@ -85,8 +86,9 @@ func (oper *Operator) GetManifest(ctx context.Context, params *GetManifestParams
if err != nil {
return res, http.StatusInternalServerError, err
}
digobj := ocidigest.SHA256.FromBytes(indexdata)
digobj := ocidigest.FromBytes(indexdata)
res.DockerContentDigest = digobj.String()
size := int64(len(indexdata))
res.ContentLength = strconv.FormatInt(size, 10)
res.ContentType = oiiMediaType
+3 -4
View File
@@ -15,7 +15,6 @@ import (
"net/http"
"strconv"
//"mstore/pkg/auxoci"
"mstore/pkg/descr"
ocidigest "github.com/opencontainers/go-digest"
@@ -48,8 +47,8 @@ func (oper *Operator) ManifestExists(ctx context.Context, params *ManifestExists
var man descr.Manifest
var exist bool
digobj, err := ocidigest.Parse(params.Reference)
if err == nil {
digobj, parseErr := ocidigest.Parse(params.Reference)
if parseErr == nil {
exist, man, err = oper.mdb.GetManifestByDigest(ctx, params.Name, digobj.String())
if err != nil {
return res, http.StatusInternalServerError, err
@@ -75,7 +74,7 @@ func (oper *Operator) ManifestExists(ctx context.Context, params *ManifestExists
if err != nil {
return res, http.StatusInternalServerError, err
}
digobj := ocidigest.SHA256.FromBytes(indexdata)
digobj := ocidigest.FromBytes(indexdata)
res.DockerContentDigest = digobj.String()
size := int64(len(indexdata))
res.ContentLength = strconv.FormatInt(size, 10)
+10 -1
View File
@@ -19,6 +19,7 @@ import (
"net/http"
"strconv"
ocidigest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
@@ -74,6 +75,14 @@ func (oper *Operator) PutManifest(ctx context.Context, params *PutManifestParams
return res, http.StatusInternalServerError, err
}
inManData := buffer.Bytes()
var digstr string
digobj, parseErr := ocidigest.Parse(params.Reference)
if parseErr == nil {
digstr = digobj.String()
} else {
digobj := ocidigest.FromBytes(inManData)
digstr = digobj.String()
}
if int64(len(inManData)) != contentLength {
err = fmt.Errorf("Mismatch Content-Length and received manifest size: %d vs %d",
contentLength, len(inManData))
@@ -112,6 +121,7 @@ func (oper *Operator) PutManifest(ctx context.Context, params *PutManifestParams
}
inManDescr, inlayerdescrs, err := descrsFromManifest(name, reference, inMan, inManData)
inManDescr.Digest = digstr
// Always check layer files for availability
var blobError error
for _, blobDescr := range inlayerdescrs {
@@ -178,7 +188,6 @@ func (oper *Operator) PutManifest(ctx context.Context, params *PutManifestParams
}
}
}
for _, blobDescr := range inlayerdescrs {
// TODO: move the requests to db layer transaction
blobDescrExists, _, err := oper.mdb.GetBlobByNameDigest(ctx, blobDescr.Name, blobDescr.Digest)
+2 -2
View File
@@ -21,14 +21,14 @@ import (
type Database struct {
datapath string
log *logger.Logger
logg *logger.Logger
db *sqlx.DB
}
func NewDatabase(datapath string) *Database {
return &Database{
datapath: datapath,
log: logger.NewLoggerWithSubject("maindb"),
logg: logger.NewLoggerWithSubject("maindb"),
}
}
+1 -1
View File
@@ -89,7 +89,7 @@ func (srv *Server) SetAsDaemon(asDaemon bool) {
func (srv *Server) Configure() error {
var err error
srv.logg.Infof("Configuration server")
//srv.logg.Infof("Configuration server")
srv.conf = config.NewConfig()
if err != nil {
return err
+2 -2
View File
@@ -70,6 +70,8 @@ func (svc *Service) Build() error {
svc.rout.Use(router.NewCorsMiddleware())
svc.rout.Use(svc.hand.AuthMiddleware)
svc.rout.Head(`/v2/{name}/blobs/{digest}`, svc.hand.BlobExists)
svc.rout.Get(`/v3/api/service/hello`, svc.hand.SendHello)
svc.rout.Head(`/v3/api/file/{filepath}`, svc.hand.FileInfo)
@@ -93,8 +95,6 @@ func (svc *Service) Build() error {
svc.rout.Get(`/v2/{name}/manifests/{reference}`, svc.hand.GetManifest)
svc.rout.Delete(`/v2/{name}/manifests/{reference}`, svc.hand.DeleteManifest)
svc.rout.Head(`/v2/{name}/blobs/{digest}`, svc.hand.BlobExists)
svc.rout.Post(`/v2/{name}/blobs/uploads/`, svc.hand.PostUpload)
svc.rout.Patch(`/v2/{name}/blobs/uploads/{reference}`, svc.hand.PatchUpload)
svc.rout.Put(`/v2/{name}/blobs/uploads/{reference}`, svc.hand.PutUpload)