[#57] services/object: Add session token to common parameters

Add session token field to CommonPrm. Remove session token field from Put
parameters.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-29 18:08:16 +03:00 committed by Alex Vanin
parent 39c17253be
commit 2da323c4b9
3 changed files with 25 additions and 14 deletions

View file

@ -1,7 +1,6 @@
package putsvc package putsvc
import ( import (
"github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/core/object"
"github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/services/object/util"
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/placement"
@ -12,8 +11,6 @@ type PutInitPrm struct {
hdr *object.RawObject hdr *object.RawObject
token *token.SessionToken
traverseOpts []placement.Option traverseOpts []placement.Option
} }
@ -37,14 +34,6 @@ func (p *PutInitPrm) WithObject(v *object.RawObject) *PutInitPrm {
return p return p
} }
func (p *PutInitPrm) WithSession(v *token.SessionToken) *PutInitPrm {
if p != nil {
p.token = v
}
return p
}
func (p *PutChunkPrm) WithChunk(v []byte) *PutChunkPrm { func (p *PutChunkPrm) WithChunk(v []byte) *PutChunkPrm {
if p != nil { if p != nil {
p.chunk = v p.chunk = v

View file

@ -48,7 +48,9 @@ func (p *Streamer) initTarget(prm *PutInitPrm) error {
return errors.Wrapf(err, "(%T) could not prepare put parameters", p) return errors.Wrapf(err, "(%T) could not prepare put parameters", p)
} }
if prm.token == nil { sToken := prm.common.SessionToken()
if sToken == nil {
// prepare untrusted-Put object target // prepare untrusted-Put object target
p.target = &validatingTarget{ p.target = &validatingTarget{
nextTarget: p.newCommonTarget(prm), nextTarget: p.newCommonTarget(prm),
@ -61,7 +63,7 @@ func (p *Streamer) initTarget(prm *PutInitPrm) error {
// prepare trusted-Put object target // prepare trusted-Put object target
// get private token from local storage // get private token from local storage
pToken := p.tokenStore.Get(prm.token.OwnerID(), prm.token.ID()) pToken := p.tokenStore.Get(sToken.OwnerID(), sToken.ID())
if pToken == nil { if pToken == nil {
return errPrivateTokenNotFound return errPrivateTokenNotFound
} }
@ -69,7 +71,7 @@ func (p *Streamer) initTarget(prm *PutInitPrm) error {
p.target = transformer.NewPayloadSizeLimiter( p.target = transformer.NewPayloadSizeLimiter(
p.maxSizeSrc.MaxObjectSize(), p.maxSizeSrc.MaxObjectSize(),
func() transformer.ObjectTarget { func() transformer.ObjectTarget {
return transformer.NewFormatTarget(pToken.SessionKey(), p.newCommonTarget(prm), prm.token) return transformer.NewFormatTarget(pToken.SessionKey(), p.newCommonTarget(prm), sToken)
}, },
) )

View file

@ -1,11 +1,14 @@
package util package util
import ( import (
"github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-api-go/v2/session"
) )
type CommonPrm struct { type CommonPrm struct {
local bool local bool
token *token.SessionToken
} }
func (p *CommonPrm) WithLocalOnly(v bool) *CommonPrm { func (p *CommonPrm) WithLocalOnly(v bool) *CommonPrm {
@ -24,6 +27,22 @@ func (p *CommonPrm) LocalOnly() bool {
return false return false
} }
func (p *CommonPrm) WithSessionToken(token *token.SessionToken) *CommonPrm {
if p != nil {
p.token = token
}
return p
}
func (p *CommonPrm) SessionToken() *token.SessionToken {
if p != nil {
return p.token
}
return nil
}
func CommonPrmFromV2(req interface { func CommonPrmFromV2(req interface {
GetMetaHeader() *session.RequestMetaHeader GetMetaHeader() *session.RequestMetaHeader
}) *CommonPrm { }) *CommonPrm {
@ -31,5 +50,6 @@ func CommonPrmFromV2(req interface {
return &CommonPrm{ return &CommonPrm{
local: meta.GetTTL() <= 1, // FIXME: use constant local: meta.GetTTL() <= 1, // FIXME: use constant
token: token.NewSessionTokenFromV2(meta.GetSessionToken()),
} }
} }