From 62ada209250ddb3ab79f8bf4a2e267bb8fc3a0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3=20=D0=91=D0=BE=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Sat, 14 Feb 2026 20:06:12 +0200 Subject: [PATCH] working commit --- app/handler/aaafunc.go | 40 ++++++++++++++++++++++++---------------- app/handler/account.go | 9 +++++++++ app/handler/service.go | 26 -------------------------- app/operator/grant.go | 7 +++++++ pkg/client/file.go | 12 ++++++------ test/image_test.go | 2 +- 6 files changed, 47 insertions(+), 49 deletions(-) diff --git a/app/handler/aaafunc.go b/app/handler/aaafunc.go index a37d39f..faaf120 100644 --- a/app/handler/aaafunc.go +++ b/app/handler/aaafunc.go @@ -1,3 +1,12 @@ +/* + * 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 handler import ( @@ -52,16 +61,19 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) { if err != nil { return success, accountID, err } + success, id, err := hand.ValidatePassword(rctx.Ctx, username, password) + if err != nil { + return false, accountID, err + } + if !success { + err = fmt.Errorf("Incorrect username or password") + return false, accountID, err + } + accountID = id + return success, accountID, err } - success, id, err := hand.ValidatePassword(rctx.Ctx, username, password) - if err != nil { - return false, accountID, err - } - if !success { - err = fmt.Errorf("Incorrect username or password") - return false, accountID, err - } - accountID = id + success = true + accountID = descr.AnonymousID return success, accountID, err } @@ -90,16 +102,12 @@ func (hand *Handler) CheckRight(ctx context.Context, accountID, right, subject s var res bool hand.logg.Debugf("Cop check your right %s: %s %s", accountID, right, subject) // =[]= - // /------\ + // .------. // .---[-] [#] \--, // >| [ ] [ ] | // '--0-------0----' // Bad news for you, baby.... # - - // TODO: defer logger - - defer hand.logg.Debugf("Checking right %s for %s: %v", right, accountID, res) - + // exists, grant, err := hand.mdb.GetGrantByAccoundIDRight(ctx, accountID, right) if err != nil { return res, err @@ -107,7 +115,6 @@ func (hand *Handler) CheckRight(ctx context.Context, accountID, right, subject s if !exists { return res, err } - switch right { case descr.RightReadFiles, descr.RightWriteFiles: grant.Pattern = ".*" @@ -122,5 +129,6 @@ func (hand *Handler) CheckRight(ctx context.Context, accountID, right, subject s // NOP } res = true + hand.logg.Debugf("Checking right %s for %s: %v", right, accountID, res) return res, err } diff --git a/app/handler/account.go b/app/handler/account.go index 6b055c7..579ac7c 100644 --- a/app/handler/account.go +++ b/app/handler/account.go @@ -1,3 +1,12 @@ +/* + * 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 handler import ( diff --git a/app/handler/service.go b/app/handler/service.go index 963f7e8..5cbf222 100644 --- a/app/handler/service.go +++ b/app/handler/service.go @@ -15,33 +15,7 @@ import ( ) func (hand *Handler) SendHello(rctx *router.Context) { - - authSuccess, _ := rctx.Bools[authTag] - authUser, _ := rctx.Strings[userTag] - - hand.logg.Debugf("%s:%v", authTag, authSuccess) - hand.logg.Debugf("%s:%v", userTag, authUser) - - if authSuccess { - - } - params := &operator.SendHelloParams{} res, _ := hand.oper.SendHello(params) hand.SendResult(rctx, res) } - -/* -func checkGrant(who, subject, operation string) (bool, error) { - - return true, error -} - -type Grant struct { - AccountID `xxxx-xxxx` - Subject `file` - Operation `putFile` - - Path "foo/bare" -} -*/ diff --git a/app/operator/grant.go b/app/operator/grant.go index 7acaa4d..f86d9c2 100644 --- a/app/operator/grant.go +++ b/app/operator/grant.go @@ -3,6 +3,7 @@ package operator import ( "context" "fmt" + "regexp" "mstore/app/descr" "mstore/pkg/auxtool" @@ -36,6 +37,12 @@ func (oper *Operator) CreateGrant(ctx context.Context, operID string, params *Cr return res, err } + _, err = regexp.Compile(params.Pattern) + if err != nil { + err := fmt.Errorf("Cannot compile regexp %s: %v", err) + return res, err + } + grantExists, _, err := oper.mdb.GetGrantByAccoundIDRightPattern(ctx, params.AccountID, params.Right, params.Pattern) if err != nil { return res, err diff --git a/pkg/client/file.go b/pkg/client/file.go index c269895..717cb58 100644 --- a/pkg/client/file.go +++ b/pkg/client/file.go @@ -53,12 +53,12 @@ func (cli *Client) FileInfo(ctx context.Context, fileuri string) (bool, *descr.F if resp.StatusCode == http.StatusOK { file.Collection = resp.Header.Get("Content-Collection") file.Name = resp.Header.Get("Content-Name") - //contentSize := resp.Header.Get("Content-Size") - //size, err := strconv.ParseInt(contentSize, 10, 64) - //if err != nil { - //return exists, file, err - //} - //file.Size = size + contentSize := resp.Header.Get("Content-Size") + size, err := strconv.ParseInt(contentSize, 10, 64) + if err != nil { + return exists, file, err + } + file.Size = size file.Type = resp.Header.Get("Content-Type") file.Checksum = resp.Header.Get("Content-Digest") exists = true diff --git a/test/image_test.go b/test/image_test.go index 8a6ee82..4c10e90 100644 --- a/test/image_test.go +++ b/test/image_test.go @@ -26,7 +26,7 @@ import ( func xxxTestImageLife(t *testing.T) { var srvport int64 = 10250 srvdir := t.TempDir() - srvaddr := fmt.Sprintf("127.0.0.1:%d", srvport) + srvaddr := fmt.Sprintf("mstore:mstore@127.0.0.1:%d", srvport) srv, err := server.NewServer() require.NoError(t, err)