From b2c66cb99ec4ec91730ce85523ed137c1a11a97b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 13 Apr 2023 08:52:14 +0300 Subject: [PATCH] [#48] client: Refactor ContainerAnnounceUsedSpace() Signed-off-by: Evgenii Stratonikov --- client/container_space.go | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/client/container_space.go b/client/container_space.go index 69dfc5e..d50944f 100644 --- a/client/container_space.go +++ b/client/container_space.go @@ -2,10 +2,13 @@ package client import ( "context" + "fmt" v2container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" 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" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container" ) @@ -39,6 +42,7 @@ func (x *PrmAnnounceSpace) formRequest(c *Client) (*v2container.AnnounceUsedSpac var req v2container.AnnounceUsedSpaceRequest req.SetBody(reqBody) + c.prepareRequest(&req, new(v2session.RequestMetaHeader)) return &req, nil } @@ -71,25 +75,16 @@ func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounce return nil, err } - // init call context - - var ( - cc contextCall - res ResAnnounceSpace - ) - - c.initCallContext(&cc) - cc.meta = prm.prmCommonMeta - cc.req = req - cc.statusRes = &res - cc.call = func() (responseV2, error) { - return rpcapi.AnnounceUsedSpace(&c.c, req, client.WithContext(ctx)) + 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.AnnounceUsedSpace(&c.c, req, client.WithContext(ctx)) + if err != nil { + return nil, err } - return &res, nil + var res ResAnnounceSpace + res.st, err = c.processResponse(resp) + return &res, err }