From 09ed2863fcb5efb0705dbf4b81bd823624b22b9a Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 13 Apr 2023 09:00:00 +0300 Subject: [PATCH] [#48] client: Refactor ContainerEACL() Signed-off-by: Evgenii Stratonikov --- client/container_eacl.go | 49 ++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/client/container_eacl.go b/client/container_eacl.go index acd07786..187a5f63 100644 --- a/client/container_eacl.go +++ b/client/container_eacl.go @@ -2,11 +2,15 @@ package client import ( "context" + "fmt" v2container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" + v2session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/signature" + apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl" ) @@ -39,6 +43,7 @@ func (x *PrmContainerEACL) formRequest(c *Client) (*v2container.GetExtendedACLRe var req v2container.GetExtendedACLRequest req.SetBody(reqBody) + c.prepareRequest(&req, new(v2session.RequestMetaHeader)) return &req, nil } @@ -75,36 +80,26 @@ func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResC return nil, err } - // init call context - - var ( - cc contextCall - res ResContainerEACL - ) - - c.initCallContext(&cc) - cc.meta = prm.prmCommonMeta - cc.req = req - cc.statusRes = &res - cc.call = func() (responseV2, error) { - return rpcapi.GetEACL(&c.c, req, client.WithContext(ctx)) - } - cc.result = func(r responseV2) { - resp := r.(*v2container.GetExtendedACLResponse) - - eACL := resp.GetBody().GetEACL() - if eACL == nil { - cc.err = newErrMissingResponseField("eACL") - return - } - - res.table = *eacl.NewTableFromV2(eACL) + if err := signature.SignServiceMessage(&c.prm.key, req); err != nil { + return nil, fmt.Errorf("sign request: %w", err) } - // process call - if !cc.processCall() { - return nil, cc.err + resp, err := rpcapi.GetEACL(&c.c, req, client.WithContext(ctx)) + if err != nil { + return nil, err } + var res ResContainerEACL + res.st, err = c.processResponse(resp) + if err != nil || !apistatus.IsSuccessful(res.st) { + return &res, err + } + + eACL := resp.GetBody().GetEACL() + if eACL == nil { + return &res, newErrMissingResponseField("eACL") + } + + res.table = *eacl.NewTableFromV2(eACL) return &res, nil }