forked from TrueCloudLab/frostfs-sdk-go
[#48] client: Refactor ContainerGet()
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
8852b262f2
commit
8e2f77890f
1 changed files with 23 additions and 31 deletions
|
@ -9,6 +9,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"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
)
|
||||
|
@ -28,7 +31,7 @@ func (x *PrmContainerGet) SetContainer(id cid.ID) {
|
|||
x.idSet = true
|
||||
}
|
||||
|
||||
func (x *PrmContainerGet) formRequest(_ *Client) (*v2container.GetRequest, error) {
|
||||
func (x *PrmContainerGet) formRequest(c *Client) (*v2container.GetRequest, error) {
|
||||
if !x.idSet {
|
||||
return nil, errorMissingContainer
|
||||
}
|
||||
|
@ -41,6 +44,7 @@ func (x *PrmContainerGet) formRequest(_ *Client) (*v2container.GetRequest, error
|
|||
|
||||
var req v2container.GetRequest
|
||||
req.SetBody(reqBody)
|
||||
c.prepareRequest(&req, new(v2session.RequestMetaHeader))
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
|
@ -78,39 +82,27 @@ func (c *Client) ContainerGet(ctx context.Context, prm PrmContainerGet) (*ResCon
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// init call context
|
||||
|
||||
var (
|
||||
cc contextCall
|
||||
res ResContainerGet
|
||||
)
|
||||
|
||||
c.initCallContext(&cc)
|
||||
cc.meta = prm.prmCommonMeta
|
||||
cc.req = req
|
||||
cc.statusRes = &res
|
||||
cc.call = func() (responseV2, error) {
|
||||
return rpcapi.GetContainer(&c.c, req, client.WithContext(ctx))
|
||||
}
|
||||
cc.result = func(r responseV2) {
|
||||
resp := r.(*v2container.GetResponse)
|
||||
|
||||
cnrV2 := resp.GetBody().GetContainer()
|
||||
if cnrV2 == nil {
|
||||
cc.err = errors.New("missing container in response")
|
||||
return
|
||||
}
|
||||
|
||||
cc.err = res.cnr.ReadFromV2(*cnrV2)
|
||||
if cc.err != nil {
|
||||
cc.err = fmt.Errorf("invalid container in response: %w", cc.err)
|
||||
}
|
||||
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.GetContainer(&c.c, req, client.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var res ResContainerGet
|
||||
res.st, err = c.processResponse(resp)
|
||||
if err != nil || !apistatus.IsSuccessful(res.st) {
|
||||
return &res, err
|
||||
}
|
||||
|
||||
cnrV2 := resp.GetBody().GetContainer()
|
||||
if cnrV2 == nil {
|
||||
return &res, errors.New("missing container in response")
|
||||
}
|
||||
if err := res.cnr.ReadFromV2(*cnrV2); err != nil {
|
||||
return &res, fmt.Errorf("invalid container in response: %w", err)
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue