forked from TrueCloudLab/frostfs-node
[#243] services/object: Fix lost tokens when generating requests
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
09916f21b5
commit
9265e31e65
6 changed files with 47 additions and 22 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"crypto/ecdsa"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
|
@ -74,6 +75,10 @@ func (exec *execCtx) commonParameters() *util.CommonPrm {
|
|||
return exec.prm.common
|
||||
}
|
||||
|
||||
func (exec execCtx) callOptions() []client.CallOption {
|
||||
return exec.prm.callOpts
|
||||
}
|
||||
|
||||
func (exec *execCtx) newAddress(id *objectSDK.ID) *objectSDK.Address {
|
||||
a := objectSDK.NewAddress()
|
||||
a.SetObjectID(id)
|
||||
|
|
|
@ -13,6 +13,8 @@ type Prm struct {
|
|||
|
||||
common *util.CommonPrm
|
||||
|
||||
callOpts []client.CallOption
|
||||
|
||||
client.DeleteObjectParams
|
||||
}
|
||||
|
||||
|
@ -25,3 +27,8 @@ func (p *Prm) SetCommonParameters(common *util.CommonPrm) {
|
|||
func (p *Prm) SetPrivateKey(key *ecdsa.PrivateKey) {
|
||||
p.key = key
|
||||
}
|
||||
|
||||
// SetRemoteCallOptions sets call options of remote client calls.
|
||||
func (p *Prm) SetRemoteCallOptions(opts ...client.CallOption) {
|
||||
p.callOpts = opts
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ func (w *headSvcWrapper) headAddress(exec *execCtx, addr *objectSDK.Address) (*o
|
|||
p.SetHeaderWriter(wr)
|
||||
p.WithRawFlag(true)
|
||||
p.WithAddress(addr)
|
||||
p.SetRemoteCallOptions(exec.callOptions()...)
|
||||
|
||||
err := (*getsvc.Service)(w).Head(exec.context(), p)
|
||||
if err != nil {
|
||||
|
@ -88,6 +89,7 @@ func (w *searchSvcWrapper) splitMembers(exec *execCtx) ([]*objectSDK.ID, error)
|
|||
p.SetPrivateKey(exec.key())
|
||||
p.WithContainerID(exec.containerID())
|
||||
p.WithSearchFilters(fs)
|
||||
p.SetRemoteCallOptions(exec.callOptions()...)
|
||||
|
||||
err := (*searchsvc.Service)(w).Search(exec.context(), p)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package deletesvc
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
||||
|
@ -24,6 +25,7 @@ func (s *Service) toPrm(req *objectV2.DeleteRequest, respBody *objectV2.DeleteRe
|
|||
p := new(deletesvc.Prm)
|
||||
p.SetPrivateKey(key)
|
||||
p.SetCommonParameters(commonParameters(meta))
|
||||
p.SetRemoteCallOptions(remoteCallOptionsFromMeta(meta)...)
|
||||
|
||||
body := req.GetBody()
|
||||
p.WithAddress(object.NewAddressFromV2(body.GetAddress()))
|
||||
|
@ -51,3 +53,19 @@ func commonParameters(meta *session.RequestMetaHeader) *util.CommonPrm {
|
|||
|
||||
return prm
|
||||
}
|
||||
|
||||
// can be shared accross all services
|
||||
func remoteCallOptionsFromMeta(meta *session.RequestMetaHeader) []client.CallOption {
|
||||
opts := make([]client.CallOption, 0, 3)
|
||||
opts = append(opts, client.WithTTL(meta.GetTTL()-1))
|
||||
|
||||
if tok := meta.GetBearerToken(); tok != nil {
|
||||
opts = append(opts, client.WithBearer(token.NewBearerTokenFromV2(tok)))
|
||||
}
|
||||
|
||||
if tok := meta.GetSessionToken(); tok != nil {
|
||||
opts = append(opts, client.WithSession(token.NewSessionTokenFromV2(tok)))
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"crypto/sha256"
|
||||
"hash"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
|
@ -145,18 +144,15 @@ func (s *Service) toHeadPrm(req *objectV2.HeadRequest, resp *objectV2.HeadRespon
|
|||
|
||||
// can be shared accross all services
|
||||
func remoteCallOptionsFromMeta(meta *session.RequestMetaHeader) []client.CallOption {
|
||||
xHdrs := meta.GetXHeaders()
|
||||
opts := make([]client.CallOption, 0, 3)
|
||||
opts = append(opts, client.WithTTL(meta.GetTTL()-1))
|
||||
|
||||
opts := make([]client.CallOption, 0, 3+len(xHdrs))
|
||||
if tok := meta.GetBearerToken(); tok != nil {
|
||||
opts = append(opts, client.WithBearer(token.NewBearerTokenFromV2(tok)))
|
||||
}
|
||||
|
||||
opts = append(opts,
|
||||
client.WithBearer(token.NewBearerTokenFromV2(meta.GetBearerToken())),
|
||||
client.WithSession(token.NewSessionTokenFromV2(meta.GetSessionToken())),
|
||||
client.WithTTL(meta.GetTTL()-1),
|
||||
)
|
||||
|
||||
for i := range xHdrs {
|
||||
opts = append(opts, client.WithXHeader(pkg.NewXHeaderFromV2(xHdrs[i])))
|
||||
if tok := meta.GetSessionToken(); tok != nil {
|
||||
opts = append(opts, client.WithSession(token.NewSessionTokenFromV2(tok)))
|
||||
}
|
||||
|
||||
return opts
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package searchsvc
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
|
@ -38,24 +37,22 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre
|
|||
|
||||
// can be shared accross all services
|
||||
func remoteCallOptionsFromMeta(meta *session.RequestMetaHeader) []client.CallOption {
|
||||
xHdrs := meta.GetXHeaders()
|
||||
opts := make([]client.CallOption, 0, 3)
|
||||
opts = append(opts, client.WithTTL(meta.GetTTL()-1))
|
||||
|
||||
opts := make([]client.CallOption, 0, 3+len(xHdrs))
|
||||
if tok := meta.GetBearerToken(); tok != nil {
|
||||
opts = append(opts, client.WithBearer(token.NewBearerTokenFromV2(tok)))
|
||||
}
|
||||
|
||||
opts = append(opts,
|
||||
client.WithBearer(token.NewBearerTokenFromV2(meta.GetBearerToken())),
|
||||
client.WithSession(token.NewSessionTokenFromV2(meta.GetSessionToken())),
|
||||
client.WithTTL(meta.GetTTL()-1),
|
||||
)
|
||||
|
||||
for i := range xHdrs {
|
||||
opts = append(opts, client.WithXHeader(pkg.NewXHeaderFromV2(xHdrs[i])))
|
||||
if tok := meta.GetSessionToken(); tok != nil {
|
||||
opts = append(opts, client.WithSession(token.NewSessionTokenFromV2(tok)))
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
func commonParameters(meta *session.RequestMetaHeader) *util.CommonPrm {
|
||||
|
||||
return new(util.CommonPrm).
|
||||
WithLocalOnly(meta.GetTTL() <= 1)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue