From 631d7b0e07632ebcf960a3e3f9cd453ac606c1b5 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 26 May 2021 14:01:38 +0300 Subject: [PATCH] [#525] morph/container: Accept container session token in Delete `Delete` method of latest `Container` contract accepts binary session token as an argument. Provide `DeleteArgs.SetSessionToken` method. Accept session token as a `[]byte` in `Wrapper.Put` method and attach it to `PutArgs`. Marshal session token from `RemovalWitness` in `wrapper.Delete` function and pass it to the method. Signed-off-by: Leonard Lyubich --- .../processors/container/process_container.go | 2 +- pkg/morph/client/container/delete.go | 7 +++++++ pkg/morph/client/container/wrapper/container.go | 12 +++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/innerring/processors/container/process_container.go b/pkg/innerring/processors/container/process_container.go index d1756a8e5..d0b76033a 100644 --- a/pkg/innerring/processors/container/process_container.go +++ b/pkg/innerring/processors/container/process_container.go @@ -124,7 +124,7 @@ func (cp *Processor) checkDeleteContainer(e *containerEvent.Delete) error { func (cp *Processor) approveDeleteContainer(e *containerEvent.Delete) { // FIXME: here we should try notary invoke - err := cp.cnrClient.Delete(e.ContainerID(), e.Signature()) + err := cp.cnrClient.Delete(e.ContainerID(), e.Signature(), nil) if err != nil { cp.log.Error("could not approve delete container", zap.String("error", err.Error()), diff --git a/pkg/morph/client/container/delete.go b/pkg/morph/client/container/delete.go index 1556643e5..f6c4e7869 100644 --- a/pkg/morph/client/container/delete.go +++ b/pkg/morph/client/container/delete.go @@ -26,6 +26,13 @@ func (p *DeleteArgs) SetSignature(v []byte) { p.sig = v } +// SetSessionToken sets token of the session +// within which the container was removed +// in a NeoFS API binary format. +func (p *DeleteArgs) SetSessionToken(v []byte) { + p.token = v +} + // Delete invokes the call of delete container // method of NeoFS Container contract. func (c *Client) Delete(args DeleteArgs) error { diff --git a/pkg/morph/client/container/wrapper/container.go b/pkg/morph/client/container/wrapper/container.go index e92d0f96b..0c53ebac4 100644 --- a/pkg/morph/client/container/wrapper/container.go +++ b/pkg/morph/client/container/wrapper/container.go @@ -150,7 +150,7 @@ func (w *Wrapper) Get(cid []byte) (*container.Container, error) { } // Delete marshals container ID, and passes it to Wrapper's Delete method -// along with signature. +// along with signature and session token. // // Returns error if container ID is nil. func Delete(w *Wrapper, witness core.RemovalWitness) error { @@ -159,7 +159,12 @@ func Delete(w *Wrapper, witness core.RemovalWitness) error { return errNilArgument } - return w.Delete(id.ToV2().GetValue(), witness.Signature()) + binToken, err := witness.SessionToken().Marshal() + if err != nil { + return fmt.Errorf("could not marshal session token: %w", err) + } + + return w.Delete(id.ToV2().GetValue(), witness.Signature(), binToken) } // Delete removes the container from NeoFS system @@ -169,7 +174,7 @@ func Delete(w *Wrapper, witness core.RemovalWitness) error { // the removal to interrupt. // // If TryNotary is provided, calls notary contract. -func (w *Wrapper) Delete(cid, signature []byte) error { +func (w *Wrapper) Delete(cid, signature, token []byte) error { if len(signature) == 0 { return errNilArgument } @@ -178,6 +183,7 @@ func (w *Wrapper) Delete(cid, signature []byte) error { args.SetSignature(signature) args.SetCID(cid) + args.SetSessionToken(token) return w.client.Delete(args) }