[#323] client: Refactor object.Delete

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

View file

@ -3,6 +3,7 @@ package client
import ( import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"fmt"
"github.com/nspcc-dev/neofs-api-go/v2/acl" "github.com/nspcc-dev/neofs-api-go/v2/acl"
v2object "github.com/nspcc-dev/neofs-api-go/v2/object" v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
@ -10,7 +11,9 @@ 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"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/session"
@ -140,42 +143,43 @@ func (c *Client) ObjectDelete(ctx context.Context, prm PrmObjectDelete) (*ResObj
// form request // form request
var req v2object.DeleteRequest var req v2object.DeleteRequest
req.SetBody(&prm.body) req.SetBody(&prm.body)
req.SetMetaHeader(&prm.meta) c.prepareRequest(&req, &prm.meta)
// init call context key := c.prm.key
var (
cc contextCall
res ResObjectDelete
)
c.initCallContext(&cc)
if prm.keySet { if prm.keySet {
cc.key = prm.key key = prm.key
} }
cc.req = &req err := signature.SignServiceMessage(&key, req)
cc.statusRes = &res if err != nil {
cc.call = func() (responseV2, error) { return nil, fmt.Errorf("sign request: %w", err)
return rpcapi.DeleteObject(&c.c, &req, client.WithContext(ctx))
}
cc.result = func(r responseV2) {
const fieldTombstone = "tombstone"
idTombV2 := r.(*v2object.DeleteResponse).GetBody().GetTombstone().GetObjectID()
if idTombV2 == nil {
cc.err = newErrMissingResponseField(fieldTombstone)
return
}
cc.err = res.tomb.ReadFromV2(*idTombV2)
if cc.err != nil {
cc.err = newErrInvalidResponseField(fieldTombstone, cc.err)
}
} }
// process call resp, err := rpcapi.DeleteObject(&c.c, &req, client.WithContext(ctx))
if !cc.processCall() { if err != nil {
return nil, cc.err return nil, err
}
var res ResObjectDelete
res.st, err = c.processResponse(resp)
if err != nil {
return nil, err
}
if !apistatus.IsSuccessful(res.st) {
return &res, nil
}
const fieldTombstone = "tombstone"
idTombV2 := resp.GetBody().GetTombstone().GetObjectID()
if idTombV2 == nil {
return nil, newErrMissingResponseField(fieldTombstone)
}
err = res.tomb.ReadFromV2(*idTombV2)
if err != nil {
return nil, newErrInvalidResponseField(fieldTombstone, err)
} }
return &res, nil return &res, nil