2020-09-29 15:05:22 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2020-09-29 15:08:16 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
2020-09-29 15:05:22 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CommonPrm struct {
|
|
|
|
local bool
|
2020-09-29 15:08:16 +00:00
|
|
|
|
2020-10-20 13:44:45 +00:00
|
|
|
token *token.SessionToken
|
|
|
|
bearer *token.BearerToken
|
2020-09-29 15:05:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *CommonPrm) WithLocalOnly(v bool) *CommonPrm {
|
|
|
|
if p != nil {
|
|
|
|
p.local = v
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *CommonPrm) LocalOnly() bool {
|
|
|
|
if p != nil {
|
|
|
|
return p.local
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:08:16 +00:00
|
|
|
func (p *CommonPrm) WithSessionToken(token *token.SessionToken) *CommonPrm {
|
|
|
|
if p != nil {
|
|
|
|
p.token = token
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-10-20 13:44:45 +00:00
|
|
|
func (p *CommonPrm) WithBearerToken(token *token.BearerToken) *CommonPrm {
|
|
|
|
if p != nil {
|
|
|
|
p.bearer = token
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:08:16 +00:00
|
|
|
func (p *CommonPrm) SessionToken() *token.SessionToken {
|
|
|
|
if p != nil {
|
|
|
|
return p.token
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-20 13:44:45 +00:00
|
|
|
func (p *CommonPrm) BearerToken() *token.BearerToken {
|
|
|
|
if p != nil {
|
|
|
|
return p.bearer
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:05:22 +00:00
|
|
|
func CommonPrmFromV2(req interface {
|
|
|
|
GetMetaHeader() *session.RequestMetaHeader
|
|
|
|
}) *CommonPrm {
|
|
|
|
meta := req.GetMetaHeader()
|
|
|
|
|
|
|
|
return &CommonPrm{
|
2020-10-20 13:44:45 +00:00
|
|
|
local: meta.GetTTL() <= 1, // FIXME: use constant
|
|
|
|
token: token.NewSessionTokenFromV2(meta.GetSessionToken()),
|
|
|
|
bearer: token.NewBearerTokenFromV2(meta.GetBearerToken()),
|
2020-09-29 15:05:22 +00:00
|
|
|
}
|
|
|
|
}
|