From 8cddbe58a65cb345e803cd4e1d854e47147c4607 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 29 Sep 2020 15:41:29 +0300 Subject: [PATCH] [#56] object/transformer: Write session token to object body Add session token argument to object formatter constructor which is written to the object. Pass session token from trusted object Put. Signed-off-by: Leonard Lyubich --- pkg/services/object/put/streamer.go | 2 +- pkg/services/object_manager/transformer/fmt.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index 7fbfda060..d1e33b433 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -69,7 +69,7 @@ func (p *Streamer) initTarget(prm *PutInitPrm) error { p.target = transformer.NewPayloadSizeLimiter( p.maxSizeSrc.MaxObjectSize(), func() transformer.ObjectTarget { - return transformer.NewFormatTarget(pToken.SessionKey(), p.newCommonTarget(prm)) + return transformer.NewFormatTarget(pToken.SessionKey(), p.newCommonTarget(prm), prm.token) }, ) diff --git a/pkg/services/object_manager/transformer/fmt.go b/pkg/services/object_manager/transformer/fmt.go index 411506153..2ee3565b1 100644 --- a/pkg/services/object_manager/transformer/fmt.go +++ b/pkg/services/object_manager/transformer/fmt.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/pkg/errors" ) @@ -17,6 +18,8 @@ type formatter struct { obj *object.RawObject sz uint64 + + token *token.SessionToken } // NewFormatTarget returns ObjectTarget instance that finalizes object structure @@ -27,11 +30,13 @@ type formatter struct { // Object changes: // - sets version to current SDK version; // - sets payload size to the total length of all written chunks; +// - sets session token; // - calculates and sets verification fields (ID, Signature). -func NewFormatTarget(key *ecdsa.PrivateKey, nextTarget ObjectTarget) ObjectTarget { +func NewFormatTarget(key *ecdsa.PrivateKey, nextTarget ObjectTarget, token *token.SessionToken) ObjectTarget { return &formatter{ nextTarget: nextTarget, key: key, + token: token, } } @@ -52,12 +57,15 @@ func (f *formatter) Write(p []byte) (n int, err error) { func (f *formatter) Close() (*AccessIdentifiers, error) { f.obj.SetVersion(pkg.SDKVersion()) f.obj.SetPayloadSize(f.sz) + f.obj.SetSessionToken(f.token) var parID *objectSDK.ID if par := f.obj.GetParent(); par != nil && par.ToV2().GetHeader() != nil { rawPar := objectSDK.NewRawFromV2(par.ToV2()) + rawPar.SetSessionToken(f.token) + if err := objectSDK.SetIDWithSignature(f.key, rawPar); err != nil { return nil, errors.Wrap(err, "could not finalize parent object") }