frostfs-node/pkg/services/object/search/v2/util.go

59 lines
1.8 KiB
Go
Raw Normal View History

package searchsvc
import (
"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-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"
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
"github.com/nspcc-dev/neofs-node/pkg/services/object/util"
)
func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStream) (*searchsvc.Prm, error) {
meta := req.GetMetaHeader()
key, err := s.keyStorage.GetKey(token.NewSessionTokenFromV2(meta.GetSessionToken()))
if err != nil {
return nil, err
}
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
}
// 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
}
func commonParameters(meta *session.RequestMetaHeader) *util.CommonPrm {
return new(util.CommonPrm).
WithLocalOnly(meta.GetTTL() <= 1)
}