[#323] client: Refactor object.Head

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-08-25 13:42:43 +03:00 committed by fyrchik
parent 02bc2bc236
commit dd5826d071

View file

@ -13,6 +13,7 @@ import (
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc" rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client" "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
v2session "github.com/nspcc-dev/neofs-api-go/v2/session" v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
"github.com/nspcc-dev/neofs-api-go/v2/signature"
"github.com/nspcc-dev/neofs-sdk-go/bearer" "github.com/nspcc-dev/neofs-sdk-go/bearer"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
@ -427,51 +428,49 @@ func (c *Client) ObjectHead(ctx context.Context, prm PrmObjectHead) (*ResObjectH
panic(panicMsgMissingObject) panic(panicMsgMissingObject)
} }
// form request body
var body v2object.HeadRequestBody var body v2object.HeadRequestBody
body.SetRaw(prm.raw) body.SetRaw(prm.raw)
body.SetAddress(&prm.addr) body.SetAddress(&prm.addr)
// form request
var req v2object.HeadRequest var req v2object.HeadRequest
req.SetBody(&body) req.SetBody(&body)
req.SetMetaHeader(&prm.meta) c.prepareRequest(&req, &prm.meta)
// init call context key := c.prm.key
if prm.keySet {
key = prm.key
}
var ( // sign the request
cc contextCall err := signature.SignServiceMessage(&key, req)
res ResObjectHead if err != nil {
) return nil, fmt.Errorf("sign request: %w", err)
}
resp, err := rpcapi.HeadObject(&c.c, &req, client.WithContext(ctx))
if err != nil {
return nil, fmt.Errorf("write request: %w", err)
}
var res ResObjectHead
res.st, err = c.processResponse(resp)
if err != nil {
return nil, err
}
if !apistatus.IsSuccessful(res.st) {
return &res, nil
}
_ = res.idObj.ReadFromV2(*prm.addr.GetObjectID()) _ = res.idObj.ReadFromV2(*prm.addr.GetObjectID())
c.initCallContext(&cc) switch v := resp.GetBody().GetHeaderPart().(type) {
if prm.keySet { default:
cc.key = prm.key return nil, fmt.Errorf("unexpected header type %T", v)
} case *v2object.SplitInfo:
return nil, object.NewSplitInfoError(object.NewSplitInfoFromV2(v))
cc.req = &req case *v2object.HeaderWithSignature:
cc.statusRes = &res res.hdr = v
cc.call = func() (responseV2, error) {
return rpcapi.HeadObject(&c.c, &req, client.WithContext(ctx))
}
cc.result = func(r responseV2) {
switch v := r.(*v2object.HeadResponse).GetBody().GetHeaderPart().(type) {
default:
cc.err = fmt.Errorf("unexpected header type %T", v)
case *v2object.SplitInfo:
handleSplitInfo(&cc, v)
case *v2object.HeaderWithSignature:
res.hdr = v
}
}
// process call
if !cc.processCall() {
return nil, cc.err
} }
return &res, nil return &res, nil