[#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 <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-14 20:06:05 +03:00 committed by Alex Vanin
parent d3e3889425
commit 7b3736567c
2 changed files with 16 additions and 1 deletions

View file

@ -1006,7 +1006,14 @@ func (c Client) attachV2SessionToken(opts callOptions, hdr *v2session.RequestMet
return nil 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 := new(v2session.ObjectSessionContext)
opCtx.SetAddress(info.addr) opCtx.SetAddress(info.addr)

View file

@ -1,6 +1,7 @@
package token package token
import ( 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/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-api-go/v2/session"
) )
@ -68,3 +69,10 @@ func (t *SessionToken) SetSessionKey(v []byte) {
body.SetSessionKey(v) body.SetSessionKey(v)
}) })
} }
func (t *SessionToken) Signature() *pkg.Signature {
return pkg.NewSignatureFromV2(
(*session.SessionToken)(t).
GetSignature(),
)
}