[#505] morph/container: Change delete container API

Make `Delete` method of the wrapper over Container contract's client to accept
two binary parameters: container ID and signature. Create `Delete` function
similar to the previous `Delete` variation, but accepting `Signature`
structure instead of binary signature. Use this function in Container
service server in the place where `Delete` method was used.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-19 18:57:08 +03:00 committed by Alex Vanin
parent 24ad60e1c8
commit e3b4c9eda0
2 changed files with 19 additions and 11 deletions

View file

@ -109,25 +109,32 @@ func (w *Wrapper) Get(cid *container.ID) (*container.Container, error) {
return cnr, nil return cnr, nil
} }
// Delete marshals container ID, and passes it to Wrapper's Delete method
// along with sig.Key() and sig.Sign().
//
// Returns error if cid is nil.
func Delete(w *Wrapper, cid *container.ID, sig *pkg.Signature) error {
if cid == nil {
return errNilArgument
}
return w.Delete(cid.ToV2().GetValue(), sig.Sign())
}
// Delete removes the container from NeoFS system // Delete removes the container from NeoFS system
// through Container contract call. // through Container contract call.
// //
// Returns any error encountered that caused // Returns any error encountered that caused
// the removal to interrupt. // the removal to interrupt.
func (w *Wrapper) Delete(cid *container.ID, signature []byte) error { func (w *Wrapper) Delete(cid, signature []byte) error {
if cid == nil || len(signature) == 0 { if len(signature) == 0 {
return errNilArgument return errNilArgument
} }
args := client.DeleteArgs{} var args client.DeleteArgs
args.SetSignature(signature) args.SetSignature(signature)
args.SetCID(cid)
v2 := cid.ToV2()
if v2 == nil {
return errUnsupported // use other major version if there any
}
args.SetCID(v2.GetValue())
return w.client.Delete(args) return w.client.Delete(args)
} }

View file

@ -45,8 +45,9 @@ func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody)
func (s *morphExecutor) Delete(ctx context.Context, body *container.DeleteRequestBody) (*container.DeleteResponseBody, error) { func (s *morphExecutor) Delete(ctx context.Context, body *container.DeleteRequestBody) (*container.DeleteResponseBody, error) {
cid := containerSDK.NewIDFromV2(body.GetContainerID()) cid := containerSDK.NewIDFromV2(body.GetContainerID())
sig := pkg.NewSignatureFromV2(body.GetSignature())
err := s.wrapper.Delete(cid, body.GetSignature().GetSign()) err := wrapper.Delete(s.wrapper, cid, sig)
if err != nil { if err != nil {
return nil, err return nil, err
} }