working commit

This commit is contained in:
2026-02-19 11:55:17 +02:00
parent 1fd55521de
commit bb0f58f46c
37 changed files with 231 additions and 150 deletions
+7 -7
View File
@@ -29,13 +29,13 @@ EXTRA_mstored_SOURCES = \
app/config/config.go \ app/config/config.go \
app/config/variant.go \ app/config/variant.go \
\ \
app/descr/account.go \ pkg/descr/account.go \
app/descr/blob.go \ pkg/descr/blob.go \
app/descr/file.go \ pkg/descr/file.go \
app/descr/grant.go \ pkg/descr/grant.go \
app/descr/manifest.go \ pkg/descr/manifest.go \
app/descr/response.go \ pkg/descr/response.go \
app/descr/server.go \ pkg/descr/server.go \
\ \
app/handler/aaafunc.go \ app/handler/aaafunc.go \
app/handler/account.go \ app/handler/account.go \
+7 -7
View File
@@ -324,13 +324,13 @@ EXTRA_mstored_SOURCES = \
app/config/config.go \ app/config/config.go \
app/config/variant.go \ app/config/variant.go \
\ \
app/descr/account.go \ pkg/descr/account.go \
app/descr/blob.go \ pkg/descr/blob.go \
app/descr/file.go \ pkg/descr/file.go \
app/descr/grant.go \ pkg/descr/grant.go \
app/descr/manifest.go \ pkg/descr/manifest.go \
app/descr/response.go \ pkg/descr/response.go \
app/descr/server.go \ pkg/descr/server.go \
\ \
app/handler/aaafunc.go \ app/handler/aaafunc.go \
app/handler/account.go \ app/handler/account.go \
+4 -4
View File
@@ -14,10 +14,10 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"mstore/app/descr"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/auxhttp" "mstore/pkg/auxhttp"
"mstore/pkg/auxpwd" "mstore/pkg/auxpwd"
"mstore/pkg/terms"
) )
const ( const (
@@ -53,7 +53,7 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
var password string var password string
var accountID string var accountID string
accountID = descr.AnonymousID accountID = terms.AnonymousID
authHeader := rctx.GetHeader("Authorization") authHeader := rctx.GetHeader("Authorization")
if authHeader != "" { if authHeader != "" {
@@ -80,7 +80,7 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
} }
anonymous: anonymous:
success = true success = true
accountID = descr.AnonymousID accountID = terms.AnonymousID
return success, accountID, err return success, accountID, err
} }
@@ -125,7 +125,7 @@ func (hand *Handler) CheckRight(ctx context.Context, accountID, reqRight, subjec
return res, err return res, err
} }
switch reqRight { switch reqRight {
case descr.RightReadFiles, descr.RightWriteFiles: case terms.RightReadFiles, terms.RightWriteFiles:
for _, grant := range grants { for _, grant := range grants {
re, err := regexp.Compile(grant.Pattern) re, err := regexp.Compile(grant.Pattern)
if err != nil { if err != nil {
+6 -6
View File
@@ -12,9 +12,9 @@ package handler
import ( import (
"fmt" "fmt"
"mstore/app/descr"
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/terms"
) )
// POST /v3/account/create 200 200 // POST /v3/account/create 200 200
@@ -29,7 +29,7 @@ func (hand *Handler) CreateAccount(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -62,7 +62,7 @@ func (hand *Handler) GetAccount(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -95,7 +95,7 @@ func (hand *Handler) ListAccounts(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -128,7 +128,7 @@ func (hand *Handler) UpdateAccount(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -161,7 +161,7 @@ func (hand *Handler) DeleteAccount(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, params.Username) opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, params.Username)
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
+7 -7
View File
@@ -14,9 +14,9 @@ import (
"io" "io"
"net/http" "net/http"
"mstore/app/descr"
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/terms"
) )
// HEAD /v2/<name>/blobs/<digest> 200 404 // HEAD /v2/<name>/blobs/<digest> 200 404
@@ -32,7 +32,7 @@ func (hand *Handler) BlobExists(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -72,7 +72,7 @@ func (hand *Handler) PostUpload(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -117,7 +117,7 @@ func (hand *Handler) PatchUpload(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -161,7 +161,7 @@ func (hand *Handler) PutUpload(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -191,7 +191,7 @@ func (hand *Handler) GetBlob(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -237,7 +237,7 @@ func (hand *Handler) DeleteBlob(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
+8 -8
View File
@@ -13,9 +13,9 @@ import (
"io" "io"
"net/http" "net/http"
"mstore/app/descr"
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/terms"
) )
const zeroContentLength = "0" const zeroContentLength = "0"
@@ -28,7 +28,7 @@ func (hand *Handler) FileInfo(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -73,7 +73,7 @@ func (hand *Handler) PutFile(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -101,7 +101,7 @@ func (hand *Handler) GetFile(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -149,7 +149,7 @@ func (hand *Handler) DeleteFile(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -179,7 +179,7 @@ func (hand *Handler) ListFiles(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -210,7 +210,7 @@ func (hand *Handler) ListCollections(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -248,7 +248,7 @@ func (hand *Handler) DeleteCollection(rctx *router.Context) {
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadFiles, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadFiles, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
+6 -6
View File
@@ -12,9 +12,9 @@ package handler
import ( import (
"fmt" "fmt"
"mstore/app/descr"
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/terms"
) )
// POST /v3/grant/create 200 200 // POST /v3/grant/create 200 200
@@ -29,7 +29,7 @@ func (hand *Handler) CreateGrant(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -62,7 +62,7 @@ func (hand *Handler) GetGrant(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -95,7 +95,7 @@ func (hand *Handler) ListGrants(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -128,7 +128,7 @@ func (hand *Handler) UpdateGrant(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
@@ -161,7 +161,7 @@ func (hand *Handler) DeleteGrant(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteAccounts, "")
if err != nil { if err != nil {
err := fmt.Errorf("Operation error: %v", err) err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err) hand.SendError(rctx, err)
+7 -7
View File
@@ -12,9 +12,9 @@ package handler
import ( import (
"net/http" "net/http"
"mstore/app/descr"
"mstore/app/operator" "mstore/app/operator"
"mstore/app/router" "mstore/app/router"
"mstore/pkg/terms"
) )
func (hand *Handler) ManifestExists(rctx *router.Context) { func (hand *Handler) ManifestExists(rctx *router.Context) {
@@ -29,7 +29,7 @@ func (hand *Handler) ManifestExists(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -71,7 +71,7 @@ func (hand *Handler) PutManifest(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -104,7 +104,7 @@ func (hand *Handler) GetManifest(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -144,7 +144,7 @@ func (hand *Handler) DeleteManifest(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightWriteImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -173,7 +173,7 @@ func (hand *Handler) GetReferer(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
@@ -199,7 +199,7 @@ func (hand *Handler) GetTags(rctx *router.Context) {
} }
// Rigth checking // Rigth checking
operatorID, _ := rctx.GetString(userTag) operatorID, _ := rctx.GetString(userTag)
opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightReadImages, "") opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, terms.RightReadImages, "")
if err != nil { if err != nil {
rctx.SetStatus(http.StatusInternalServerError) rctx.SetStatus(http.StatusInternalServerError)
return return
+1 -1
View File
@@ -3,7 +3,7 @@ package maindb
import ( import (
"context" "context"
"mstore/app/descr" "mstore/pkg/descr"
) )
func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) error { func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) error {
+1 -1
View File
@@ -12,7 +12,7 @@ package maindb
import ( import (
"context" "context"
"mstore/app/descr" "mstore/pkg/descr"
) )
func (db *Database) InsertBlob(ctx context.Context, layer *descr.Blob) error { func (db *Database) InsertBlob(ctx context.Context, layer *descr.Blob) error {
+1 -1
View File
@@ -12,7 +12,7 @@ package maindb
import ( import (
"context" "context"
"mstore/app/descr" "mstore/pkg/descr"
) )
func (db *Database) InsertFile(ctx context.Context, file *descr.File) error { func (db *Database) InsertFile(ctx context.Context, file *descr.File) error {
+1 -1
View File
@@ -14,9 +14,9 @@ import (
"testing" "testing"
"time" "time"
"mstore/app/descr"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid" "mstore/pkg/auxuuid"
"mstore/pkg/descr"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
+1 -1
View File
@@ -12,7 +12,7 @@ package maindb
import ( import (
"context" "context"
"mstore/app/descr" "mstore/pkg/descr"
) )
func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error { func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
+1 -1
View File
@@ -14,9 +14,9 @@ import (
"testing" "testing"
"time" "time"
"mstore/app/descr"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid" "mstore/pkg/auxuuid"
"mstore/pkg/descr"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
+35 -34
View File
@@ -13,10 +13,11 @@ package maindb
import ( import (
"context" "context"
"mstore/app/descr"
"mstore/pkg/auxpwd" "mstore/pkg/auxpwd"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid" "mstore/pkg/auxuuid"
"mstore/pkg/descr"
"mstore/pkg/terms"
) )
func (db *Database) WriteAnonymous(ctx context.Context) error { func (db *Database) WriteAnonymous(ctx context.Context) error {
@@ -26,14 +27,14 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
password := auxtool.RandomString(64) password := auxtool.RandomString(64)
passhash := auxpwd.MakeSHA256Hash([]byte(password)) passhash := auxpwd.MakeSHA256Hash([]byte(password))
accountDescr := &descr.Account{ accountDescr := &descr.Account{
ID: descr.AnonymousID, ID: terms.AnonymousID,
Username: descr.AnonimousUsername, Username: terms.AnonimousUsername,
Passhash: passhash, Passhash: passhash,
Disabled: false, Disabled: false,
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: descr.ServerID, CreatedBy: terms.ServerID,
UpdatedBy: descr.ServerID, UpdatedBy: terms.ServerID,
} }
err = db.InsertAccount(ctx, accountDescr) err = db.InsertAccount(ctx, accountDescr)
if err != nil { if err != nil {
@@ -42,12 +43,12 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
grantDescr := &descr.Grant{ grantDescr := &descr.Grant{
ID: auxuuid.NewUUID(), ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: descr.RightReadFiles, Right: terms.RightReadFiles,
Pattern: ".*", Pattern: ".*",
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: descr.ServerID, CreatedBy: terms.ServerID,
UpdatedBy: descr.ServerID, UpdatedBy: terms.ServerID,
} }
err = db.InsertGrant(ctx, grantDescr) err = db.InsertGrant(ctx, grantDescr)
if err != nil { if err != nil {
@@ -56,12 +57,12 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: descr.RightReadImages, Right: terms.RightReadImages,
Pattern: ".*", Pattern: ".*",
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: descr.ServerID, CreatedBy: terms.ServerID,
UpdatedBy: descr.ServerID, UpdatedBy: terms.ServerID,
} }
err = db.InsertGrant(ctx, grantDescr) err = db.InsertGrant(ctx, grantDescr)
if err != nil { if err != nil {
@@ -75,16 +76,16 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
func (db *Database) WriteInituser(ctx context.Context) error { func (db *Database) WriteInituser(ctx context.Context) error {
var err error var err error
now := auxtool.TimeNow() now := auxtool.TimeNow()
passhash := auxpwd.MakeSHA256Hash([]byte(descr.InitUsername)) passhash := auxpwd.MakeSHA256Hash([]byte(terms.InitUsername))
accountDescr := &descr.Account{ accountDescr := &descr.Account{
ID: descr.InitID, ID: terms.InitID,
Username: descr.InitUsername, Username: terms.InitUsername,
Passhash: passhash, Passhash: passhash,
Disabled: false, Disabled: false,
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: descr.ServerID, CreatedBy: terms.ServerID,
UpdatedBy: descr.ServerID, UpdatedBy: terms.ServerID,
} }
err = db.InsertAccount(ctx, accountDescr) err = db.InsertAccount(ctx, accountDescr)
if err != nil { if err != nil {
@@ -94,12 +95,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr := &descr.Grant{ grantDescr := &descr.Grant{
ID: auxuuid.NewUUID(), ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: descr.RightReadFiles, Right: terms.RightReadFiles,
Pattern: ".*", Pattern: ".*",
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: descr.ServerID, CreatedBy: terms.ServerID,
UpdatedBy: descr.ServerID, UpdatedBy: terms.ServerID,
} }
err = db.InsertGrant(ctx, grantDescr) err = db.InsertGrant(ctx, grantDescr)
if err != nil { if err != nil {
@@ -108,12 +109,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: descr.RightWriteFiles, Right: terms.RightWriteFiles,
Pattern: ".*", Pattern: ".*",
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: descr.ServerID, CreatedBy: terms.ServerID,
UpdatedBy: descr.ServerID, UpdatedBy: terms.ServerID,
} }
err = db.InsertGrant(ctx, grantDescr) err = db.InsertGrant(ctx, grantDescr)
if err != nil { if err != nil {
@@ -123,12 +124,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: descr.RightReadAccounts, Right: terms.RightReadAccounts,
Pattern: ".*", Pattern: ".*",
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: descr.ServerID, CreatedBy: terms.ServerID,
UpdatedBy: descr.ServerID, UpdatedBy: terms.ServerID,
} }
err = db.InsertGrant(ctx, grantDescr) err = db.InsertGrant(ctx, grantDescr)
if err != nil { if err != nil {
@@ -137,12 +138,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: descr.RightWriteAccounts, Right: terms.RightWriteAccounts,
Pattern: ".*", Pattern: ".*",
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: descr.ServerID, CreatedBy: terms.ServerID,
UpdatedBy: descr.ServerID, UpdatedBy: terms.ServerID,
} }
err = db.InsertGrant(ctx, grantDescr) err = db.InsertGrant(ctx, grantDescr)
if err != nil { if err != nil {
@@ -152,12 +153,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: descr.RightReadImages, Right: terms.RightReadImages,
Pattern: ".*", Pattern: ".*",
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: descr.ServerID, CreatedBy: terms.ServerID,
UpdatedBy: descr.ServerID, UpdatedBy: terms.ServerID,
} }
err = db.InsertGrant(ctx, grantDescr) err = db.InsertGrant(ctx, grantDescr)
if err != nil { if err != nil {
@@ -166,12 +167,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr = &descr.Grant{ grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(), ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID, AccountID: accountDescr.ID,
Right: descr.RightWriteImages, Right: terms.RightWriteImages,
Pattern: ".*", Pattern: ".*",
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
CreatedBy: descr.ServerID, CreatedBy: terms.ServerID,
UpdatedBy: descr.ServerID, UpdatedBy: terms.ServerID,
} }
err = db.InsertGrant(ctx, grantDescr) err = db.InsertGrant(ctx, grantDescr)
if err != nil { if err != nil {
+1 -1
View File
@@ -12,7 +12,7 @@ package maindb
import ( import (
"context" "context"
"mstore/app/descr" "mstore/pkg/descr"
) )
func (db *Database) InsertManifest(ctx context.Context, manifest *descr.Manifest) error { func (db *Database) InsertManifest(ctx context.Context, manifest *descr.Manifest) error {
+1 -1
View File
@@ -4,10 +4,10 @@ import (
"context" "context"
"fmt" "fmt"
"mstore/app/descr"
"mstore/pkg/auxpwd" "mstore/pkg/auxpwd"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid" "mstore/pkg/auxuuid"
"mstore/pkg/descr"
) )
type CreateAccountParams struct { type CreateAccountParams struct {
+51 -3
View File
@@ -20,9 +20,10 @@ import (
"strconv" "strconv"
"strings" "strings"
"mstore/app/descr"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid" "mstore/pkg/auxuuid"
"mstore/pkg/descr"
"mstore/pkg/terms"
) )
// FileInfo // FileInfo
@@ -359,7 +360,7 @@ func (oper *Operator) ListCollections(ctx context.Context, operID string, param
// DeleteColletion // DeleteColletion
type DeleteColletionParams struct { type DeleteColletionParams struct {
Path string Path string
IsPattern bool `params:"isPattern"` PathAs string `param:"pathAs"`
} }
type DeleteColletionResult struct { type DeleteColletionResult struct {
Files []descr.File `json:"collection,omitempty"` Files []descr.File `json:"collection,omitempty"`
@@ -375,7 +376,30 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operID string, param
code := http.StatusInternalServerError code := http.StatusInternalServerError
return code, res, err return code, res, err
} }
fileDescrs, err := oper.mdb.ListFilesByCollection(ctx, param.Path) oper.logg.Debugf("=== Use path as %s", param.PathAs)
switch terms.PathAs(param.PathAs) {
case terms.AsPrefix:
fileDescrs, err := oper.mdb.ListAllFiles(ctx)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
collMap := make(map[string]bool)
for _, item := range fileDescrs {
_, exists := collMap[item.Collection]
if !exists {
collMap[item.Collection] = true
}
}
collections := make([]string, len(collMap))
for key, _ := range collMap {
collections = append(collections, key)
}
for _, collection := range collections {
if strings.HasPrefix(collection, param.Path) {
fileDescrs, err := oper.mdb.ListFilesByCollection(ctx, collection)
if err != nil { if err != nil {
code := http.StatusInternalServerError code := http.StatusInternalServerError
return code, res, err return code, res, err
@@ -394,6 +418,30 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operID string, param
} }
res.Files = append(res.Files, file) res.Files = append(res.Files, file)
} }
}
}
default:
fileDescrs, err := oper.mdb.ListFilesByCollection(ctx, param.Path)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
// TODO: transaction
for _, file := range fileDescrs {
err = oper.store.DeleteFile(file.Collection, file.Name)
if err != nil {
oper.logg.Warningf("%v", err)
err = nil
}
err = oper.mdb.DeleteFileByCollectionName(ctx, file.Collection, file.Name)
if err != nil {
code := http.StatusInternalServerError
return code, res, err
}
res.Files = append(res.Files, file)
}
}
code := http.StatusOK code := http.StatusOK
return code, res, err return code, res, err
} }
+1 -1
View File
@@ -5,9 +5,9 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"mstore/app/descr"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid" "mstore/pkg/auxuuid"
"mstore/pkg/descr"
) )
// CreateGrant // CreateGrant
+1 -1
View File
@@ -18,8 +18,8 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"mstore/app/descr"
"mstore/pkg/auxoci" "mstore/pkg/auxoci"
"mstore/pkg/descr"
) )
type ManifestExistsParams struct { type ManifestExistsParams struct {
+1 -1
View File
@@ -10,9 +10,9 @@
package operator package operator
import ( import (
"mstore/app/descr"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/auxuuid" "mstore/pkg/auxuuid"
"mstore/pkg/descr"
ocidigest "github.com/opencontainers/go-digest" ocidigest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
+1 -1
View File
@@ -22,7 +22,6 @@ import (
"time" "time"
"mstore/app/config" "mstore/app/config"
"mstore/app/descr"
"mstore/app/handler" "mstore/app/handler"
"mstore/app/logger" "mstore/app/logger"
"mstore/app/maindb" "mstore/app/maindb"
@@ -30,6 +29,7 @@ import (
"mstore/app/service" "mstore/app/service"
"mstore/app/storage" "mstore/app/storage"
"mstore/pkg/auxtool" "mstore/pkg/auxtool"
"mstore/pkg/descr"
yaml "go.yaml.in/yaml/v4" yaml "go.yaml.in/yaml/v4"
) )
+8 -7
View File
@@ -17,8 +17,9 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"mstore/app/descr"
"mstore/pkg/client" "mstore/pkg/client"
"mstore/pkg/descr"
"mstore/pkg/terms"
) )
const ( const (
@@ -145,12 +146,12 @@ func (util *AccountUtil) createAccount(common *CommonAccountParams, params *Crea
} }
fullRights := []string{ fullRights := []string{
descr.RightWriteAccounts, terms.RightWriteAccounts,
descr.RightReadAccounts, terms.RightReadAccounts,
descr.RightWriteFiles, terms.RightWriteFiles,
descr.RightReadFiles, terms.RightReadFiles,
descr.RightWriteImages, terms.RightWriteImages,
descr.RightReadImages, terms.RightReadImages,
} }
for _, right := range fullRights { for _, right := range fullRights {
id, err := client.NewClient().CreateGrantByAccountID(ctx, hostname, accountID, right, ".*") id, err := client.NewClient().CreateGrantByAccountID(ctx, hostname, accountID, right, ".*")
+12 -4
View File
@@ -21,8 +21,9 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"mstore/app/descr"
"mstore/pkg/client" "mstore/pkg/client"
"mstore/pkg/descr"
"mstore/pkg/terms"
) )
func (util *FileUtil) CreateFileCmds() *cobra.Command { func (util *FileUtil) CreateFileCmds() *cobra.Command {
@@ -131,7 +132,7 @@ func (util *FileUtil) CreateCollectionCmds() *cobra.Command {
Run: util.DeleteCollection, Run: util.DeleteCollection,
} }
deleteCollectionCmd.Flags().BoolVarP(&util.deleteCollectionParams.Detail, "detail", "D", false, "Show detail file information") deleteCollectionCmd.Flags().BoolVarP(&util.deleteCollectionParams.Detail, "detail", "D", false, "Show detail file information")
deleteCollectionCmd.Flags().BoolVarP(&util.deleteCollectionParams.Recursive, "recursive", "R", false, "Use path as collection pattern") deleteCollectionCmd.Flags().BoolVarP(&util.deleteCollectionParams.AsPrefix, "asPrefix", "P", true, "Use path as collection path prefix")
subCmd.AddCommand(deleteCollectionCmd) subCmd.AddCommand(deleteCollectionCmd)
@@ -430,7 +431,7 @@ func (util *FileUtil) listCollections(common *CommonFileParams, params *ListColl
type DeleteCollectionParams struct { type DeleteCollectionParams struct {
Path string Path string
Detail bool Detail bool
Recursive bool AsPrefix bool
} }
type DeleteCollectionResult struct { type DeleteCollectionResult struct {
@@ -454,7 +455,14 @@ func (util *FileUtil) deleteCollection(common *CommonFileParams, params *DeleteC
} }
timeout := time.Duration(common.Timeout) * time.Second timeout := time.Duration(common.Timeout) * time.Second
ctx, _ := context.WithTimeout(context.Background(), timeout) ctx, _ := context.WithTimeout(context.Background(), timeout)
files, err := client.NewClient().DeleteCollection(ctx, params.Path, params.Recursive) var pathAs terms.PathAs
switch {
case params.AsPrefix:
pathAs = terms.AsPrefix
default:
pathAs = terms.AsFinePath
}
files, err := client.NewClient().DeleteCollection(ctx, params.Path, pathAs)
if err != nil { if err != nil {
return res, err return res, err
} }
+1 -1
View File
@@ -17,8 +17,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"mstore/app/descr"
"mstore/pkg/client" "mstore/pkg/client"
"mstore/pkg/descr"
) )
func (util *GrantUtil) CreateGrantCmds() *cobra.Command { func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
+1 -1
View File
@@ -14,9 +14,9 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"mstore/app/descr"
"mstore/app/handler" "mstore/app/handler"
"mstore/app/operator" "mstore/app/operator"
"mstore/pkg/descr"
) )
func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, password string) (string, error) { func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, password string) (string, error) {
+9 -5
View File
@@ -21,8 +21,9 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"mstore/app/descr"
"mstore/pkg/auxhttp" "mstore/pkg/auxhttp"
"mstore/pkg/descr"
"mstore/pkg/terms"
) )
func (cli *Client) FileInfo(ctx context.Context, fileuri string) (bool, *descr.File, error) { func (cli *Client) FileInfo(ctx context.Context, fileuri string) (bool, *descr.File, error) {
@@ -324,7 +325,7 @@ func (cli *Client) ListCollections(ctx context.Context, catalogURI string) ([]st
return res, err return res, err
} }
func (cli *Client) DeleteCollection(ctx context.Context, catalogURI string, isPattern bool) ([]descr.File, error) { func (cli *Client) DeleteCollection(ctx context.Context, catalogURI string, usePathAs terms.PathAs) ([]descr.File, error) {
var err error var err error
res := make([]descr.File, 0) res := make([]descr.File, 0)
@@ -336,10 +337,13 @@ func (cli *Client) DeleteCollection(ctx context.Context, catalogURI string, isPa
if err != nil { if err != nil {
return res, err return res, err
} }
if isPattern {
values := url.Values{} values := url.Values{}
values.Add("isPattern", "true") if usePathAs != "" {
catalogURI = catalogURI + "?" + values.Encode() values.Add("pathAs", string(usePathAs))
}
encodedValues := values.Encode()
if encodedValues != "" {
catalogURI = catalogURI + "?" + encodedValues
} }
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, catalogURI, nil) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, catalogURI, nil)
+1 -1
View File
@@ -14,9 +14,9 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"mstore/app/descr"
"mstore/app/handler" "mstore/app/handler"
"mstore/app/operator" "mstore/app/operator"
"mstore/pkg/descr"
) )
func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi, accountID, right, pattern string) (string, error) { func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi, accountID, right, pattern string) (string, error) {
+22
View File
@@ -0,0 +1,22 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* This work is published and licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package descr
type Grant struct {
ID string `json:"id" db:"id"`
AccountID string `json:"accountID" db:"account_id"`
Right string `json:"right" db:"right"`
Pattern string `json:"pattern" db:"pattern"`
CreatedAt string `json:"createdAt" db:"created_at"`
UpdatedAt string `json:"updatedAt" db:"updated_at"`
CreatedBy string `json:"createdBy" db:"created_by"`
UpdatedBy string `json:"updatedBy" db:"updated_by"`
}
+9 -12
View File
@@ -8,7 +8,15 @@
* modifications are strictly prohibited. * modifications are strictly prohibited.
*/ */
package descr package terms
type PathAs string
const (
AsFinePath PathAs = "asFinePath"
AsPrefix PathAs = "asPrefix"
AsRegexp PathAs = "asRegexp"
)
const ( const (
AnonimousUsername = "anonymous" AnonimousUsername = "anonymous"
@@ -20,17 +28,6 @@ const (
InitID = "10000000-0000-0000-0000-000000000005" InitID = "10000000-0000-0000-0000-000000000005"
) )
type Grant struct {
ID string `json:"id" db:"id"`
AccountID string `json:"accountID" db:"account_id"`
Right string `json:"right" db:"right"`
Pattern string `json:"pattern" db:"pattern"`
CreatedAt string `json:"createdAt" db:"created_at"`
UpdatedAt string `json:"updatedAt" db:"updated_at"`
CreatedBy string `json:"createdBy" db:"created_by"`
UpdatedBy string `json:"updatedBy" db:"updated_by"`
}
const ( const (
// Accounts, grants // Accounts, grants
RightReadAccounts = "readAccounts" // GetAccount, ListAccounts RightReadAccounts = "readAccounts" // GetAccount, ListAccounts
+1 -1
View File
@@ -16,9 +16,9 @@ import (
"testing" "testing"
"time" "time"
"mstore/app/descr"
"mstore/app/server" "mstore/app/server"
"mstore/pkg/client" "mstore/pkg/client"
"mstore/pkg/descr"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"