2020-09-30 10:52:14 +00:00
|
|
|
package deletesvc
|
|
|
|
|
|
|
|
import (
|
2020-12-11 10:02:32 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
2020-09-30 10:52:14 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-12-11 08:04:04 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
2020-09-30 10:52:14 +00:00
|
|
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
2020-12-11 08:04:04 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
2020-09-30 10:52:14 +00:00
|
|
|
deletesvc "github.com/nspcc-dev/neofs-node/pkg/services/object/delete"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
|
|
|
)
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
type tombstoneBodyWriter struct {
|
|
|
|
body *objectV2.DeleteResponseBody
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) toPrm(req *objectV2.DeleteRequest, respBody *objectV2.DeleteResponseBody) (*deletesvc.Prm, error) {
|
|
|
|
meta := req.GetMetaHeader()
|
|
|
|
|
|
|
|
key, err := s.keyStorage.GetKey(token.NewSessionTokenFromV2(meta.GetSessionToken()))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
p := new(deletesvc.Prm)
|
|
|
|
p.SetPrivateKey(key)
|
|
|
|
p.SetCommonParameters(commonParameters(meta))
|
2020-12-11 10:02:32 +00:00
|
|
|
p.SetRemoteCallOptions(remoteCallOptionsFromMeta(meta)...)
|
2020-12-11 08:04:04 +00:00
|
|
|
|
2020-09-30 10:52:14 +00:00
|
|
|
body := req.GetBody()
|
2020-12-11 08:04:04 +00:00
|
|
|
p.WithAddress(object.NewAddressFromV2(body.GetAddress()))
|
|
|
|
p.WithTombstoneAddressTarget(&tombstoneBodyWriter{
|
|
|
|
body: respBody,
|
|
|
|
})
|
2020-09-30 10:52:14 +00:00
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
return p, nil
|
2020-09-30 10:52:14 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 08:04:04 +00:00
|
|
|
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
|
2020-09-30 10:52:14 +00:00
|
|
|
}
|
2020-12-11 10:02:32 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|