From e3b4c9eda0bc47de96c82020675080745651ab35 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 19 May 2021 18:57:08 +0300 Subject: [PATCH] [#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 --- .../client/container/wrapper/container.go | 27 ++++++++++++------- pkg/services/container/morph/executor.go | 3 ++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pkg/morph/client/container/wrapper/container.go b/pkg/morph/client/container/wrapper/container.go index 59baacfee..019726ce6 100644 --- a/pkg/morph/client/container/wrapper/container.go +++ b/pkg/morph/client/container/wrapper/container.go @@ -109,25 +109,32 @@ func (w *Wrapper) Get(cid *container.ID) (*container.Container, error) { 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 // through Container contract call. // // Returns any error encountered that caused // the removal to interrupt. -func (w *Wrapper) Delete(cid *container.ID, signature []byte) error { - if cid == nil || len(signature) == 0 { +func (w *Wrapper) Delete(cid, signature []byte) error { + if len(signature) == 0 { return errNilArgument } - args := client.DeleteArgs{} + var args client.DeleteArgs + args.SetSignature(signature) - - v2 := cid.ToV2() - if v2 == nil { - return errUnsupported // use other major version if there any - } - - args.SetCID(v2.GetValue()) + args.SetCID(cid) return w.client.Delete(args) } diff --git a/pkg/services/container/morph/executor.go b/pkg/services/container/morph/executor.go index 3e4baed33..e6801e028 100644 --- a/pkg/services/container/morph/executor.go +++ b/pkg/services/container/morph/executor.go @@ -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) { 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 { return nil, err }