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/variant.go \
\
app/descr/account.go \
app/descr/blob.go \
app/descr/file.go \
app/descr/grant.go \
app/descr/manifest.go \
app/descr/response.go \
app/descr/server.go \
pkg/descr/account.go \
pkg/descr/blob.go \
pkg/descr/file.go \
pkg/descr/grant.go \
pkg/descr/manifest.go \
pkg/descr/response.go \
pkg/descr/server.go \
\
app/handler/aaafunc.go \
app/handler/account.go \
+7 -7
View File
@@ -324,13 +324,13 @@ EXTRA_mstored_SOURCES = \
app/config/config.go \
app/config/variant.go \
\
app/descr/account.go \
app/descr/blob.go \
app/descr/file.go \
app/descr/grant.go \
app/descr/manifest.go \
app/descr/response.go \
app/descr/server.go \
pkg/descr/account.go \
pkg/descr/blob.go \
pkg/descr/file.go \
pkg/descr/grant.go \
pkg/descr/manifest.go \
pkg/descr/response.go \
pkg/descr/server.go \
\
app/handler/aaafunc.go \
app/handler/account.go \
+4 -4
View File
@@ -14,10 +14,10 @@ import (
"fmt"
"regexp"
"mstore/app/descr"
"mstore/app/router"
"mstore/pkg/auxhttp"
"mstore/pkg/auxpwd"
"mstore/pkg/terms"
)
const (
@@ -53,7 +53,7 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
var password string
var accountID string
accountID = descr.AnonymousID
accountID = terms.AnonymousID
authHeader := rctx.GetHeader("Authorization")
if authHeader != "" {
@@ -80,7 +80,7 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
}
anonymous:
success = true
accountID = descr.AnonymousID
accountID = terms.AnonymousID
return success, accountID, err
}
@@ -125,7 +125,7 @@ func (hand *Handler) CheckRight(ctx context.Context, accountID, reqRight, subjec
return res, err
}
switch reqRight {
case descr.RightReadFiles, descr.RightWriteFiles:
case terms.RightReadFiles, terms.RightWriteFiles:
for _, grant := range grants {
re, err := regexp.Compile(grant.Pattern)
if err != nil {
+6 -6
View File
@@ -12,9 +12,9 @@ package handler
import (
"fmt"
"mstore/app/descr"
"mstore/app/operator"
"mstore/app/router"
"mstore/pkg/terms"
)
// POST /v3/account/create 200 200
@@ -29,7 +29,7 @@ func (hand *Handler) CreateAccount(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -62,7 +62,7 @@ func (hand *Handler) GetAccount(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -95,7 +95,7 @@ func (hand *Handler) ListAccounts(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -128,7 +128,7 @@ func (hand *Handler) UpdateAccount(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -161,7 +161,7 @@ func (hand *Handler) DeleteAccount(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
+7 -7
View File
@@ -14,9 +14,9 @@ import (
"io"
"net/http"
"mstore/app/descr"
"mstore/app/operator"
"mstore/app/router"
"mstore/pkg/terms"
)
// HEAD /v2/<name>/blobs/<digest> 200 404
@@ -32,7 +32,7 @@ func (hand *Handler) BlobExists(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -72,7 +72,7 @@ func (hand *Handler) PostUpload(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -117,7 +117,7 @@ func (hand *Handler) PatchUpload(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -161,7 +161,7 @@ func (hand *Handler) PutUpload(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -191,7 +191,7 @@ func (hand *Handler) GetBlob(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -237,7 +237,7 @@ func (hand *Handler) DeleteBlob(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
+8 -8
View File
@@ -13,9 +13,9 @@ import (
"io"
"net/http"
"mstore/app/descr"
"mstore/app/operator"
"mstore/app/router"
"mstore/pkg/terms"
)
const zeroContentLength = "0"
@@ -28,7 +28,7 @@ func (hand *Handler) FileInfo(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -73,7 +73,7 @@ func (hand *Handler) PutFile(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -101,7 +101,7 @@ func (hand *Handler) GetFile(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -149,7 +149,7 @@ func (hand *Handler) DeleteFile(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -179,7 +179,7 @@ func (hand *Handler) ListFiles(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -210,7 +210,7 @@ func (hand *Handler) ListCollections(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -248,7 +248,7 @@ func (hand *Handler) DeleteCollection(rctx *router.Context) {
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
+6 -6
View File
@@ -12,9 +12,9 @@ package handler
import (
"fmt"
"mstore/app/descr"
"mstore/app/operator"
"mstore/app/router"
"mstore/pkg/terms"
)
// POST /v3/grant/create 200 200
@@ -29,7 +29,7 @@ func (hand *Handler) CreateGrant(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -62,7 +62,7 @@ func (hand *Handler) GetGrant(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -95,7 +95,7 @@ func (hand *Handler) ListGrants(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -128,7 +128,7 @@ func (hand *Handler) UpdateGrant(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
@@ -161,7 +161,7 @@ func (hand *Handler) DeleteGrant(rctx *router.Context) {
}
// Rigth checking
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 {
err := fmt.Errorf("Operation error: %v", err)
hand.SendError(rctx, err)
+7 -7
View File
@@ -12,9 +12,9 @@ package handler
import (
"net/http"
"mstore/app/descr"
"mstore/app/operator"
"mstore/app/router"
"mstore/pkg/terms"
)
func (hand *Handler) ManifestExists(rctx *router.Context) {
@@ -29,7 +29,7 @@ func (hand *Handler) ManifestExists(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -71,7 +71,7 @@ func (hand *Handler) PutManifest(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -104,7 +104,7 @@ func (hand *Handler) GetManifest(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -144,7 +144,7 @@ func (hand *Handler) DeleteManifest(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -173,7 +173,7 @@ func (hand *Handler) GetReferer(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
@@ -199,7 +199,7 @@ func (hand *Handler) GetTags(rctx *router.Context) {
}
// Rigth checking
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 {
rctx.SetStatus(http.StatusInternalServerError)
return
+1 -1
View File
@@ -3,7 +3,7 @@ package maindb
import (
"context"
"mstore/app/descr"
"mstore/pkg/descr"
)
func (db *Database) InsertAccount(ctx context.Context, account *descr.Account) error {
+1 -1
View File
@@ -12,7 +12,7 @@ package maindb
import (
"context"
"mstore/app/descr"
"mstore/pkg/descr"
)
func (db *Database) InsertBlob(ctx context.Context, layer *descr.Blob) error {
+1 -1
View File
@@ -12,7 +12,7 @@ package maindb
import (
"context"
"mstore/app/descr"
"mstore/pkg/descr"
)
func (db *Database) InsertFile(ctx context.Context, file *descr.File) error {
+1 -1
View File
@@ -14,9 +14,9 @@ import (
"testing"
"time"
"mstore/app/descr"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
"github.com/stretchr/testify/require"
)
+1 -1
View File
@@ -12,7 +12,7 @@ package maindb
import (
"context"
"mstore/app/descr"
"mstore/pkg/descr"
)
func (db *Database) InsertGrant(ctx context.Context, grant *descr.Grant) error {
+1 -1
View File
@@ -14,9 +14,9 @@ import (
"testing"
"time"
"mstore/app/descr"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
"github.com/stretchr/testify/require"
)
+35 -34
View File
@@ -13,10 +13,11 @@ package maindb
import (
"context"
"mstore/app/descr"
"mstore/pkg/auxpwd"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
"mstore/pkg/terms"
)
func (db *Database) WriteAnonymous(ctx context.Context) error {
@@ -26,14 +27,14 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
password := auxtool.RandomString(64)
passhash := auxpwd.MakeSHA256Hash([]byte(password))
accountDescr := &descr.Account{
ID: descr.AnonymousID,
Username: descr.AnonimousUsername,
ID: terms.AnonymousID,
Username: terms.AnonimousUsername,
Passhash: passhash,
Disabled: false,
CreatedAt: now,
UpdatedAt: now,
CreatedBy: descr.ServerID,
UpdatedBy: descr.ServerID,
CreatedBy: terms.ServerID,
UpdatedBy: terms.ServerID,
}
err = db.InsertAccount(ctx, accountDescr)
if err != nil {
@@ -42,12 +43,12 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
grantDescr := &descr.Grant{
ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID,
Right: descr.RightReadFiles,
Right: terms.RightReadFiles,
Pattern: ".*",
CreatedAt: now,
UpdatedAt: now,
CreatedBy: descr.ServerID,
UpdatedBy: descr.ServerID,
CreatedBy: terms.ServerID,
UpdatedBy: terms.ServerID,
}
err = db.InsertGrant(ctx, grantDescr)
if err != nil {
@@ -56,12 +57,12 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID,
Right: descr.RightReadImages,
Right: terms.RightReadImages,
Pattern: ".*",
CreatedAt: now,
UpdatedAt: now,
CreatedBy: descr.ServerID,
UpdatedBy: descr.ServerID,
CreatedBy: terms.ServerID,
UpdatedBy: terms.ServerID,
}
err = db.InsertGrant(ctx, grantDescr)
if err != nil {
@@ -75,16 +76,16 @@ func (db *Database) WriteAnonymous(ctx context.Context) error {
func (db *Database) WriteInituser(ctx context.Context) error {
var err error
now := auxtool.TimeNow()
passhash := auxpwd.MakeSHA256Hash([]byte(descr.InitUsername))
passhash := auxpwd.MakeSHA256Hash([]byte(terms.InitUsername))
accountDescr := &descr.Account{
ID: descr.InitID,
Username: descr.InitUsername,
ID: terms.InitID,
Username: terms.InitUsername,
Passhash: passhash,
Disabled: false,
CreatedAt: now,
UpdatedAt: now,
CreatedBy: descr.ServerID,
UpdatedBy: descr.ServerID,
CreatedBy: terms.ServerID,
UpdatedBy: terms.ServerID,
}
err = db.InsertAccount(ctx, accountDescr)
if err != nil {
@@ -94,12 +95,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr := &descr.Grant{
ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID,
Right: descr.RightReadFiles,
Right: terms.RightReadFiles,
Pattern: ".*",
CreatedAt: now,
UpdatedAt: now,
CreatedBy: descr.ServerID,
UpdatedBy: descr.ServerID,
CreatedBy: terms.ServerID,
UpdatedBy: terms.ServerID,
}
err = db.InsertGrant(ctx, grantDescr)
if err != nil {
@@ -108,12 +109,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID,
Right: descr.RightWriteFiles,
Right: terms.RightWriteFiles,
Pattern: ".*",
CreatedAt: now,
UpdatedAt: now,
CreatedBy: descr.ServerID,
UpdatedBy: descr.ServerID,
CreatedBy: terms.ServerID,
UpdatedBy: terms.ServerID,
}
err = db.InsertGrant(ctx, grantDescr)
if err != nil {
@@ -123,12 +124,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID,
Right: descr.RightReadAccounts,
Right: terms.RightReadAccounts,
Pattern: ".*",
CreatedAt: now,
UpdatedAt: now,
CreatedBy: descr.ServerID,
UpdatedBy: descr.ServerID,
CreatedBy: terms.ServerID,
UpdatedBy: terms.ServerID,
}
err = db.InsertGrant(ctx, grantDescr)
if err != nil {
@@ -137,12 +138,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID,
Right: descr.RightWriteAccounts,
Right: terms.RightWriteAccounts,
Pattern: ".*",
CreatedAt: now,
UpdatedAt: now,
CreatedBy: descr.ServerID,
UpdatedBy: descr.ServerID,
CreatedBy: terms.ServerID,
UpdatedBy: terms.ServerID,
}
err = db.InsertGrant(ctx, grantDescr)
if err != nil {
@@ -152,12 +153,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID,
Right: descr.RightReadImages,
Right: terms.RightReadImages,
Pattern: ".*",
CreatedAt: now,
UpdatedAt: now,
CreatedBy: descr.ServerID,
UpdatedBy: descr.ServerID,
CreatedBy: terms.ServerID,
UpdatedBy: terms.ServerID,
}
err = db.InsertGrant(ctx, grantDescr)
if err != nil {
@@ -166,12 +167,12 @@ func (db *Database) WriteInituser(ctx context.Context) error {
grantDescr = &descr.Grant{
ID: auxuuid.NewUUID(),
AccountID: accountDescr.ID,
Right: descr.RightWriteImages,
Right: terms.RightWriteImages,
Pattern: ".*",
CreatedAt: now,
UpdatedAt: now,
CreatedBy: descr.ServerID,
UpdatedBy: descr.ServerID,
CreatedBy: terms.ServerID,
UpdatedBy: terms.ServerID,
}
err = db.InsertGrant(ctx, grantDescr)
if err != nil {
+1 -1
View File
@@ -12,7 +12,7 @@ package maindb
import (
"context"
"mstore/app/descr"
"mstore/pkg/descr"
)
func (db *Database) InsertManifest(ctx context.Context, manifest *descr.Manifest) error {
+1 -1
View File
@@ -4,10 +4,10 @@ import (
"context"
"fmt"
"mstore/app/descr"
"mstore/pkg/auxpwd"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
)
type CreateAccountParams struct {
+51 -3
View File
@@ -20,9 +20,10 @@ import (
"strconv"
"strings"
"mstore/app/descr"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
"mstore/pkg/terms"
)
// FileInfo
@@ -359,7 +360,7 @@ func (oper *Operator) ListCollections(ctx context.Context, operID string, param
// DeleteColletion
type DeleteColletionParams struct {
Path string
IsPattern bool `params:"isPattern"`
PathAs string `param:"pathAs"`
}
type DeleteColletionResult struct {
Files []descr.File `json:"collection,omitempty"`
@@ -375,7 +376,30 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operID string, param
code := http.StatusInternalServerError
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 {
code := http.StatusInternalServerError
return code, res, err
@@ -394,6 +418,30 @@ func (oper *Operator) DeleteColletion(ctx context.Context, operID string, param
}
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
return code, res, err
}
+1 -1
View File
@@ -5,9 +5,9 @@ import (
"fmt"
"regexp"
"mstore/app/descr"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
)
// CreateGrant
+1 -1
View File
@@ -18,8 +18,8 @@ import (
"net/http"
"strconv"
"mstore/app/descr"
"mstore/pkg/auxoci"
"mstore/pkg/descr"
)
type ManifestExistsParams struct {
+1 -1
View File
@@ -10,9 +10,9 @@
package operator
import (
"mstore/app/descr"
"mstore/pkg/auxtool"
"mstore/pkg/auxuuid"
"mstore/pkg/descr"
ocidigest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
+1 -1
View File
@@ -22,7 +22,6 @@ import (
"time"
"mstore/app/config"
"mstore/app/descr"
"mstore/app/handler"
"mstore/app/logger"
"mstore/app/maindb"
@@ -30,6 +29,7 @@ import (
"mstore/app/service"
"mstore/app/storage"
"mstore/pkg/auxtool"
"mstore/pkg/descr"
yaml "go.yaml.in/yaml/v4"
)
+8 -7
View File
@@ -17,8 +17,9 @@ import (
"github.com/spf13/cobra"
"mstore/app/descr"
"mstore/pkg/client"
"mstore/pkg/descr"
"mstore/pkg/terms"
)
const (
@@ -145,12 +146,12 @@ func (util *AccountUtil) createAccount(common *CommonAccountParams, params *Crea
}
fullRights := []string{
descr.RightWriteAccounts,
descr.RightReadAccounts,
descr.RightWriteFiles,
descr.RightReadFiles,
descr.RightWriteImages,
descr.RightReadImages,
terms.RightWriteAccounts,
terms.RightReadAccounts,
terms.RightWriteFiles,
terms.RightReadFiles,
terms.RightWriteImages,
terms.RightReadImages,
}
for _, right := range fullRights {
id, err := client.NewClient().CreateGrantByAccountID(ctx, hostname, accountID, right, ".*")
+12 -4
View File
@@ -21,8 +21,9 @@ import (
"github.com/spf13/cobra"
"mstore/app/descr"
"mstore/pkg/client"
"mstore/pkg/descr"
"mstore/pkg/terms"
)
func (util *FileUtil) CreateFileCmds() *cobra.Command {
@@ -131,7 +132,7 @@ func (util *FileUtil) CreateCollectionCmds() *cobra.Command {
Run: util.DeleteCollection,
}
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)
@@ -430,7 +431,7 @@ func (util *FileUtil) listCollections(common *CommonFileParams, params *ListColl
type DeleteCollectionParams struct {
Path string
Detail bool
Recursive bool
AsPrefix bool
}
type DeleteCollectionResult struct {
@@ -454,7 +455,14 @@ func (util *FileUtil) deleteCollection(common *CommonFileParams, params *DeleteC
}
timeout := time.Duration(common.Timeout) * time.Second
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 {
return res, err
}
+1 -1
View File
@@ -17,8 +17,8 @@ import (
"github.com/spf13/cobra"
"mstore/app/descr"
"mstore/pkg/client"
"mstore/pkg/descr"
)
func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
+1 -1
View File
@@ -14,9 +14,9 @@ import (
"encoding/json"
"fmt"
"mstore/app/descr"
"mstore/app/handler"
"mstore/app/operator"
"mstore/pkg/descr"
)
func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, password string) (string, error) {
+9 -5
View File
@@ -21,8 +21,9 @@ import (
"path/filepath"
"strconv"
"mstore/app/descr"
"mstore/pkg/auxhttp"
"mstore/pkg/descr"
"mstore/pkg/terms"
)
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
}
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
res := make([]descr.File, 0)
@@ -336,10 +337,13 @@ func (cli *Client) DeleteCollection(ctx context.Context, catalogURI string, isPa
if err != nil {
return res, err
}
if isPattern {
values := url.Values{}
values.Add("isPattern", "true")
catalogURI = catalogURI + "?" + values.Encode()
if usePathAs != "" {
values.Add("pathAs", string(usePathAs))
}
encodedValues := values.Encode()
if encodedValues != "" {
catalogURI = catalogURI + "?" + encodedValues
}
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, catalogURI, nil)
+1 -1
View File
@@ -14,9 +14,9 @@ import (
"encoding/json"
"fmt"
"mstore/app/descr"
"mstore/app/handler"
"mstore/app/operator"
"mstore/pkg/descr"
)
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.
*/
package descr
package terms
type PathAs string
const (
AsFinePath PathAs = "asFinePath"
AsPrefix PathAs = "asPrefix"
AsRegexp PathAs = "asRegexp"
)
const (
AnonimousUsername = "anonymous"
@@ -20,17 +28,6 @@ const (
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 (
// Accounts, grants
RightReadAccounts = "readAccounts" // GetAccount, ListAccounts
+1 -1
View File
@@ -16,9 +16,9 @@ import (
"testing"
"time"
"mstore/app/descr"
"mstore/app/server"
"mstore/pkg/client"
"mstore/pkg/descr"
"github.com/stretchr/testify/require"