adapt changed function signatures

This commit is contained in:
Willy Kloucek committed 2021-11-19 13:22:47 +01:00
1 parent 63f74b1930
commit 32ffbe3ac6
5 files changed
+15 -12

No files matched your search

+1 -1
View File
@@ -276,7 +276,7 @@ func (s Service) ListAccounts(ctx context.Context, in *proto.ListAccountsRequest
} }
func (s Service) findAccountsByQuery(ctx context.Context, query string) ([]string, error) { func (s Service) findAccountsByQuery(ctx context.Context, query string) ([]string, error) {
return s.index.Query(&proto.Account{}, query) return s.index.Query(ctx, &proto.Account{}, query)
} }
// GetAccount implements the AccountsServiceHandler interface // GetAccount implements the AccountsServiceHandler interface
+1 -1
View File
@@ -88,7 +88,7 @@ func (s Service) ListGroups(ctx context.Context, in *proto.ListGroupsRequest, ou
return return
} }
func (s Service) findGroupsByQuery(ctx context.Context, query string) ([]string, error) { func (s Service) findGroupsByQuery(ctx context.Context, query string) ([]string, error) {
return s.index.Query(&proto.Group{}, query) return s.index.Query(ctx, &proto.Group{}, query)
} }
// GetGroup implements the GroupsServiceHandler interface // GetGroup implements the GroupsServiceHandler interface
+1 -1
View File
@@ -257,7 +257,7 @@ func (g Graph) UpdateDrive(w http.ResponseWriter, r *http.Request) {
//https://github.com/CiscoM31/godata/blob/d70e191d2908191623be84401fecc40d6af4afde/url_parser_test.go#L10 //https://github.com/CiscoM31/godata/blob/d70e191d2908191623be84401fecc40d6af4afde/url_parser_test.go#L10
sanitized := strings.TrimPrefix(r.URL.Path, "/graph/v1.0/") sanitized := strings.TrimPrefix(r.URL.Path, "/graph/v1.0/")
req, err := godata.ParseRequest(sanitized, r.URL.Query(), true) req, err := godata.ParseRequest(r.Context(), sanitized, r.URL.Query())
if err != nil { if err != nil {
errorcode.GeneralException.Render(w, r, http.StatusBadRequest, err.Error()) errorcode.GeneralException.Render(w, r, http.StatusBadRequest, err.Error())
return return
+5 -4
View File
@@ -2,6 +2,7 @@
package indexer package indexer
import ( import (
"context"
"fmt" "fmt"
"path" "path"
"strings" "strings"
@@ -255,8 +256,8 @@ func (i *Indexer) Update(from, to interface{}) error {
} }
// Query parses an OData query into something our indexer.Index understands and resolves it. // Query parses an OData query into something our indexer.Index understands and resolves it.
func (i *Indexer) Query(t interface{}, q string) ([]string, error) { func (i *Indexer) Query(ctx context.Context, t interface{}, q string) ([]string, error) {
query, err := godata.ParseFilterString(q) query, err := godata.ParseFilterString(ctx, q)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -353,7 +354,7 @@ func sanitizeInput(operands []string) (*indexerTuple, error) {
// is to transform godata operators and functions into supported operations on our index. At the time of this writing // is to transform godata operators and functions into supported operations on our index. At the time of this writing
// we only support `FindBy` and `FindByPartial` queries as these are the only implemented filters on indexer.Index(es). // we only support `FindBy` and `FindByPartial` queries as these are the only implemented filters on indexer.Index(es).
func buildTreeFromOdataQuery(root *godata.ParseNode, tree *queryTree) error { func buildTreeFromOdataQuery(root *godata.ParseNode, tree *queryTree) error {
if root.Token.Type == godata.FilterTokenFunc { // i.e "startswith", "contains" if root.Token.Type == godata.ExpressionTokenFunc { // i.e "startswith", "contains"
switch root.Token.Value { switch root.Token.Value {
case "startswith": case "startswith":
token := token{ token := token{
@@ -372,7 +373,7 @@ func buildTreeFromOdataQuery(root *godata.ParseNode, tree *queryTree) error {
} }
} }
if root.Token.Type == godata.FilterTokenLogical { if root.Token.Type == godata.ExpressionTokenLogical {
switch root.Token.Value { switch root.Token.Value {
case "or": case "or":
tree.insert(&token{operator: root.Token.Value}) tree.insert(&token{operator: root.Token.Value})
+7 -5
View File
@@ -1,6 +1,7 @@
package indexer package indexer
import ( import (
"context"
"os" "os"
"path" "path"
"testing" "testing"
@@ -255,6 +256,7 @@ func TestQueryDiskImpl(t *testing.T) {
dataDir, err := WriteIndexTestData(Data, "ID", "") dataDir, err := WriteIndexTestData(Data, "ID", "")
assert.NoError(t, err) assert.NoError(t, err)
indexer := createDiskIndexer(dataDir) indexer := createDiskIndexer(dataDir)
ctx := context.Background()
err = indexer.AddIndex(&Account{}, "OnPremisesSamAccountName", "ID", "accounts", "non_unique", nil, false) err = indexer.AddIndex(&Account{}, "OnPremisesSamAccountName", "ID", "accounts", "non_unique", nil, false)
assert.NoError(t, err) assert.NoError(t, err)
@@ -274,23 +276,23 @@ func TestQueryDiskImpl(t *testing.T) {
_, err = indexer.Add(acc) _, err = indexer.Add(acc)
assert.NoError(t, err) assert.NoError(t, err)
r, err := indexer.Query(&Account{}, "on_premises_sam_account_name eq 'MrDootDoot'") // this query will match both pets. r, err := indexer.Query(ctx, &Account{}, "on_premises_sam_account_name eq 'MrDootDoot'") // this query will match both pets.
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, []string{"ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2"}, r) assert.Equal(t, []string{"ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2"}, r)
r, err = indexer.Query(&Account{}, "mail eq 'spooky@skeletons.org'") // this query will match both pets. r, err = indexer.Query(ctx, &Account{}, "mail eq 'spooky@skeletons.org'") // this query will match both pets.
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, []string{"ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2"}, r) assert.Equal(t, []string{"ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2"}, r)
r, err = indexer.Query(&Account{}, "on_premises_sam_account_name eq 'MrDootDoot' or mail eq 'spooky@skeletons.org'") // this query will match both pets. r, err = indexer.Query(ctx, &Account{}, "on_premises_sam_account_name eq 'MrDootDoot' or mail eq 'spooky@skeletons.org'") // this query will match both pets.
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, []string{"ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2"}, r) assert.Equal(t, []string{"ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2"}, r)
r, err = indexer.Query(&Account{}, "startswith(on_premises_sam_account_name,'MrDoo')") // this query will match both pets. r, err = indexer.Query(ctx, &Account{}, "startswith(on_premises_sam_account_name,'MrDoo')") // this query will match both pets.
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, []string{"ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2"}, r) assert.Equal(t, []string{"ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2"}, r)
r, err = indexer.Query(&Account{}, "id eq 'ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2' or on_premises_sam_account_name eq 'MrDootDoot'") // this query will match both pets. r, err = indexer.Query(ctx, &Account{}, "id eq 'ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2' or on_premises_sam_account_name eq 'MrDootDoot'") // this query will match both pets.
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, []string{"ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2"}, r) assert.Equal(t, []string{"ba5b6e54-e29d-4b2b-8cc4-0a0b958140d2"}, r)