From db67a117f01c8fd43c41a3f3be0234c4b439a6e7 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 25 May 2021 18:34:56 +0300 Subject: [PATCH] [#525] morph/container: Accept container session token in Put `Put` method of latest `Container` contract accepts binary session token as an argument. Provide `PutArgs.SetSessionToken` method. Accept session token as a `[]byte` in `Wrapper.Put` method and attach it to `PutArgs`. Marshal session token from container in `wrapper.Put` function and pass it to the method. Signed-off-by: Leonard Lyubich --- .../processors/container/process_container.go | 2 +- pkg/morph/client/container/put.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 1c4fb5206..d7b0a24ba 100644 --- a/pkg/innerring/processors/container/process_container.go +++ b/pkg/innerring/processors/container/process_container.go @@ -66,7 +66,7 @@ func (cp *Processor) checkPutContainer(e *containerEvent.Put) error { func (cp *Processor) approvePutContainer(e *containerEvent.Put) { // FIXME: here we should bind key to owner if needed - err := cp.cnrClient.Put(e.Container(), e.PublicKey(), e.Signature()) + err := cp.cnrClient.Put(e.Container(), e.PublicKey(), e.Signature(), nil) if err != nil { cp.log.Error("could not approve put container", zap.String("error", err.Error()), diff --git a/pkg/morph/client/container/put.go b/pkg/morph/client/container/put.go index 4c6060ac3..5b53c762a 100644 --- a/pkg/morph/client/container/put.go +++ b/pkg/morph/client/container/put.go @@ -36,6 +36,13 @@ func (p *PutArgs) SetSignature(v []byte) { p.sig = v } +// SetSessionToken sets token of the session +// within which the container was created +// in a binary format. +func (p *PutArgs) SetSessionToken(v []byte) { + p.token = v +} + // Put invokes the call of put container method // of NeoFS Container contract. func (c *Client) Put(args PutArgs) error { diff --git a/pkg/morph/client/container/wrapper/container.go b/pkg/morph/client/container/wrapper/container.go index c922cac30..0abfe33a0 100644 --- a/pkg/morph/client/container/wrapper/container.go +++ b/pkg/morph/client/container/wrapper/container.go @@ -33,9 +33,14 @@ func Put(w *Wrapper, cnr *container.Container) (*cid.ID, error) { return nil, fmt.Errorf("can't marshal container: %w", err) } + binToken, err := cnr.SessionToken().Marshal() + if err != nil { + return nil, fmt.Errorf("could not marshal session token: %w", err) + } + sig := cnr.Signature() - err = w.Put(data, sig.Key(), sig.Sign()) + err = w.Put(data, sig.Key(), sig.Sign(), binToken) if err != nil { return nil, err } @@ -46,14 +51,14 @@ func Put(w *Wrapper, cnr *container.Container) (*cid.ID, error) { return id, nil } -// Put saves binary container with its key and signature +// Put saves binary container with its session token, key and signature // in NeoFS system through Container contract call. // // Returns calculated container identifier and any error // encountered that caused the saving to interrupt. // // If TryNotary is provided, call notary contract. -func (w *Wrapper) Put(cnr, key, sig []byte) error { +func (w *Wrapper) Put(cnr, key, sig, token []byte) error { if len(sig) == 0 || len(key) == 0 { return errNilArgument } @@ -63,6 +68,7 @@ func (w *Wrapper) Put(cnr, key, sig []byte) error { args.SetContainer(cnr) args.SetSignature(sig) args.SetPublicKey(key) + args.SetSessionToken(token) err := w.client.Put(args) if err != nil {