[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-25 18:34:56 +03:00 committed by Leonard Lyubich
parent 1deb3f3d01
commit db67a117f0
3 changed files with 17 additions and 4 deletions

View file

@ -66,7 +66,7 @@ func (cp *Processor) checkPutContainer(e *containerEvent.Put) error {
func (cp *Processor) approvePutContainer(e *containerEvent.Put) { func (cp *Processor) approvePutContainer(e *containerEvent.Put) {
// FIXME: here we should bind key to owner if needed // 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 { if err != nil {
cp.log.Error("could not approve put container", cp.log.Error("could not approve put container",
zap.String("error", err.Error()), zap.String("error", err.Error()),

View file

@ -36,6 +36,13 @@ func (p *PutArgs) SetSignature(v []byte) {
p.sig = v 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 // Put invokes the call of put container method
// of NeoFS Container contract. // of NeoFS Container contract.
func (c *Client) Put(args PutArgs) error { func (c *Client) Put(args PutArgs) error {

View file

@ -33,9 +33,14 @@ func Put(w *Wrapper, cnr *container.Container) (*cid.ID, error) {
return nil, fmt.Errorf("can't marshal container: %w", err) 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() sig := cnr.Signature()
err = w.Put(data, sig.Key(), sig.Sign()) err = w.Put(data, sig.Key(), sig.Sign(), binToken)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -46,14 +51,14 @@ func Put(w *Wrapper, cnr *container.Container) (*cid.ID, error) {
return id, nil 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. // in NeoFS system through Container contract call.
// //
// Returns calculated container identifier and any error // Returns calculated container identifier and any error
// encountered that caused the saving to interrupt. // encountered that caused the saving to interrupt.
// //
// If TryNotary is provided, call notary contract. // 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 { if len(sig) == 0 || len(key) == 0 {
return errNilArgument return errNilArgument
} }
@ -63,6 +68,7 @@ func (w *Wrapper) Put(cnr, key, sig []byte) error {
args.SetContainer(cnr) args.SetContainer(cnr)
args.SetSignature(sig) args.SetSignature(sig)
args.SetPublicKey(key) args.SetPublicKey(key)
args.SetSessionToken(token)
err := w.client.Put(args) err := w.client.Put(args)
if err != nil { if err != nil {