[#106] Pass bearer token through generated requests

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-20 16:44:45 +03:00 committed by Alex Vanin
parent e6f04f7785
commit ae0dd9e051
8 changed files with 32 additions and 3 deletions

View file

@ -8,7 +8,8 @@ import (
type CommonPrm struct {
local bool
token *token.SessionToken
token *token.SessionToken
bearer *token.BearerToken
}
func (p *CommonPrm) WithLocalOnly(v bool) *CommonPrm {
@ -35,6 +36,14 @@ func (p *CommonPrm) WithSessionToken(token *token.SessionToken) *CommonPrm {
return p
}
func (p *CommonPrm) WithBearerToken(token *token.BearerToken) *CommonPrm {
if p != nil {
p.bearer = token
}
return p
}
func (p *CommonPrm) SessionToken() *token.SessionToken {
if p != nil {
return p.token
@ -43,13 +52,22 @@ func (p *CommonPrm) SessionToken() *token.SessionToken {
return nil
}
func (p *CommonPrm) BearerToken() *token.BearerToken {
if p != nil {
return p.bearer
}
return nil
}
func CommonPrmFromV2(req interface {
GetMetaHeader() *session.RequestMetaHeader
}) *CommonPrm {
meta := req.GetMetaHeader()
return &CommonPrm{
local: meta.GetTTL() <= 1, // FIXME: use constant
token: token.NewSessionTokenFromV2(meta.GetSessionToken()),
local: meta.GetTTL() <= 1, // FIXME: use constant
token: token.NewSessionTokenFromV2(meta.GetSessionToken()),
bearer: token.NewBearerTokenFromV2(meta.GetBearerToken()),
}
}