From 4a56f825711e65820d3ac92e531bb522fcc7791d Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 21 Oct 2020 18:10:22 +0300 Subject: [PATCH] [#60] object/transformer: Group parameters of NewFormatTarget func Signed-off-by: Leonard Lyubich --- pkg/services/object/put/streamer.go | 6 +++- .../object_manager/transformer/fmt.go | 33 ++++++++++--------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index a8c26d53f8..3fe7c946ae 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -69,7 +69,11 @@ func (p *Streamer) initTarget(prm *PutInitPrm) error { p.target = transformer.NewPayloadSizeLimiter( p.maxSizeSrc.MaxObjectSize(), func() transformer.ObjectTarget { - return transformer.NewFormatTarget(sessionKey, p.newCommonTarget(prm), sToken) + return transformer.NewFormatTarget(&transformer.FormatterParams{ + Key: sessionKey, + NextTarget: p.newCommonTarget(prm), + SessionToken: sToken, + }) }, ) diff --git a/pkg/services/object_manager/transformer/fmt.go b/pkg/services/object_manager/transformer/fmt.go index af36780058..5336228cfd 100644 --- a/pkg/services/object_manager/transformer/fmt.go +++ b/pkg/services/object_manager/transformer/fmt.go @@ -11,15 +11,20 @@ import ( ) type formatter struct { - nextTarget ObjectTarget - - key *ecdsa.PrivateKey + prm *FormatterParams obj *object.RawObject sz uint64 +} - token *token.SessionToken +// FormatterParams groups NewFormatTarget parameters. +type FormatterParams struct { + Key *ecdsa.PrivateKey + + NextTarget ObjectTarget + + SessionToken *token.SessionToken } // NewFormatTarget returns ObjectTarget instance that finalizes object structure @@ -32,11 +37,9 @@ type formatter struct { // - 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, token *token.SessionToken) ObjectTarget { +func NewFormatTarget(p *FormatterParams) ObjectTarget { return &formatter{ - nextTarget: nextTarget, - key: key, - token: token, + prm: p, } } @@ -47,7 +50,7 @@ func (f *formatter) WriteHeader(obj *object.RawObject) error { } func (f *formatter) Write(p []byte) (n int, err error) { - n, err = f.nextTarget.Write(p) + n, err = f.prm.NextTarget.Write(p) f.sz += uint64(n) @@ -57,16 +60,16 @@ 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) + f.obj.SetSessionToken(f.prm.SessionToken) var parID *objectSDK.ID if par := f.obj.GetParent(); par != nil { rawPar := objectSDK.NewRawFromV2(par.ToV2()) - rawPar.SetSessionToken(f.token) + rawPar.SetSessionToken(f.prm.SessionToken) - if err := objectSDK.SetIDWithSignature(f.key, rawPar); err != nil { + if err := objectSDK.SetIDWithSignature(f.prm.Key, rawPar); err != nil { return nil, errors.Wrap(err, "could not finalize parent object") } @@ -75,15 +78,15 @@ func (f *formatter) Close() (*AccessIdentifiers, error) { f.obj.SetParent(rawPar.Object()) } - if err := objectSDK.SetIDWithSignature(f.key, f.obj.SDK()); err != nil { + if err := objectSDK.SetIDWithSignature(f.prm.Key, f.obj.SDK()); err != nil { return nil, errors.Wrap(err, "could not finalize object") } - if err := f.nextTarget.WriteHeader(f.obj); err != nil { + if err := f.prm.NextTarget.WriteHeader(f.obj); err != nil { return nil, errors.Wrap(err, "could not write header to next target") } - if _, err := f.nextTarget.Close(); err != nil { + if _, err := f.prm.NextTarget.Close(); err != nil { return nil, errors.Wrap(err, "could not close next target") }