From 609ce4ddd5ffb71d7d1c6a57a3a73614be2c028d Mon Sep 17 00:00:00 2001 From: Abduh Date: Tue, 7 Jun 2022 17:08:36 +0700 Subject: [PATCH] fix(compass): remove type whitelist (#147) --- core/asset/discovery.go | 4 --- internal/server/v1beta1/search.go | 28 ++++--------------- internal/server/v1beta1/search_test.go | 8 +++--- .../discovery_search_repository.go | 11 -------- 4 files changed, 9 insertions(+), 42 deletions(-) diff --git a/core/asset/discovery.go b/core/asset/discovery.go index d38a6533..91dce091 100644 --- a/core/asset/discovery.go +++ b/core/asset/discovery.go @@ -34,10 +34,6 @@ type SearchConfig struct { // Number of relevant results to return MaxResults int - // List of asset types to search for - // a zero value signifies that all types should be searched - TypeWhiteList []string - // RankBy is a param to rank based on a specific parameter RankBy string diff --git a/internal/server/v1beta1/search.go b/internal/server/v1beta1/search.go index 1d671771..36082988 100644 --- a/internal/server/v1beta1/search.go +++ b/internal/server/v1beta1/search.go @@ -11,10 +11,6 @@ import ( "google.golang.org/grpc/status" ) -const ( - whiteListQueryParamKey = "type" -) - func (server *APIServer) SearchAssets(ctx context.Context, req *compassv1beta1.SearchAssetsRequest) (*compassv1beta1.SearchAssetsResponse, error) { _, err := server.validateUserInCtx(ctx) if err != nil { @@ -27,12 +23,11 @@ func (server *APIServer) SearchAssets(ctx context.Context, req *compassv1beta1.S } cfg := asset.SearchConfig{ - Text: text, - MaxResults: int(req.GetSize()), - Filters: filterConfigFromValues(req.GetFilter()), - RankBy: req.GetRankby(), - Queries: req.GetQuery(), - TypeWhiteList: parseTypeWhiteList(req.GetFilter()), + Text: text, + MaxResults: int(req.GetSize()), + Filters: filterConfigFromValues(req.GetFilter()), + RankBy: req.GetRankby(), + Queries: req.GetQuery(), } results, err := server.assetService.SearchAssets(ctx, cfg) @@ -82,12 +77,6 @@ func (server *APIServer) SuggestAssets(ctx context.Context, req *compassv1beta1. func filterConfigFromValues(fltMap map[string]string) map[string][]string { var filter = make(map[string][]string) for key, value := range fltMap { - // filters are of form "filter[{field}]", apart from "filter[type]", which is used - // for building the type whitelist. - if key == whiteListQueryParamKey { - continue - } - var filterValues []string filterValues = append(filterValues, strings.Split(value, ",")...) @@ -95,10 +84,3 @@ func filterConfigFromValues(fltMap map[string]string) map[string][]string { } return filter } - -func parseTypeWhiteList(fltMap map[string]string) (types []string) { - if val, ok := fltMap[whiteListQueryParamKey]; ok { - types = append(types, strings.Split(val, ",")...) - } - return -} diff --git a/internal/server/v1beta1/search_test.go b/internal/server/v1beta1/search_test.go index ec61db32..e1d79a63 100644 --- a/internal/server/v1beta1/search_test.go +++ b/internal/server/v1beta1/search_test.go @@ -63,9 +63,9 @@ func TestSearch(t *testing.T) { Setup: func(ctx context.Context, as *mocks.AssetService) { cfg := asset.SearchConfig{ - Text: "resource", - TypeWhiteList: []string{"topic"}, + Text: "resource", Filters: map[string][]string{ + "type": {"topic"}, "service": {"kafka", "rabbitmq"}, "data.landscape": {"th"}, }, @@ -91,9 +91,9 @@ func TestSearch(t *testing.T) { Setup: func(ctx context.Context, as *mocks.AssetService) { cfg := asset.SearchConfig{ - Text: "resource", - TypeWhiteList: []string{"topic"}, + Text: "resource", Filters: map[string][]string{ + "type": {"topic"}, "service": {"kafka", "rabbitmq"}, "data.landscape": {"th"}, }, diff --git a/internal/store/elasticsearch/discovery_search_repository.go b/internal/store/elasticsearch/discovery_search_repository.go index 266e3ace..bc477367 100644 --- a/internal/store/elasticsearch/discovery_search_repository.go +++ b/internal/store/elasticsearch/discovery_search_repository.go @@ -24,17 +24,6 @@ const ( var returnedAssetFieldsResult = []string{"id", "urn", "type", "service", "name", "description", "data", "labels", "created_at", "updated_at"} // Search the asset store -// Note that Searcher accepts 2 different forms of type white list, -// depending on how it is passed -// (1) when passed to NewSearcher, this is called the "Global White List" or GL for short -// (2) when passed to Search() as models.SearchConfig.TypeWhiteList, it's called "Local White List" or LL -// GL dictates the superset of all type types that should searched, while LL can only be a subset. -// To demonstrate: -// GL : {A, B, C} -// LL : {C, D} -// Entities searched : {C} -// GL specified that search can only be done for {A, B, C} types, while LL requested -// the search for {C, D} types. Since {D} doesn't belong to GL's set, it won't be searched func (repo *DiscoveryRepository) Search(ctx context.Context, cfg asset.SearchConfig) (results []asset.SearchResult, err error) { if strings.TrimSpace(cfg.Text) == "" { err = errors.New("search text cannot be empty")