forked from TrueCloudLab/frostfs-node
[#106] Pass bearer token through generated requests
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
e6f04f7785
commit
ae0dd9e051
8 changed files with 32 additions and 3 deletions
pkg/services/object
head
put
range
rangehash
search
util
|
@ -44,6 +44,7 @@ func (h *remoteHeader) head(ctx context.Context, prm *Prm, handler func(*object.
|
||||||
hdr, err := c.GetObjectHeader(ctx, p,
|
hdr, err := c.GetObjectHeader(ctx, p,
|
||||||
client.WithTTL(1), // FIXME: use constant
|
client.WithTTL(1), // FIXME: use constant
|
||||||
client.WithSession(prm.common.SessionToken()),
|
client.WithSession(prm.common.SessionToken()),
|
||||||
|
client.WithBearer(prm.common.BearerToken()),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "(%T) could not head object in %s", h, addr)
|
return errors.Wrapf(err, "(%T) could not head object in %s", h, addr)
|
||||||
|
|
|
@ -21,6 +21,8 @@ type remoteTarget struct {
|
||||||
|
|
||||||
token *token.SessionToken
|
token *token.SessionToken
|
||||||
|
|
||||||
|
bearer *token.BearerToken
|
||||||
|
|
||||||
addr *network.Address
|
addr *network.Address
|
||||||
|
|
||||||
obj *object.Object
|
obj *object.Object
|
||||||
|
@ -55,6 +57,7 @@ func (t *remoteTarget) Close() (*transformer.AccessIdentifiers, error) {
|
||||||
t.obj.SDK(),
|
t.obj.SDK(),
|
||||||
),
|
),
|
||||||
client.WithTTL(1), // FIXME: use constant
|
client.WithTTL(1), // FIXME: use constant
|
||||||
|
client.WithBearer(t.bearer),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "(%T) could not put object to %s", t, addr)
|
return nil, errors.Wrapf(err, "(%T) could not put object to %s", t, addr)
|
||||||
|
|
|
@ -131,6 +131,7 @@ func (p *Streamer) newCommonTarget(prm *PutInitPrm) transformer.ObjectTarget {
|
||||||
ctx: p.ctx,
|
ctx: p.ctx,
|
||||||
keyStorage: p.keyStorage,
|
keyStorage: p.keyStorage,
|
||||||
token: prm.common.SessionToken(),
|
token: prm.common.SessionToken(),
|
||||||
|
bearer: prm.common.BearerToken(),
|
||||||
addr: addr,
|
addr: addr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ type remoteRangeWriter struct {
|
||||||
|
|
||||||
token *token.SessionToken
|
token *token.SessionToken
|
||||||
|
|
||||||
|
bearer *token.BearerToken
|
||||||
|
|
||||||
addr *object.Address
|
addr *object.Address
|
||||||
|
|
||||||
rng *object.Range
|
rng *object.Range
|
||||||
|
@ -50,6 +52,7 @@ func (r *remoteRangeWriter) WriteTo(w io.Writer) (int64, error) {
|
||||||
WithAddress(r.addr),
|
WithAddress(r.addr),
|
||||||
client.WithTTL(1), // FIXME: use constant
|
client.WithTTL(1), // FIXME: use constant
|
||||||
client.WithSession(r.token),
|
client.WithSession(r.token),
|
||||||
|
client.WithBearer(r.bearer),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Wrapf(err, "(%T) could not read object payload range from %s", r, addr)
|
return 0, errors.Wrapf(err, "(%T) could not read object payload range from %s", r, addr)
|
||||||
|
|
|
@ -182,6 +182,7 @@ loop:
|
||||||
keyStorage: p.keyStorage,
|
keyStorage: p.keyStorage,
|
||||||
node: addr,
|
node: addr,
|
||||||
token: p.prm.common.SessionToken(),
|
token: p.prm.common.SessionToken(),
|
||||||
|
bearer: p.prm.common.BearerToken(),
|
||||||
addr: objAddr,
|
addr: objAddr,
|
||||||
rng: nextRange,
|
rng: nextRange,
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ func (h *remoteHasher) hashRange(ctx context.Context, prm *Prm, handler func([][
|
||||||
opts := []client.CallOption{
|
opts := []client.CallOption{
|
||||||
client.WithTTL(1), // FIXME: use constant
|
client.WithTTL(1), // FIXME: use constant
|
||||||
client.WithSession(prm.common.SessionToken()),
|
client.WithSession(prm.common.SessionToken()),
|
||||||
|
client.WithBearer(prm.common.BearerToken()),
|
||||||
}
|
}
|
||||||
|
|
||||||
switch prm.typ {
|
switch prm.typ {
|
||||||
|
|
|
@ -42,6 +42,7 @@ func (s *remoteStream) stream(ctx context.Context, ch chan<- []*object.ID) error
|
||||||
WithSearchFilters(s.prm.query.ToSearchFilters()),
|
WithSearchFilters(s.prm.query.ToSearchFilters()),
|
||||||
client.WithTTL(1), // FIXME: use constant
|
client.WithTTL(1), // FIXME: use constant
|
||||||
client.WithSession(s.prm.common.SessionToken()),
|
client.WithSession(s.prm.common.SessionToken()),
|
||||||
|
client.WithBearer(s.prm.common.BearerToken()),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "(%T) could not search objects in %s", s, addr)
|
return errors.Wrapf(err, "(%T) could not search objects in %s", s, addr)
|
||||||
|
|
|
@ -8,7 +8,8 @@ import (
|
||||||
type CommonPrm struct {
|
type CommonPrm struct {
|
||||||
local bool
|
local bool
|
||||||
|
|
||||||
token *token.SessionToken
|
token *token.SessionToken
|
||||||
|
bearer *token.BearerToken
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *CommonPrm) WithLocalOnly(v bool) *CommonPrm {
|
func (p *CommonPrm) WithLocalOnly(v bool) *CommonPrm {
|
||||||
|
@ -35,6 +36,14 @@ func (p *CommonPrm) WithSessionToken(token *token.SessionToken) *CommonPrm {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *CommonPrm) WithBearerToken(token *token.BearerToken) *CommonPrm {
|
||||||
|
if p != nil {
|
||||||
|
p.bearer = token
|
||||||
|
}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
func (p *CommonPrm) SessionToken() *token.SessionToken {
|
func (p *CommonPrm) SessionToken() *token.SessionToken {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
return p.token
|
return p.token
|
||||||
|
@ -43,13 +52,22 @@ func (p *CommonPrm) SessionToken() *token.SessionToken {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *CommonPrm) BearerToken() *token.BearerToken {
|
||||||
|
if p != nil {
|
||||||
|
return p.bearer
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func CommonPrmFromV2(req interface {
|
func CommonPrmFromV2(req interface {
|
||||||
GetMetaHeader() *session.RequestMetaHeader
|
GetMetaHeader() *session.RequestMetaHeader
|
||||||
}) *CommonPrm {
|
}) *CommonPrm {
|
||||||
meta := req.GetMetaHeader()
|
meta := req.GetMetaHeader()
|
||||||
|
|
||||||
return &CommonPrm{
|
return &CommonPrm{
|
||||||
local: meta.GetTTL() <= 1, // FIXME: use constant
|
local: meta.GetTTL() <= 1, // FIXME: use constant
|
||||||
token: token.NewSessionTokenFromV2(meta.GetSessionToken()),
|
token: token.NewSessionTokenFromV2(meta.GetSessionToken()),
|
||||||
|
bearer: token.NewBearerTokenFromV2(meta.GetBearerToken()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue