forked from TrueCloudLab/frostfs-sdk-go
[#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"
|
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"
|
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"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
||||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||||
frostfscrypto "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto"
|
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
|
var req v2container.PutRequest
|
||||||
req.SetBody(reqBody)
|
req.SetBody(reqBody)
|
||||||
req.SetMetaHeader(&meta)
|
c.prepareRequest(&req, &meta)
|
||||||
return &req, nil
|
return &req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,40 +127,29 @@ func (c *Client) ContainerPut(ctx context.Context, prm PrmContainerPut) (*ResCon
|
||||||
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 ResContainerPut
|
resp, err := rpcapi.PutContainer(&c.c, req, client.WithContext(ctx))
|
||||||
)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
c.initCallContext(&cc)
|
}
|
||||||
cc.req = req
|
|
||||||
cc.statusRes = &res
|
var res ResContainerPut
|
||||||
cc.call = func() (responseV2, error) {
|
res.st, err = c.processResponse(resp)
|
||||||
return rpcapi.PutContainer(&c.c, req, client.WithContext(ctx))
|
if err != nil || !apistatus.IsSuccessful(res.st) {
|
||||||
|
return &res, err
|
||||||
}
|
}
|
||||||
cc.result = func(r responseV2) {
|
|
||||||
resp := r.(*v2container.PutResponse)
|
|
||||||
|
|
||||||
const fieldCnrID = "container ID"
|
const fieldCnrID = "container ID"
|
||||||
|
|
||||||
cidV2 := resp.GetBody().GetContainerID()
|
cidV2 := resp.GetBody().GetContainerID()
|
||||||
if cidV2 == nil {
|
if cidV2 == nil {
|
||||||
cc.err = newErrMissingResponseField(fieldCnrID)
|
return &res, newErrMissingResponseField(fieldCnrID)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
if err := res.id.ReadFromV2(*cidV2); err != nil {
|
||||||
cc.err = res.id.ReadFromV2(*cidV2)
|
return &res, newErrInvalidResponseField(fieldCnrID, err)
|
||||||
if cc.err != nil {
|
|
||||||
cc.err = newErrInvalidResponseField(fieldCnrID, cc.err)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// process call
|
|
||||||
if !cc.processCall() {
|
|
||||||
return nil, cc.err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue