From a9526f73a201e401b068f8d53fc852c417574b6d 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: Thu, 12 Feb 2026 13:10:12 +0200 Subject: [PATCH] working commit --- app/server/server.go | 9 --- app/service/service.go | 8 ++- pkg/client/account.go | 2 +- pkg/client/grant.go | 146 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 11 deletions(-) create mode 100644 pkg/client/grant.go diff --git a/app/server/server.go b/app/server/server.go index 9d2bad4..dedae35 100644 --- a/app/server/server.go +++ b/app/server/server.go @@ -7,15 +7,6 @@ * Distribution of this work is permitted, but commercial use and * modifications are strictly prohibited. */ -/* - * 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. - */ /* * Это произведение распространяется под лицензией Creative Commons diff --git a/app/service/service.go b/app/service/service.go index 895d9ba..2f1a024 100644 --- a/app/service/service.go +++ b/app/service/service.go @@ -101,9 +101,15 @@ func (svc *Service) Build() error { svc.rout.Post(`/v3/account/create`, svc.hand.CreateAccount) svc.rout.Post(`/v3/account/get`, svc.hand.GetAccount) - svc.rout.Post(`/v3/accounts/list`, svc.hand.ListAccounts) svc.rout.Post(`/v3/account/update`, svc.hand.UpdateAccount) svc.rout.Post(`/v3/account/delete`, svc.hand.DeleteAccount) + svc.rout.Post(`/v3/accounts/list`, svc.hand.ListAccounts) + + svc.rout.Post(`/v3/grant/create`, svc.hand.CreateGrant) + svc.rout.Post(`/v3/grant/get`, svc.hand.GetGrant) + svc.rout.Post(`/v3/grant/update`, svc.hand.UpdateGrant) + svc.rout.Post(`/v3/grant/delete`, svc.hand.DeleteGrant) + svc.rout.Post(`/v3/grants/list`, svc.hand.ListGrants) svc.rout.NotFound(svc.hand.NotFound) diff --git a/pkg/client/account.go b/pkg/client/account.go index 41f09da..9a6157b 100644 --- a/pkg/client/account.go +++ b/pkg/client/account.go @@ -22,7 +22,7 @@ import ( func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, password string) error { var err error - apiuri, err := url.JoinPath(hosturi, "/v3/api/account/get") + apiuri, err := url.JoinPath(hosturi, "/v3/api/account/create") if err != nil { return err } diff --git a/pkg/client/grant.go b/pkg/client/grant.go new file mode 100644 index 0000000..70e5aad --- /dev/null +++ b/pkg/client/grant.go @@ -0,0 +1,146 @@ +/* + * 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 client + +import ( + "context" + "encoding/json" + "fmt" + "net/url" + + "mstore/app/handler" + "mstore/app/operator" +) + +func (cli *Client) CreateGrant(ctx context.Context, hosturi, accountID, operation, pattern string) error { + var err error + + apiuri, err := url.JoinPath(hosturi, "/v3/api/grant/create") + if err != nil { + return err + } + operParams := operator.CreateGrantParams{ + AccountID: accountID, + Operation: operation, + Pattern: pattern, + } + paramsJson, err := json.Marshal(operParams) + if err != nil { + return err + } + respBytes, err := doHTTPCall(ctx, apiuri, paramsJson) + if err != nil { + return err + } + + operRes := handler.NewResponse[operator.CreateGrantResult]() + err = json.Unmarshal(respBytes, operRes) + if err != nil { + return err + } + if !operRes.Error { + err = fmt.Errorf("%s", operRes.Message) + return err + } + return err +} + +func (cli *Client) GetGrant(ctx context.Context, hosturi, id, username string) error { + var err error + + apipath, err := url.JoinPath(hosturi, "/v3/api/grant/get") + if err != nil { + return err + } + operParams := operator.GetGrantParams{ + GrantID: id, + } + paramsJson, err := json.Marshal(operParams) + if err != nil { + return err + } + respBytes, err := doHTTPCall(ctx, apipath, paramsJson) + if err != nil { + return err + } + + operRes := handler.NewResponse[operator.GetGrantResult]() + err = json.Unmarshal(respBytes, operRes) + if err != nil { + return err + } + if !operRes.Error { + err = fmt.Errorf("%s", operRes.Message) + return err + } + return err +} + +func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern string) error { + var err error + + apipath, err := url.JoinPath(hosturi, "/v3/api/grant/update") + if err != nil { + return err + } + operParams := operator.UpdateGrantParams{ + GrantID: grantID, + NewPattern: newPattern, + } + paramsJson, err := json.Marshal(operParams) + if err != nil { + return err + } + respBytes, err := doHTTPCall(ctx, apipath, paramsJson) + if err != nil { + return err + } + operRes := handler.NewResponse[operator.UpdateGrantResult]() + err = json.Unmarshal(respBytes, operRes) + if err != nil { + return err + } + if !operRes.Error { + err = fmt.Errorf("%s", operRes.Message) + return err + } + return err +} + +func (cli *Client) DeleteGrant(ctx context.Context, hosturi, grantID string) error { + var err error + + apipath, err := url.JoinPath(hosturi, "/v3/api/grant/delete") + if err != nil { + return err + } + operParams := operator.DeleteGrantParams{ + GrantID: grantID, + } + paramsJson, err := json.Marshal(operParams) + if err != nil { + return err + } + respBytes, err := doHTTPCall(ctx, apipath, paramsJson) + if err != nil { + return err + } + + operRes := handler.NewResponse[operator.DeleteGrantResult]() + err = json.Unmarshal(respBytes, operRes) + if err != nil { + return err + } + if !operRes.Error { + err = fmt.Errorf("%s", operRes.Message) + return err + } + return err +}