2020-09-22 06:51:47 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
2023-03-07 13:38:26 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
|
|
|
|
searchsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/search"
|
|
|
|
objutil "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
2020-09-22 06:51:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Service implements Search operation of Object service v2.
|
|
|
|
type Service struct {
|
2022-12-30 11:19:42 +00:00
|
|
|
cfg
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Option represents Service constructor option.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
svc *searchsvc.Service
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
keyStorage *objutil.KeyStorage
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewService constructs Service instance from provided options.
|
|
|
|
func NewService(opts ...Option) *Service {
|
2022-12-30 11:19:42 +00:00
|
|
|
var s Service
|
2020-09-22 06:51:47 +00:00
|
|
|
|
|
|
|
for i := range opts {
|
2022-12-30 11:19:42 +00:00
|
|
|
opts[i](&s.cfg)
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 11:19:42 +00:00
|
|
|
return &s
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 13:29:46 +00:00
|
|
|
// Search calls internal service and returns v2 object stream.
|
2020-12-10 12:26:40 +00:00
|
|
|
func (s *Service) Search(req *objectV2.SearchRequest, stream objectSvc.SearchStream) error {
|
|
|
|
p, err := s.toPrm(req, stream)
|
2020-09-22 06:51:47 +00:00
|
|
|
if err != nil {
|
2020-12-10 12:26:40 +00:00
|
|
|
return err
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
return s.svc.Search(stream.Context(), *p)
|
2020-09-22 06:51:47 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:26:40 +00:00
|
|
|
// WithInternalService returns option to set entity
|
|
|
|
// that handles request payload.
|
2020-09-22 06:51:47 +00:00
|
|
|
func WithInternalService(v *searchsvc.Service) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.svc = v
|
|
|
|
}
|
|
|
|
}
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
// WithKeyStorage returns option to set local private key storage.
|
|
|
|
func WithKeyStorage(ks *objutil.KeyStorage) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.keyStorage = ks
|
|
|
|
}
|
|
|
|
}
|