Properly pass on the token in the context to the search provider

This commit is contained in:
André Duffeck
2022-04-22 12:59:09 +02:00
parent 5598fc04ec
commit 3ec212c0cb
3 changed files with 22 additions and 5 deletions
@@ -92,7 +92,7 @@ var _ = Describe("Searchprovider", func() {
}, nil)
})
It("trigger an index change", func() {
It("trigger an index update when a file has been uploaded", func() {
called := false
indexClient.On("Add", mock.Anything, mock.MatchedBy(func(riToIndex *sprovider.ResourceInfo) bool {
return riToIndex.Id.OpaqueId == ri.Id.OpaqueId
+13 -1
View File
@@ -2,12 +2,16 @@ package service
import (
"context"
"errors"
"github.com/asim/go-micro/plugins/events/natsjs/v4"
"github.com/blevesearch/bleve/v2"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/events"
"github.com/cs3org/reva/v2/pkg/events/server"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
"go-micro.dev/v4/metadata"
grpcmetadata "google.golang.org/grpc/metadata"
"github.com/owncloud/ocis/extensions/audit/pkg/types"
"github.com/owncloud/ocis/extensions/search/pkg/config"
@@ -71,11 +75,19 @@ type Service struct {
}
func (s Service) Search(ctx context.Context, in *searchsvc.SearchRequest, out *searchsvc.SearchResponse) error {
// Get token from the context (go-micro) and make it known to the reva client too (grpc)
t, ok := metadata.Get(ctx, revactx.TokenHeader)
if !ok {
s.log.Error().Msg("Could not get token from context")
return errors.New("could not get token from context")
}
ctx = grpcmetadata.AppendToOutgoingContext(ctx, revactx.TokenHeader, t)
res, err := s.provider.Search(ctx, &searchsvc.SearchRequest{
Query: in.Query,
})
if err != nil {
return nil
return err
}
out.Matches = res.Matches