working commit

This commit is contained in:
2026-02-23 00:07:38 +02:00
parent 685880c8a8
commit b6efc19f7a
41 changed files with 11938 additions and 93 deletions
+23
View File
@@ -216,3 +216,26 @@ func (hand *Handler) GetTags(rctx *router.Context) {
}
rctx.SendJSON(code, res.TagDescr)
}
// GET /v2/_catalog?n=1000 200 404
func (hand *Handler) ListManifests(rctx *router.Context) {
params := &operator.ListManifestsParams{}
// Rigth checking
operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "_catalog")
if err != nil {
rctx.SetStatus(http.StatusInternalServerError)
return
}
if !opEnable {
rctx.SetStatus(http.StatusMethodNotAllowed)
return
}
// Execution of the operation
ctx := rctx.GetContext()
res, code, err := hand.oper.ListManifests(ctx, params)
if err != nil {
hand.logg.Errorf("ListManifests error: %v", err)
}
rctx.SendJSON(code, res)
}
+31
View File
@@ -16,6 +16,7 @@ import (
"fmt"
"io"
"net/http"
"slices"
"strconv"
"mstore/pkg/auxoci"
@@ -470,3 +471,33 @@ func (oper *Operator) GetReferer(ctx context.Context, params *GetRefererParams)
res.Reference = manifests[0].Reference
return res, http.StatusOK, err
}
type ListManifestsParams struct {
N int64
}
type ListManifestsResult struct {
Catalog []string `json:"repositories"`
}
func (oper *Operator) ListManifests(ctx context.Context, params *ListManifestsParams) (*ListManifestsResult, int, error) {
var err error
res := &ListManifestsResult{
Catalog: make([]string, 0),
}
refMap := make(map[string]bool)
descrs, err := oper.mdb.ListAllManifests(ctx)
if err != nil {
return res, http.StatusInternalServerError, err
}
for _, descr := range descrs {
_, yet := refMap[descr.Reference]
if !yet {
refMap[descr.Reference] = true
}
}
for key, _ := range refMap {
res.Catalog = append(res.Catalog, key)
}
slices.Sort(res.Catalog)
return res, http.StatusOK, err
}
+3 -1
View File
@@ -124,7 +124,7 @@ func (rctx *Context) SetStatus(httpStatus int) {
}
func (rctx *Context) SendJSON(statusCode int, payload any) {
rctx.StatusCode = statusCode
buffer := bytes.NewBuffer(nil)
json.NewEncoder(buffer).Encode(payload)
rctx.Writer.Header().Set("Content-Type", "application/json")
@@ -135,6 +135,7 @@ func (rctx *Context) SendJSON(statusCode int, payload any) {
}
func (rctx *Context) SendText(statusCode int, payload string) {
rctx.StatusCode = statusCode
size := strconv.FormatInt(int64(len(payload)), 10)
rctx.Writer.Header().Set("Content-Type", "text/plain")
rctx.Writer.Header().Set("Content-Length", size)
@@ -143,6 +144,7 @@ func (rctx *Context) SendText(statusCode int, payload string) {
}
func (rctx *Context) SendBytes(statusCode int, ctype string, payload []byte) {
rctx.StatusCode = statusCode
size := strconv.FormatInt(int64(len(payload)), 10)
rctx.Writer.Header().Set("Content-Type", ctype)
rctx.Writer.Header().Set("Content-Length", size)
+3 -2
View File
@@ -30,7 +30,8 @@ func newLoggingHandler(next Handler, print func(string, ...any)) *loggingHandler
func (logging loggingHandler) ServeHTTP(rctx *Context) {
logging.next.ServeHTTP(rctx)
logging.printFunc("%s %s %s %s %d", rctx.Request.RemoteAddr,
cl := rctx.Writer.Header().Get("Content-Length")
logging.printFunc("%s %s %s %s %s %d", rctx.Request.RemoteAddr,
rctx.Request.Method, rctx.Request.URL.String(),
rctx.Request.Proto, rctx.StatusCode)
rctx.Request.Proto, cl, rctx.StatusCode)
}
+1
View File
@@ -104,6 +104,7 @@ func (svc *Service) Build() error {
svc.rout.Get(`/v2/{name}/tags/list`, svc.hand.GetTags)
svc.rout.Get(`/v2/{name}/referrers/{digest}`, svc.hand.GetReferer)
svc.rout.Get(`/v2/_catalog`, svc.hand.ListManifests)
svc.rout.Post(`/v3/api/account/create`, svc.hand.CreateAccount)
svc.rout.Post(`/v3/api/account/get`, svc.hand.GetAccount)