client rebuilding in progress

This commit is contained in:
2026-03-04 12:27:52 +02:00
parent 2d34ec5634
commit ae9c29de1e
31 changed files with 908 additions and 467 deletions
+2
View File
@@ -52,7 +52,9 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
accountID = terms.AnonymousID
hand.logg.Debugf("URL: %s", rctx.URL().String())
authHeader := rctx.GetHeader("Authorization")
hand.logg.Debugf("Authorization: %s", authHeader)
if authHeader != "" {
username, password, err = auxhttp.ParseBasicAuth(authHeader)
if err != nil {
+3 -2
View File
@@ -57,6 +57,8 @@ func (hand *Handler) BlobExists(rctx *router.Context) {
}
// POST /v2/<name>/blobs/uploads/ 202 404
// POST /v2/<name>/blobs/uploads/?digest=<digest> 201/202 404/400
// POST /v2/<name>/blobs/uploads/?mount=<digest>&from=<other_name> 201 404
func (hand *Handler) PostUpload(rctx *router.Context) {
name, _ := rctx.GetSubpath("name")
@@ -102,8 +104,7 @@ func (hand *Handler) PostUpload(rctx *router.Context) {
rctx.SetStatus(code)
}
// POST /v2/<name>/blobs/uploads/?digest=<digest> 201/202 404/400
// POST /v2/<name>/blobs/uploads/?mount=<digest>&from=<other_name> 201 404
// PATCH /v2/<name>/blobs/uploads/<reference> 202 404/416
func (hand *Handler) PatchUpload(rctx *router.Context) {
+1 -3
View File
@@ -256,9 +256,7 @@ type ListAccountsResult struct {
func (oper *Operator) ListAccounts(ctx context.Context, params *ListAccountsParams) (*ListAccountsResult, error) {
var err error
res := &ListAccountsResult{
Accounts: make([]descr.AccountShort, 0),
}
res := &ListAccountsResult{}
accountDescrs, err := oper.mdb.ReducedListAccounts(ctx)
if err != nil {
+126 -130
View File
@@ -24,7 +24,7 @@ import (
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
"mstore/pkg/terms"
"mstore/pkg/filecli"
)
// FileInfo
@@ -39,11 +39,10 @@ type FileInfoResult struct {
ContentType string
ContentSize string
ContentDigest string
ContentCreatedAt string
ContentCreatedBy string
ContentUpdatedAt string
ContentUpdatedBy string
ContentCreatedAt string
ContentCreatedBy string
ContentUpdatedAt string
ContentUpdatedBy string
}
func cleanFilepath(filename string) (string, error) {
@@ -299,122 +298,10 @@ func (oper *Operator) DeleteFile(ctx context.Context, operatorID string, params
return code, res, err
}
// ListFiles
type ListFilesParams struct {
Filepath string
PathAs string `param:"pathAs"`
}
type ListFilesResult struct {
Files []descr.File `json:"files,omitempty"`
}
func (oper *Operator) ListFiles(ctx context.Context, operatorID string, params *ListFilesParams) (int, *ListFilesResult, error) {
var err error
res := &ListFilesResult{
Files: make([]descr.File, 0),
}
switch params.PathAs {
case terms.AsRegexp:
files, err := oper.listFilesWithRegex(ctx, params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
res.Files = files
case terms.AsPrefix:
params.Filepath, err = cleanFilepath(params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
params.Filepath, err = cleanFilepath(params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
files, err := oper.listFilesWithPrefix(ctx, params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
res.Files = files
default: // Fine
params.Filepath, err = cleanFilepath(params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
params.Filepath, err = cleanFilepath(params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
files, err := oper.listFilesInOneCollection(ctx, params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
res.Files = files
}
code := http.StatusOK
return code, res, err
}
func (oper *Operator) listFilesInOneCollection(ctx context.Context, collection string) ([]descr.File, error) {
var err error
res := make([]descr.File, 0)
files, err := oper.mdb.ListFilesByCollection(ctx, collection)
if err != nil {
return res, err
}
res = files
return res, err
}
func (oper *Operator) listFilesWithPrefix(ctx context.Context, prefix string) ([]descr.File, error) {
var err error
res := make([]descr.File, 0)
files, err := oper.mdb.ListAllFiles(ctx)
if err != nil {
return res, err
}
for _, file := range files {
fullpath := filepath.Join(file.Collection, file.Name)
if strings.HasPrefix(fullpath, prefix) {
res = append(res, file)
}
}
return res, err
}
func (oper *Operator) listFilesWithRegex(ctx context.Context, regex string) ([]descr.File, error) {
var err error
res := make([]descr.File, 0)
re, err := regexp.Compile(regex)
if err != nil {
return res, err
}
files, err := oper.mdb.ListAllFiles(ctx)
if err != nil {
return res, err
}
for _, file := range files {
fullpath := filepath.Join(file.Collection, file.Name)
if re.MatchString(fullpath) {
res = append(res, file)
}
}
return res, err
}
// ListCollections
type ListCollectionsParams struct {
Path string
PathAS string `param:"pathAs"`
Path string
PathType string `param:"pathType"`
}
type ListCollectionsResult struct {
Collections []string `json:"collection,omitempty"`
@@ -427,14 +314,14 @@ func (oper *Operator) ListCollections(ctx context.Context, operatorID string, pa
}
collectionList := make([]string, 0)
switch param.PathAS {
case terms.AsRegexp:
switch param.PathType {
case filecli.PathTypeRegexp:
collectionList, err = oper.listCollectionsWithRegexp(ctx, param.Path)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
case terms.AsPrefix:
case filecli.PathTypePrefix:
param.Path, err = cleanFilepath(param.Path)
if err != nil {
code := http.StatusInternalServerError
@@ -545,9 +432,9 @@ func (oper *Operator) listAllCollections(ctx context.Context) ([]string, error)
// DeleteColletion
type DeleteColletionParams struct {
Path string
PathAs string `param:"pathAs"`
DryRun bool `param:"dryRun"`
Path string
PathType string `param:"pathType"`
DryRun bool `param:"dryRun"`
}
type DeleteColletionResult struct {
Files []descr.File `json:"files,omitempty"`
@@ -558,8 +445,8 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operatorID string, pa
res := &DeleteColletionResult{
Files: make([]descr.File, 0),
}
switch param.PathAs {
case terms.AsRegexp:
switch param.PathType {
case filecli.PathTypeRegexp:
collections, err := oper.listCollectionsWithRegexp(ctx, param.Path)
if err != nil {
code := http.StatusInternalServerError
@@ -576,7 +463,7 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operatorID string, pa
}
res.Files = allfiles
case terms.AsPrefix:
case filecli.PathTypePrefix:
param.Path, err = cleanFilepath(param.Path)
if err != nil {
code := http.StatusInternalServerError
@@ -598,7 +485,7 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operatorID string, pa
allfiles = append(allfiles, files...)
}
res.Files = allfiles
default: // Fine
default:
param.Path, err = cleanFilepath(param.Path)
if err != nil {
code := http.StatusInternalServerError
@@ -641,3 +528,112 @@ func (oper *Operator) deleteFilesInCollection(ctx context.Context, collection st
}
return res, err
}
// ListFiles
type ListFilesParams struct {
Filepath string
PathType string `param:"pathType"`
}
type ListFilesResult struct {
Files []descr.File `json:"files,omitempty"`
}
func (oper *Operator) ListFiles(ctx context.Context, operatorID string, params *ListFilesParams) (int, *ListFilesResult, error) {
var err error
res := &ListFilesResult{}
switch params.PathType {
case filecli.PathTypeRegexp:
files, err := oper.listFilesWithRegex(ctx, params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
res.Files = files
case filecli.PathTypePrefix:
params.Filepath, err = cleanFilepath(params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
params.Filepath, err = cleanFilepath(params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
files, err := oper.listFilesWithPrefix(ctx, params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
res.Files = files
default:
params.Filepath, err = cleanFilepath(params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
params.Filepath, err = cleanFilepath(params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
files, err := oper.listFilesInCollection(ctx, params.Filepath)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
res.Files = files
}
code := http.StatusOK
return code, res, err
}
func (oper *Operator) listFilesInCollection(ctx context.Context, collection string) ([]descr.File, error) {
var err error
res := make([]descr.File, 0)
files, err := oper.mdb.ListFilesByCollection(ctx, collection)
if err != nil {
return res, err
}
res = files
return res, err
}
func (oper *Operator) listFilesWithPrefix(ctx context.Context, prefix string) ([]descr.File, error) {
var err error
res := make([]descr.File, 0)
files, err := oper.mdb.ListAllFiles(ctx)
if err != nil {
return res, err
}
for _, file := range files {
fullpath := filepath.Join(file.Collection, file.Name)
if strings.HasPrefix(fullpath, prefix) {
res = append(res, file)
}
}
return res, err
}
func (oper *Operator) listFilesWithRegex(ctx context.Context, regex string) ([]descr.File, error) {
var err error
res := make([]descr.File, 0)
re, err := regexp.Compile(regex)
if err != nil {
return res, err
}
files, err := oper.mdb.ListAllFiles(ctx)
if err != nil {
return res, err
}
for _, file := range files {
fullpath := filepath.Join(file.Collection, file.Name)
if re.MatchString(fullpath) {
res = append(res, file)
}
}
return res, err
}
+19 -9
View File
@@ -321,17 +321,27 @@ func (oper *Operator) GetManifest(ctx context.Context, params *GetManifestParams
if !exists {
return res, http.StatusNotFound, err
}
/*
index, indexBytes, err := indexFromManigestDescrs(manifestDescrs)
if err != nil {
return res, http.StatusInternalServerError, err
}
indexDigest := auxoci.SHA256DigestFromString(indexBytes)
res.DockerContentDigest = indexDigest.String()
index, indexBytes, err := indexFromManigestDescrs(manifestDescrs)
if err != nil {
return res, http.StatusInternalServerError, err
}
indexDigest := auxoci.SHA256DigestFromString(indexBytes)
res.DockerContentDigest = indexDigest.String()
res.ContentLength = strconv.FormatInt(int64(len(indexBytes)), 10)
res.ContentType = index.MediaType
res.Payload = string(indexBytes)
*/
manifestDescr = manifestDescrs[0]
manifestDigest := auxoci.SHA256DigestFromString(manifestDescr.Payload)
res.DockerContentDigest = manifestDigest.String()
res.ContentLength = strconv.FormatInt(int64(len(manifestDescr.Payload)), 10)
res.ContentType = manifestDescr.ContentType
res.Payload = manifestDescr.Payload
res.ContentLength = strconv.FormatInt(int64(len(indexBytes)), 10)
res.ContentType = index.MediaType
res.Payload = string(indexBytes)
}
return res, http.StatusOK, err
}
+6 -3
View File
@@ -15,6 +15,7 @@ import (
"encoding/json"
"io"
"net/http"
"net/url"
"strconv"
)
@@ -29,11 +30,10 @@ type Context struct {
}
func NewContext(writer http.ResponseWriter, request *http.Request) *Context {
ctx := context.Background()
rctx := &Context{
Writer: writer,
Request: request,
Ctx: ctx,
Ctx: request.Context(),
PathMap: make(map[string]string),
Bools: make(map[string]bool),
Strings: make(map[string]string),
@@ -66,6 +66,10 @@ func (rctx *Context) GetSubpath(key string) (string, bool) {
return value, exists
}
func (rctx *Context) URL() *url.URL {
return rctx.Request.URL
}
func (rctx *Context) GetQuery(key string) string {
return rctx.Request.URL.Query().Get(key)
}
@@ -83,7 +87,6 @@ func (rctx *Context) GetContext() context.Context {
}
// Binding
const emptyJSON = "{}"
func (rctx *Context) BindJSON(obj any) error {