Skip to content

Commit

Permalink
fix(compass): remove type whitelist (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdh authored Jun 7, 2022
1 parent eced082 commit 609ce4d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 42 deletions.
4 changes: 0 additions & 4 deletions core/asset/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 5 additions & 23 deletions internal/server/v1beta1/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -82,23 +77,10 @@ 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, ",")...)

filter[key] = filterValues
}
return filter
}

func parseTypeWhiteList(fltMap map[string]string) (types []string) {
if val, ok := fltMap[whiteListQueryParamKey]; ok {
types = append(types, strings.Split(val, ",")...)
}
return
}
8 changes: 4 additions & 4 deletions internal/server/v1beta1/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
Expand All @@ -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"},
},
Expand Down
11 changes: 0 additions & 11 deletions internal/store/elasticsearch/discovery_search_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 609ce4d

Please sign in to comment.