From 8852b262f29caa912e384ce6cbba577d1f746445 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 13 Apr 2023 08:55:01 +0300 Subject: [PATCH] [#48] client: Refactor ContainerList() Signed-off-by: Evgenii Stratonikov --- client/container_list.go | 49 +++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/client/container_list.go b/client/container_list.go index 6108c99..9274e30 100644 --- a/client/container_list.go +++ b/client/container_list.go @@ -8,6 +8,9 @@ import ( "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/user" ) @@ -27,7 +30,7 @@ func (x *PrmContainerList) SetAccount(id user.ID) { x.ownerSet = true } -func (x *PrmContainerList) formRequest(_ *Client) (*v2container.ListRequest, error) { +func (x *PrmContainerList) formRequest(c *Client) (*v2container.ListRequest, error) { if !x.ownerSet { return nil, errorAccountNotSet } @@ -40,6 +43,7 @@ func (x *PrmContainerList) formRequest(_ *Client) (*v2container.ListRequest, err var req v2container.ListRequest req.SetBody(reqBody) + c.prepareRequest(&req, new(v2session.RequestMetaHeader)) return &req, nil } @@ -76,38 +80,27 @@ func (c *Client) ContainerList(ctx context.Context, prm PrmContainerList) (*ResC return nil, err } - // init call context - - var ( - cc contextCall - res ResContainerList - ) - - c.initCallContext(&cc) - cc.meta = prm.prmCommonMeta - cc.req = req - cc.statusRes = &res - cc.call = func() (responseV2, error) { - return rpcapi.ListContainers(&c.c, req, client.WithContext(ctx)) + if err := signature.SignServiceMessage(&c.prm.key, req); err != nil { + return nil, fmt.Errorf("sign request: %w", err) } - cc.result = func(r responseV2) { - resp := r.(*v2container.ListResponse) - res.ids = make([]cid.ID, len(resp.GetBody().GetContainerIDs())) + resp, err := rpcapi.ListContainers(&c.c, req, client.WithContext(ctx)) + if err != nil { + return nil, err + } - for i, cidV2 := range resp.GetBody().GetContainerIDs() { - cc.err = res.ids[i].ReadFromV2(cidV2) - if cc.err != nil { - cc.err = fmt.Errorf("invalid ID in the response: %w", cc.err) - return - } + var res ResContainerList + res.st, err = c.processResponse(resp) + if err != nil || !apistatus.IsSuccessful(res.st) { + return &res, err + } + + res.ids = make([]cid.ID, len(resp.GetBody().GetContainerIDs())) + for i, cidV2 := range resp.GetBody().GetContainerIDs() { + if err := res.ids[i].ReadFromV2(cidV2); err != nil { + return &res, fmt.Errorf("invalid ID in the response: %w", err) } } - // process call - if !cc.processCall() { - return nil, cc.err - } - return &res, nil }