[#48] client: Refactor ContainerPut()
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
57619fbbe4
commit
591dd1247d
1 changed files with 23 additions and 32 deletions
|
@ -9,6 +9,8 @@ import (
|
|||
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"
|
||||
frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto"
|
||||
|
@ -81,7 +83,7 @@ func (x *PrmContainerPut) formRequest(c *Client) (*v2container.PutRequest, error
|
|||
|
||||
var req v2container.PutRequest
|
||||
req.SetBody(reqBody)
|
||||
req.SetMetaHeader(&meta)
|
||||
c.prepareRequest(&req, &meta)
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
|
@ -125,40 +127,29 @@ func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResCon
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// init call context
|
||||
|
||||
var (
|
||||
cc contextCall
|
||||
res ResContainerPut
|
||||
)
|
||||
|
||||
c.initCallContext(&cc)
|
||||
cc.req = req
|
||||
cc.statusRes = &res
|
||||
cc.call = func() (responseV2, error) {
|
||||
return rpcapi.PutContainer(&c.c, req, client.WithContext(ctx))
|
||||
}
|
||||
cc.result = func(r responseV2) {
|
||||
resp := r.(*v2container.PutResponse)
|
||||
|
||||
const fieldCnrID = "container ID"
|
||||
|
||||
cidV2 := resp.GetBody().GetContainerID()
|
||||
if cidV2 == nil {
|
||||
cc.err = newErrMissingResponseField(fieldCnrID)
|
||||
return
|
||||
}
|
||||
|
||||
cc.err = res.id.ReadFromV2(*cidV2)
|
||||
if cc.err != nil {
|
||||
cc.err = newErrInvalidResponseField(fieldCnrID, 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.PutContainer(&c.c, req, client.WithContext(ctx))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var res ResContainerPut
|
||||
res.st, err = c.processResponse(resp)
|
||||
if err != nil || !apistatus.IsSuccessful(res.st) {
|
||||
return &res, err
|
||||
}
|
||||
|
||||
const fieldCnrID = "container ID"
|
||||
|
||||
cidV2 := resp.GetBody().GetContainerID()
|
||||
if cidV2 == nil {
|
||||
return &res, newErrMissingResponseField(fieldCnrID)
|
||||
}
|
||||
if err := res.id.ReadFromV2(*cidV2); err != nil {
|
||||
return &res, newErrInvalidResponseField(fieldCnrID, err)
|
||||
}
|
||||
return &res, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue