2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
2020-12-10 12:26:40 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
2020-09-22 06:51:47 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
2020-10-01 12:12:39 +00:00
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-12-10 12:26:40 +00:00
|
|
|
"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"
|
|
|
|
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
2020-09-22 06:51:47 +00:00
|
|
|
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
|
2020-09-29 15:05:22 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
|
2020-09-22 06:51:47 +00:00
|
|
|
)
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStream) (*searchsvc.Prm, error) {
|
|
|
|
meta := req.GetMetaHeader()
|
2020-09-22 06:51:47 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
key, err := s.keyStorage.GetKey(token.NewSessionTokenFromV2(meta.GetSessionToken()))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
p := new(searchsvc.Prm)
|
|
|
|
p.SetPrivateKey(key)
|
|
|
|
p.SetCommonParameters(commonParameters(meta))
|
|
|
|
p.SetRemoteCallOptions(remoteCallOptionsFromMeta(meta)...)
|
|
|
|
p.SetWriter(&streamWriter{
|
|
|
|
stream: stream,
|
|
|
|
})
|
|
|
|
|
|
|
|
body := req.GetBody()
|
|
|
|
p.WithContainerID(container.NewIDFromV2(body.GetContainerID()))
|
|
|
|
p.WithSearchFilters(objectSDK.NewSearchFiltersFromV2(body.GetFilters()))
|
|
|
|
|
|
|
|
return p, nil
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// can be shared accross all services
|
|
|
|
func remoteCallOptionsFromMeta(meta *session.RequestMetaHeader) []client.CallOption {
|
2020-12-11 10:02:32 +00:00
|
|
|
opts := make([]client.CallOption, 0, 3)
|
|
|
|
opts = append(opts, client.WithTTL(meta.GetTTL()-1))
|
2020-09-22 06:51:47 +00:00
|
|
|
|
2020-12-11 10:02:32 +00:00
|
|
|
if tok := meta.GetBearerToken(); tok != nil {
|
|
|
|
opts = append(opts, client.WithBearer(token.NewBearerTokenFromV2(tok)))
|
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
|
2020-12-11 10:02:32 +00:00
|
|
|
if tok := meta.GetSessionToken(); tok != nil {
|
|
|
|
opts = append(opts, client.WithSession(token.NewSessionTokenFromV2(tok)))
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return opts
|
|
|
|
}
|
2020-09-22 06:51:47 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
func commonParameters(meta *session.RequestMetaHeader) *util.CommonPrm {
|
2020-12-11 10:02:32 +00:00
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
return new(util.CommonPrm).
|
|
|
|
WithLocalOnly(meta.GetTTL() <= 1)
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|