Skip to content

Commit 609ce4d

Browse files
authored
fix(compass): remove type whitelist (#147)
1 parent eced082 commit 609ce4d

File tree

4 files changed

+9
-42
lines changed

4 files changed

+9
-42
lines changed

core/asset/discovery.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ type SearchConfig struct {
3434
// Number of relevant results to return
3535
MaxResults int
3636

37-
// List of asset types to search for
38-
// a zero value signifies that all types should be searched
39-
TypeWhiteList []string
40-
4137
// RankBy is a param to rank based on a specific parameter
4238
RankBy string
4339

internal/server/v1beta1/search.go

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import (
1111
"google.golang.org/grpc/status"
1212
)
1313

14-
const (
15-
whiteListQueryParamKey = "type"
16-
)
17-
1814
func (server *APIServer) SearchAssets(ctx context.Context, req *compassv1beta1.SearchAssetsRequest) (*compassv1beta1.SearchAssetsResponse, error) {
1915
_, err := server.validateUserInCtx(ctx)
2016
if err != nil {
@@ -27,12 +23,11 @@ func (server *APIServer) SearchAssets(ctx context.Context, req *compassv1beta1.S
2723
}
2824

2925
cfg := asset.SearchConfig{
30-
Text: text,
31-
MaxResults: int(req.GetSize()),
32-
Filters: filterConfigFromValues(req.GetFilter()),
33-
RankBy: req.GetRankby(),
34-
Queries: req.GetQuery(),
35-
TypeWhiteList: parseTypeWhiteList(req.GetFilter()),
26+
Text: text,
27+
MaxResults: int(req.GetSize()),
28+
Filters: filterConfigFromValues(req.GetFilter()),
29+
RankBy: req.GetRankby(),
30+
Queries: req.GetQuery(),
3631
}
3732

3833
results, err := server.assetService.SearchAssets(ctx, cfg)
@@ -82,23 +77,10 @@ func (server *APIServer) SuggestAssets(ctx context.Context, req *compassv1beta1.
8277
func filterConfigFromValues(fltMap map[string]string) map[string][]string {
8378
var filter = make(map[string][]string)
8479
for key, value := range fltMap {
85-
// filters are of form "filter[{field}]", apart from "filter[type]", which is used
86-
// for building the type whitelist.
87-
if key == whiteListQueryParamKey {
88-
continue
89-
}
90-
9180
var filterValues []string
9281
filterValues = append(filterValues, strings.Split(value, ",")...)
9382

9483
filter[key] = filterValues
9584
}
9685
return filter
9786
}
98-
99-
func parseTypeWhiteList(fltMap map[string]string) (types []string) {
100-
if val, ok := fltMap[whiteListQueryParamKey]; ok {
101-
types = append(types, strings.Split(val, ",")...)
102-
}
103-
return
104-
}

internal/server/v1beta1/search_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func TestSearch(t *testing.T) {
6363
Setup: func(ctx context.Context, as *mocks.AssetService) {
6464

6565
cfg := asset.SearchConfig{
66-
Text: "resource",
67-
TypeWhiteList: []string{"topic"},
66+
Text: "resource",
6867
Filters: map[string][]string{
68+
"type": {"topic"},
6969
"service": {"kafka", "rabbitmq"},
7070
"data.landscape": {"th"},
7171
},
@@ -91,9 +91,9 @@ func TestSearch(t *testing.T) {
9191
Setup: func(ctx context.Context, as *mocks.AssetService) {
9292

9393
cfg := asset.SearchConfig{
94-
Text: "resource",
95-
TypeWhiteList: []string{"topic"},
94+
Text: "resource",
9695
Filters: map[string][]string{
96+
"type": {"topic"},
9797
"service": {"kafka", "rabbitmq"},
9898
"data.landscape": {"th"},
9999
},

internal/store/elasticsearch/discovery_search_repository.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ const (
2424
var returnedAssetFieldsResult = []string{"id", "urn", "type", "service", "name", "description", "data", "labels", "created_at", "updated_at"}
2525

2626
// Search the asset store
27-
// Note that Searcher accepts 2 different forms of type white list,
28-
// depending on how it is passed
29-
// (1) when passed to NewSearcher, this is called the "Global White List" or GL for short
30-
// (2) when passed to Search() as models.SearchConfig.TypeWhiteList, it's called "Local White List" or LL
31-
// GL dictates the superset of all type types that should searched, while LL can only be a subset.
32-
// To demonstrate:
33-
// GL : {A, B, C}
34-
// LL : {C, D}
35-
// Entities searched : {C}
36-
// GL specified that search can only be done for {A, B, C} types, while LL requested
37-
// the search for {C, D} types. Since {D} doesn't belong to GL's set, it won't be searched
3827
func (repo *DiscoveryRepository) Search(ctx context.Context, cfg asset.SearchConfig) (results []asset.SearchResult, err error) {
3928
if strings.TrimSpace(cfg.Text) == "" {
4029
err = errors.New("search text cannot be empty")

0 commit comments

Comments
 (0)