From 15a3379e5c7f96054b2311cc3603c5bccb8655d6 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: Sun, 15 Feb 2026 12:25:09 +0200 Subject: [PATCH] working commit --- Makefile.am | 2 +- Makefile.in | 2 +- app/config/config.go | 15 +++++++++------ app/descr/grant.go | 5 +---- app/handler/grant.go | 10 +++++----- app/maindb/init.go | 6 +++--- test/file_test.go | 2 +- test/image_test.go | 3 +-- 8 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Makefile.am b/Makefile.am index 52fd6e2..ca87e56 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,7 @@ mstored$(EXEEXT): $(mstored_SOURCES) $(EXTRA_mstored_SOURCES) env CGO_ENABLED=1 $(GO) build $(GOFLAGS) -o mstored$(EXEEXT) $(mstored_SOURCES) run: $(mstored_SOURCES) - cd cmd/mstored && env CGO_ENABLED=1 $(GO) run . + cd cmd/mstored && env CGO_ENABLED=1 $(GO) run . -daemon=false CWD=$(shell pwd) diff --git a/Makefile.in b/Makefile.in index ae494ec..5d65ba6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -977,7 +977,7 @@ mstored$(EXEEXT): $(mstored_SOURCES) $(EXTRA_mstored_SOURCES) env CGO_ENABLED=1 $(GO) build $(GOFLAGS) -o mstored$(EXEEXT) $(mstored_SOURCES) run: $(mstored_SOURCES) - cd cmd/mstored && env CGO_ENABLED=1 $(GO) run . + cd cmd/mstored && env CGO_ENABLED=1 $(GO) run . -daemon=false format: @dirs=$$($(FIND) $(CWD) -name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \ diff --git a/app/config/config.go b/app/config/config.go index 18cee00..806130e 100644 --- a/app/config/config.go +++ b/app/config/config.go @@ -109,20 +109,23 @@ func (conf *Config) ReadOptions() error { // TODO: make local scope of flags - //flag.Int64Var(&conf.Service.Port, "port", conf.Service.Port, "listen port") - //flag.BoolVar(&conf.AsDaemon, "daemon", conf.AsDaemon, "run as daemon") + flagSet := flag.NewFlagSet(exename, flag.ExitOnError) + flagSet.Int64Var(&conf.Service.Port, "port", conf.Service.Port, "listen port") + flagSet.BoolVar(&conf.AsDaemon, "daemon", conf.AsDaemon, "run as daemon") help := func() { fmt.Println("") fmt.Printf("Usage: %s [option]\n", exename) fmt.Println("") fmt.Println("Options:") - flag.PrintDefaults() + flagSet.PrintDefaults() fmt.Println("") } - flag.Usage = help - flag.Parse() - + flagSet.Usage = help + args := flag.Args() + if len(args) > 1 { + flagSet.Parse(args) + } return err } diff --git a/app/descr/grant.go b/app/descr/grant.go index d10dc5a..aa3ad8b 100644 --- a/app/descr/grant.go +++ b/app/descr/grant.go @@ -32,12 +32,9 @@ type Grant struct { } const ( - // Accounts + // Accounts, grants RightReadAccounts = "readAccounts" // GetAccount, ListAccounts RightWriteAccounts = "writeAccounts" // CreateAccount, UpdateAccount, DeleteAccount - // Frants - RightReadGrants = "readGrants" // Like account operation - RightWriteGrants = "writeGrants" // Files RightWriteFiles = "writeFiles" // FileInfo, GetFile, ListFiles RightReadFiles = "readFiles" // PutFile, DeleteFile diff --git a/app/handler/grant.go b/app/handler/grant.go index 8e595fc..f669ec4 100644 --- a/app/handler/grant.go +++ b/app/handler/grant.go @@ -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.RightWriteGrants, "") + opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.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.RightReadGrants, "") + opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.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.RightReadGrants, "") + opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.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.RightWriteGrants, "") + opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.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.RightWriteGrants, "") + opEnable, err := hand.CheckRight(rctx.Ctx, operatorID, descr.RightWriteAccounts, "") if err != nil { err := fmt.Errorf("Operation error: %v", err) hand.SendError(rctx, err) diff --git a/app/maindb/init.go b/app/maindb/init.go index c9bcab4..aedeb9e 100644 --- a/app/maindb/init.go +++ b/app/maindb/init.go @@ -148,11 +148,11 @@ func (db *Database) WriteInituser(ctx context.Context) error { if err != nil { return err } - // Grants + // Images grantDescr = &descr.Grant{ ID: auxuuid.NewUUID(), AccountID: accountDescr.ID, - Right: descr.RightReadGrants, + Right: descr.RightReadImages, Pattern: ".*", CreatedAt: now, UpdatedAt: now, @@ -166,7 +166,7 @@ func (db *Database) WriteInituser(ctx context.Context) error { grantDescr = &descr.Grant{ ID: auxuuid.NewUUID(), AccountID: accountDescr.ID, - Right: descr.RightWriteGrants, + Right: descr.RightWriteImages, Pattern: ".*", CreatedAt: now, UpdatedAt: now, diff --git a/test/file_test.go b/test/file_test.go index 2c6218a..a441253 100644 --- a/test/file_test.go +++ b/test/file_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/require" ) -func xxxTestFileLife(t *testing.T) { +func TestFileLife(t *testing.T) { var srvport int64 = 10250 srvdir := t.TempDir() srvaddr := fmt.Sprintf("mstore:mstore@127.0.0.1:%d", srvport) diff --git a/test/image_test.go b/test/image_test.go index e003046..5546bc5 100644 --- a/test/image_test.go +++ b/test/image_test.go @@ -23,7 +23,7 @@ import ( "sigs.k8s.io/yaml" ) -func xxxTestImageLife(t *testing.T) { +func TestImageLife(t *testing.T) { var srvport int64 = 10250 srvdir := t.TempDir() srvaddr := fmt.Sprintf("mstore:mstore@127.0.0.1:%d", srvport) @@ -103,5 +103,4 @@ func xxxTestImageLife(t *testing.T) { err := cli.DeleteImage(ctx, srvaddr+"/foo/test:123") require.NoError(t, err) } - }