[#48] client: Refactor ContainerList()
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
b2c66cb99e
commit
8852b262f2
1 changed files with 21 additions and 28 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue