diff --git a/Makefile.am b/Makefile.am index 088991a..629276d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/Makefile.in b/Makefile.in index d519973..f4e25ec 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 \ diff --git a/app/handler/aaafunc.go b/app/handler/aaafunc.go index 284ffc5..4a33d0b 100644 --- a/app/handler/aaafunc.go +++ b/app/handler/aaafunc.go @@ -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 { diff --git a/app/handler/account.go b/app/handler/account.go index 579ac7c..8114d84 100644 --- a/app/handler/account.go +++ b/app/handler/account.go @@ -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) diff --git a/app/handler/blob.go b/app/handler/blob.go index e1250ce..6a474b1 100644 --- a/app/handler/blob.go +++ b/app/handler/blob.go @@ -14,9 +14,9 @@ import ( "io" "net/http" - "mstore/app/descr" "mstore/app/operator" "mstore/app/router" + "mstore/pkg/terms" ) // HEAD /v2//blobs/ 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 diff --git a/app/handler/file.go b/app/handler/file.go index 1bec50a..e809310 100644 --- a/app/handler/file.go +++ b/app/handler/file.go @@ -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 diff --git a/app/handler/grant.go b/app/handler/grant.go index f669ec4..7445c0a 100644 --- a/app/handler/grant.go +++ b/app/handler/grant.go @@ -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) diff --git a/app/handler/manifest.go b/app/handler/manifest.go index 3de76c4..9ab899b 100644 --- a/app/handler/manifest.go +++ b/app/handler/manifest.go @@ -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 diff --git a/app/maindb/account.go b/app/maindb/account.go index fdcd8e3..56e613d 100644 --- a/app/maindb/account.go +++ b/app/maindb/account.go @@ -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 { diff --git a/app/maindb/blob.go b/app/maindb/blob.go index 6a2ca5c..1a3f2ae 100644 --- a/app/maindb/blob.go +++ b/app/maindb/blob.go @@ -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 { diff --git a/app/maindb/file.go b/app/maindb/file.go index e3a25b0..2ccb22d 100644 --- a/app/maindb/file.go +++ b/app/maindb/file.go @@ -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 { diff --git a/app/maindb/file_test.go b/app/maindb/file_test.go index fa99e2b..a571ec4 100644 --- a/app/maindb/file_test.go +++ b/app/maindb/file_test.go @@ -14,9 +14,9 @@ import ( "testing" "time" - "mstore/app/descr" "mstore/pkg/auxtool" "mstore/pkg/auxuuid" + "mstore/pkg/descr" "github.com/stretchr/testify/require" ) diff --git a/app/maindb/grant.go b/app/maindb/grant.go index 29a7bdc..4df4c40 100644 --- a/app/maindb/grant.go +++ b/app/maindb/grant.go @@ -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 { diff --git a/app/maindb/grant_test.go b/app/maindb/grant_test.go index 44ae262..bdbd03d 100644 --- a/app/maindb/grant_test.go +++ b/app/maindb/grant_test.go @@ -14,9 +14,9 @@ import ( "testing" "time" - "mstore/app/descr" "mstore/pkg/auxtool" "mstore/pkg/auxuuid" + "mstore/pkg/descr" "github.com/stretchr/testify/require" ) diff --git a/app/maindb/init.go b/app/maindb/init.go index aedeb9e..ee7a5e5 100644 --- a/app/maindb/init.go +++ b/app/maindb/init.go @@ -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 { diff --git a/app/maindb/manifest.go b/app/maindb/manifest.go index c7bcbce..c1ad5c7 100644 --- a/app/maindb/manifest.go +++ b/app/maindb/manifest.go @@ -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 { diff --git a/app/operator/account.go b/app/operator/account.go index 5b8b15e..f6fc47d 100644 --- a/app/operator/account.go +++ b/app/operator/account.go @@ -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 { diff --git a/app/operator/file.go b/app/operator/file.go index 8e86acb..8bd2a4f 100644 --- a/app/operator/file.go +++ b/app/operator/file.go @@ -20,9 +20,10 @@ import ( "strconv" "strings" - "mstore/app/descr" "mstore/pkg/auxtool" "mstore/pkg/auxuuid" + "mstore/pkg/descr" + "mstore/pkg/terms" ) // FileInfo @@ -358,8 +359,8 @@ func (oper *Operator) ListCollections(ctx context.Context, operID string, param // DeleteColletion type DeleteColletionParams struct { - Path string - IsPattern bool `params:"isPattern"` + Path string + PathAs string `param:"pathAs"` } type DeleteColletionResult struct { Files []descr.File `json:"collection,omitempty"` @@ -375,24 +376,71 @@ 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) - 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) + 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 } - res.Files = append(res.Files, file) + + 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 + } + // 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) + } + } + } + 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 diff --git a/app/operator/grant.go b/app/operator/grant.go index 0be8e7e..c217cd2 100644 --- a/app/operator/grant.go +++ b/app/operator/grant.go @@ -5,9 +5,9 @@ import ( "fmt" "regexp" - "mstore/app/descr" "mstore/pkg/auxtool" "mstore/pkg/auxuuid" + "mstore/pkg/descr" ) // CreateGrant diff --git a/app/operator/manifest.go b/app/operator/manifest.go index aff0895..ac80f94 100644 --- a/app/operator/manifest.go +++ b/app/operator/manifest.go @@ -18,8 +18,8 @@ import ( "net/http" "strconv" - "mstore/app/descr" "mstore/pkg/auxoci" + "mstore/pkg/descr" ) type ManifestExistsParams struct { diff --git a/app/operator/ociaux.go b/app/operator/ociaux.go index 5f7d26c..a9ff8bc 100644 --- a/app/operator/ociaux.go +++ b/app/operator/ociaux.go @@ -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" diff --git a/app/server/server.go b/app/server/server.go index caef8cf..602c168 100644 --- a/app/server/server.go +++ b/app/server/server.go @@ -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" ) diff --git a/cmd/mstorectl/accountcmd.go b/cmd/mstorectl/accountcmd.go index cc228a7..b3dfd3d 100644 --- a/cmd/mstorectl/accountcmd.go +++ b/cmd/mstorectl/accountcmd.go @@ -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, ".*") diff --git a/cmd/mstorectl/filecmd.go b/cmd/mstorectl/filecmd.go index 5db8d42..9ef89ed 100644 --- a/cmd/mstorectl/filecmd.go +++ b/cmd/mstorectl/filecmd.go @@ -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) @@ -428,9 +429,9 @@ func (util *FileUtil) listCollections(common *CommonFileParams, params *ListColl // DeleteCollection type DeleteCollectionParams struct { - Path string - Detail bool - Recursive bool + Path string + Detail 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 } diff --git a/cmd/mstorectl/grantcmd.go b/cmd/mstorectl/grantcmd.go index c72419f..b985c44 100644 --- a/cmd/mstorectl/grantcmd.go +++ b/cmd/mstorectl/grantcmd.go @@ -17,8 +17,8 @@ import ( "github.com/spf13/cobra" - "mstore/app/descr" "mstore/pkg/client" + "mstore/pkg/descr" ) func (util *GrantUtil) CreateGrantCmds() *cobra.Command { diff --git a/pkg/client/account.go b/pkg/client/account.go index 613eff1..97d0ede 100644 --- a/pkg/client/account.go +++ b/pkg/client/account.go @@ -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) { diff --git a/pkg/client/file.go b/pkg/client/file.go index 9c040af..e7b7e9a 100644 --- a/pkg/client/file.go +++ b/pkg/client/file.go @@ -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() + values := url.Values{} + if usePathAs != "" { + values.Add("pathAs", string(usePathAs)) + } + encodedValues := values.Encode() + if encodedValues != "" { + catalogURI = catalogURI + "?" + encodedValues } req, err := http.NewRequestWithContext(ctx, http.MethodDelete, catalogURI, nil) diff --git a/pkg/client/grant.go b/pkg/client/grant.go index 344c7dc..fcd8578 100644 --- a/pkg/client/grant.go +++ b/pkg/client/grant.go @@ -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) { diff --git a/app/descr/account.go b/pkg/descr/account.go similarity index 100% rename from app/descr/account.go rename to pkg/descr/account.go diff --git a/app/descr/blob.go b/pkg/descr/blob.go similarity index 100% rename from app/descr/blob.go rename to pkg/descr/blob.go diff --git a/app/descr/file.go b/pkg/descr/file.go similarity index 100% rename from app/descr/file.go rename to pkg/descr/file.go diff --git a/pkg/descr/grant.go b/pkg/descr/grant.go new file mode 100644 index 0000000..8140be5 --- /dev/null +++ b/pkg/descr/grant.go @@ -0,0 +1,22 @@ +/* + * Copyright 2026 Oleg Borodin + * + * 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"` +} diff --git a/app/descr/manifest.go b/pkg/descr/manifest.go similarity index 100% rename from app/descr/manifest.go rename to pkg/descr/manifest.go diff --git a/app/descr/response.go b/pkg/descr/response.go similarity index 100% rename from app/descr/response.go rename to pkg/descr/response.go diff --git a/app/descr/server.go b/pkg/descr/server.go similarity index 100% rename from app/descr/server.go rename to pkg/descr/server.go diff --git a/app/descr/grant.go b/pkg/terms/terms.go similarity index 70% rename from app/descr/grant.go rename to pkg/terms/terms.go index aa3ad8b..29ec444 100644 --- a/app/descr/grant.go +++ b/pkg/terms/terms.go @@ -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 diff --git a/test/account_test.go b/test/account_test.go index 174e94b..9deb8bc 100644 --- a/test/account_test.go +++ b/test/account_test.go @@ -16,9 +16,9 @@ import ( "testing" "time" - "mstore/app/descr" "mstore/app/server" "mstore/pkg/client" + "mstore/pkg/descr" "github.com/stretchr/testify/require"