[#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

@ -44,6 +44,7 @@ func (h *remoteHeader) head(ctx context.Context, prm *Prm, handler func(*object.
hdr, err := c.GetObjectHeader(ctx, p,
client.WithTTL(1), // FIXME: use constant
client.WithSession(prm.common.SessionToken()),
client.WithBearer(prm.common.BearerToken()),
)
if err != nil {
return errors.Wrapf(err, "(%T) could not head object in %s", h, addr)

View file

@ -21,6 +21,8 @@ type remoteTarget struct {
token *token.SessionToken
bearer *token.BearerToken
addr *network.Address
obj *object.Object
@ -55,6 +57,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
t.obj.SDK(),
),
client.WithTTL(1), // FIXME: use constant
client.WithBearer(t.bearer),
)
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not put object to %s", t, addr)

View file

@ -131,6 +131,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
ctx: p.ctx,
keyStorage: p.keyStorage,
token: prm.common.SessionToken(),
bearer: prm.common.BearerToken(),
addr: addr,
}
}

View file

@ -21,6 +21,8 @@ type remoteRangeWriter struct {
token *token.SessionToken
bearer *token.BearerToken
addr *object.Address
rng *object.Range
@ -50,6 +52,7 @@ func (r *remoteRangeWriter) WriteTo(w io.Writer) (int64, error) {
WithAddress(r.addr),
client.WithTTL(1), // FIXME: use constant
client.WithSession(r.token),
client.WithBearer(r.bearer),
)
if err != nil {
return 0, errors.Wrapf(err, "(%T) could not read object payload range from %s", r, addr)

View file

@ -182,6 +182,7 @@ loop:
keyStorage: p.keyStorage,
node: addr,
token: p.prm.common.SessionToken(),
bearer: p.prm.common.BearerToken(),
addr: objAddr,
rng: nextRange,
}

View file

@ -45,6 +45,7 @@ func (h *remoteHasher) hashRange(ctx context.Context, prm *Prm, handler func([][
opts := []client.CallOption{
client.WithTTL(1), // FIXME: use constant
client.WithSession(prm.common.SessionToken()),
client.WithBearer(prm.common.BearerToken()),
}
switch prm.typ {

View file

@ -42,6 +42,7 @@ func (s *remoteStream) stream(ctx context.Context, ch chan<- []*object.ID) error
WithSearchFilters(s.prm.query.ToSearchFilters()),
client.WithTTL(1), // FIXME: use constant
client.WithSession(s.prm.common.SessionToken()),
client.WithBearer(s.prm.common.BearerToken()),
)
if err != nil {
return errors.Wrapf(err, "(%T) could not search objects in %s", s, addr)

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()),
}
}