[#48] client: Refactor ContainerEACL()

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-04-13 09:00:00 +03:00
parent 8e2f77890f
commit 09ed2863fc

View file

@ -2,11 +2,15 @@ package client
import ( import (
"context" "context"
"fmt"
v2container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" v2container "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc" rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" "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" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/eacl"
) )
@ -39,6 +43,7 @@ func (x *PrmContainerEACL) formRequest(c *Client) (*v2container.GetExtendedACLRe
var req v2container.GetExtendedACLRequest var req v2container.GetExtendedACLRequest
req.SetBody(reqBody) req.SetBody(reqBody)
c.prepareRequest(&req, new(v2session.RequestMetaHeader))
return &req, nil return &req, nil
} }
@ -75,36 +80,26 @@ func (c *Client) ContainerEACL(ctx context.Context, prm PrmContainerEACL) (*ResC
return nil, err return nil, err
} }
// init call context if err := signature.SignServiceMessage(&c.prm.key, req); err != nil {
return nil, fmt.Errorf("sign request: %w", err)
var ( }
cc contextCall
res ResContainerEACL resp, err := rpcapi.GetEACL(&c.c, req, client.WithContext(ctx))
) if err != nil {
return nil, err
c.initCallContext(&cc) }
cc.meta = prm.prmCommonMeta
cc.req = req var res ResContainerEACL
cc.statusRes = &res res.st, err = c.processResponse(resp)
cc.call = func() (responseV2, error) { if err != nil || !apistatus.IsSuccessful(res.st) {
return rpcapi.GetEACL(&c.c, req, client.WithContext(ctx)) return &res, err
} }
cc.result = func(r responseV2) {
resp := r.(*v2container.GetExtendedACLResponse)
eACL := resp.GetBody().GetEACL() eACL := resp.GetBody().GetEACL()
if eACL == nil { if eACL == nil {
cc.err = newErrMissingResponseField("eACL") return &res, newErrMissingResponseField("eACL")
return
} }
res.table = *eacl.NewTableFromV2(eACL) res.table = *eacl.NewTableFromV2(eACL)
}
// process call
if !cc.processCall() {
return nil, cc.err
}
return &res, nil return &res, nil
} }