[#143] sdk/client: Add call option to set bearer token

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-09-15 13:46:56 +03:00 committed by Stanislav Bogatyrev
parent 96de0bd25a
commit 59033d330d

View file

@ -30,7 +30,7 @@ type (
ttl uint32 ttl uint32
epoch uint64 epoch uint64
session *token.SessionToken session *token.SessionToken
// add bearer token bearer *token.BearerToken
} }
clientOptions struct { clientOptions struct {
@ -107,6 +107,12 @@ func WithSession(token *token.SessionToken) CallOption {
}) })
} }
func WithBearer(token *token.BearerToken) CallOption {
return newFuncCallOption(func(option *callOptions) {
option.bearer = token
})
}
func v2MetaHeaderFromOpts(options callOptions) *v2session.RequestMetaHeader { func v2MetaHeaderFromOpts(options callOptions) *v2session.RequestMetaHeader {
meta := new(v2session.RequestMetaHeader) meta := new(v2session.RequestMetaHeader)
meta.SetVersion(options.version.ToV2()) meta.SetVersion(options.version.ToV2())
@ -120,6 +126,10 @@ func v2MetaHeaderFromOpts(options callOptions) *v2session.RequestMetaHeader {
meta.SetXHeaders(xhdrs) meta.SetXHeaders(xhdrs)
if options.bearer != nil {
meta.SetBearerToken(options.bearer.ToV2())
}
return meta return meta
} }