mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-25 05:58:38 -06:00
Properly pass on the token in the context to the search provider
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,14 +5,17 @@ import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
|
||||
revactx "github.com/cs3org/reva/v2/pkg/ctx"
|
||||
"github.com/owncloud/ocis/extensions/webdav/pkg/net"
|
||||
"github.com/owncloud/ocis/extensions/webdav/pkg/prop"
|
||||
"github.com/owncloud/ocis/extensions/webdav/pkg/propfind"
|
||||
searchmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/search/v0"
|
||||
searchsvc "github.com/owncloud/ocis/protogen/gen/ocis/services/search/v0"
|
||||
merrors "go-micro.dev/v4/errors"
|
||||
"go-micro.dev/v4/metadata"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,7 +25,6 @@ const (
|
||||
|
||||
// Search is the endpoint for retrieving search results for REPORT requests
|
||||
func (g Webdav) Search(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
rep, err := readReport(r.Body)
|
||||
if err != nil {
|
||||
renderError(w, r, errBadRequest(err.Error()))
|
||||
@@ -36,7 +38,10 @@ func (g Webdav) Search(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rsp, err := g.searchClient.Search(r.Context(), &searchsvc.SearchRequest{
|
||||
t := r.Header.Get(TokenHeader)
|
||||
ctx := revactx.ContextSetToken(r.Context(), t)
|
||||
ctx = metadata.Set(ctx, revactx.TokenHeader, t)
|
||||
rsp, err := g.searchClient.Search(ctx, &searchsvc.SearchRequest{
|
||||
Query: rep.SearchFiles.Search.Pattern,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -93,7 +98,7 @@ func multistatusResponse(ctx context.Context, matches []*searchmsg.Match) ([]byt
|
||||
func matchToPropResponse(ctx context.Context, match *searchmsg.Match) (*propfind.ResponseXML, error) {
|
||||
|
||||
response := propfind.ResponseXML{
|
||||
Href: net.EncodePath(match.Entity.Ref.Path),
|
||||
Href: net.EncodePath(path.Join("/dav/spaces/", match.Entity.Ref.ResourceId.StorageId+"!"+match.Entity.Ref.ResourceId.OpaqueId, match.Entity.Ref.Path)),
|
||||
Propstat: []propfind.PropstatXML{},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user