From 7b3736567c0b1eddc2c2122e58854a12b239b33f Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 14 Oct 2020 20:06:05 +0300 Subject: [PATCH] [#169] sdk/client: Do not resign session token In some cases SDK Client provided with signed and prepared session token. In this case we don't need to change verb or sign it. Signed-off-by: Alex Vanin --- pkg/client/object.go | 9 ++++++++- pkg/token/session.go | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/client/object.go b/pkg/client/object.go index 62fa701..1784af3 100644 --- a/pkg/client/object.go +++ b/pkg/client/object.go @@ -1006,7 +1006,14 @@ func (c Client) attachV2SessionToken(opts callOptions, hdr *v2session.RequestMet return nil } - token := opts.session.ToV2() + // Do not resign already prepared session token + if opts.session.Signature() != nil { + hdr.SetSessionToken(opts.session.ToV2()) + return nil + } + + token := new(v2session.SessionToken) + token.SetBody(opts.session.ToV2().GetBody()) opCtx := new(v2session.ObjectSessionContext) opCtx.SetAddress(info.addr) diff --git a/pkg/token/session.go b/pkg/token/session.go index 6ff3753..d9e1c47 100644 --- a/pkg/token/session.go +++ b/pkg/token/session.go @@ -1,6 +1,7 @@ package token import ( + "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/v2/session" ) @@ -68,3 +69,10 @@ func (t *SessionToken) SetSessionKey(v []byte) { body.SetSessionKey(v) }) } + +func (t *SessionToken) Signature() *pkg.Signature { + return pkg.NewSignatureFromV2( + (*session.SessionToken)(t). + GetSignature(), + ) +}