Skip to content

Commit

Permalink
[#323] client: Refactor object.Delete
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Stratonikov <[email protected]>
  • Loading branch information
fyrchik committed Aug 26, 2022
1 parent dd5826d commit f543ba6
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions client/object_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package client
import (
"context"
"crypto/ecdsa"
"fmt"

"github.com/nspcc-dev/neofs-api-go/v2/acl"
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
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"
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/session"
Expand Down Expand Up @@ -140,42 +143,43 @@ func (c *Client) ObjectDelete(ctx context.Context, prm PrmObjectDelete) (*ResObj
// form request
var req v2object.DeleteRequest
req.SetBody(&prm.body)
req.SetMetaHeader(&prm.meta)
c.prepareRequest(&req, &prm.meta)

// init call context
var (
cc contextCall
res ResObjectDelete
)

c.initCallContext(&cc)
key := c.prm.key
if prm.keySet {
cc.key = prm.key
key = prm.key
}

err := signature.SignServiceMessage(&key, req)
if err != nil {
return nil, fmt.Errorf("sign request: %w", err)
}

resp, err := rpcapi.DeleteObject(&c.c, &req, client.WithContext(ctx))
if err != nil {
return nil, err
}

cc.req = &req
cc.statusRes = &res
cc.call = func() (responseV2, error) {
return rpcapi.DeleteObject(&c.c, &req, client.WithContext(ctx))
var res ResObjectDelete
res.st, err = c.processResponse(resp)
if err != nil {
return nil, err
}
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)
}

if !apistatus.IsSuccessful(res.st) {
return &res, nil
}

const fieldTombstone = "tombstone"

idTombV2 := resp.GetBody().GetTombstone().GetObjectID()
if idTombV2 == nil {
return nil, newErrMissingResponseField(fieldTombstone)
}

// process call
if !cc.processCall() {
return nil, cc.err
err = res.tomb.ReadFromV2(*idTombV2)
if err != nil {
return nil, newErrInvalidResponseField(fieldTombstone, err)
}

return &res, nil
Expand Down

0 comments on commit f543ba6

Please sign in to comment.