forked from TrueCloudLab/frostfs-node
[#243] services/object: Share common parameters across services
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
a01262d8bd
commit
fb50362dcc
12 changed files with 89 additions and 163 deletions
|
@ -1,11 +1,9 @@
|
|||
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"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
deletesvc "github.com/nspcc-dev/neofs-node/pkg/services/object/delete"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
||||
)
|
||||
|
@ -23,9 +21,9 @@ 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)...)
|
||||
p.SetCommonParameters(util.CommonPrmFromV2(req).
|
||||
WithPrivateKey(key),
|
||||
)
|
||||
|
||||
body := req.GetBody()
|
||||
p.WithAddress(object.NewAddressFromV2(body.GetAddress()))
|
||||
|
@ -39,33 +37,3 @@ func (s *Service) toPrm(req *objectV2.DeleteRequest, respBody *objectV2.DeleteRe
|
|||
func (w *tombstoneBodyWriter) SetAddress(addr *object.Address) {
|
||||
w.body.SetTombstone(addr.ToV2())
|
||||
}
|
||||
|
||||
func commonParameters(meta *session.RequestMetaHeader) *util.CommonPrm {
|
||||
prm := new(util.CommonPrm)
|
||||
|
||||
if tok := meta.GetBearerToken(); tok != nil {
|
||||
prm.WithBearerToken(token.NewBearerTokenFromV2(tok))
|
||||
}
|
||||
|
||||
if tok := meta.GetSessionToken(); tok != nil {
|
||||
prm.WithSessionToken(token.NewSessionTokenFromV2(tok))
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue