diff --git a/internal/install/discovery/process_filterer.go b/internal/install/discovery/process_filterer.go index 8cabbf36e..4e008d325 100644 --- a/internal/install/discovery/process_filterer.go +++ b/internal/install/discovery/process_filterer.go @@ -7,5 +7,5 @@ import ( ) type ProcessFilterer interface { - filter(context.Context, []types.GenericProcess) ([]types.MatchedProcess, error) + filter(context.Context, []types.GenericProcess, types.DiscoveryManifest) ([]types.MatchedProcess, error) } diff --git a/internal/install/discovery/psutil_discoverer.go b/internal/install/discovery/psutil_discoverer.go index fdcf7ebc6..a63251bfd 100644 --- a/internal/install/discovery/psutil_discoverer.go +++ b/internal/install/discovery/psutil_discoverer.go @@ -62,7 +62,7 @@ func (p *PSUtilDiscoverer) Discover(ctx context.Context) (*types.DiscoveryManife processes = append(processes, PSUtilProcess(*pp)) } - matchedProcesses, err := p.processFilterer.filter(ctx, processes) + matchedProcesses, err := p.processFilterer.filter(ctx, processes, m) if err != nil { return nil, err } diff --git a/internal/install/discovery/regex_process_filterer.go b/internal/install/discovery/regex_process_filterer.go index 5f2787203..e498a1b41 100644 --- a/internal/install/discovery/regex_process_filterer.go +++ b/internal/install/discovery/regex_process_filterer.go @@ -23,14 +23,15 @@ func NewRegexProcessFilterer(r recipes.RecipeFetcher) *RegexProcessFilterer { return &f } -func (f *RegexProcessFilterer) filter(ctx context.Context, processes []types.GenericProcess) ([]types.MatchedProcess, error) { +func (f *RegexProcessFilterer) filter(ctx context.Context, processes []types.GenericProcess, manifest types.DiscoveryManifest) ([]types.MatchedProcess, error) { matchedProcesses := getMatchedProcesses(processes) log.Debugf("Filtering recipes with %d processes...", len(matchedProcesses)) - recipes, err := f.recipeFetcher.FetchRecipes(ctx) + recipes, err := f.recipeFetcher.FetchRecipes(ctx, &manifest) if err != nil { return nil, fmt.Errorf("could not retrieve process filter criteria: %s", err) } + for _, r := range recipes { log.Tracef("Match using recipe DisplayName: %s RecipeProcessMatch: %s", r.DisplayName, r.ProcessMatch) } diff --git a/internal/install/discovery/regex_process_filterer_test.go b/internal/install/discovery/regex_process_filterer_test.go index 9d886c19f..e97cc763f 100644 --- a/internal/install/discovery/regex_process_filterer_test.go +++ b/internal/install/discovery/regex_process_filterer_test.go @@ -36,7 +36,7 @@ func TestFilter(t *testing.T) { } f := NewRegexProcessFilterer(mockRecipeFetcher) - filtered, err := f.filter(context.Background(), processes) + filtered, err := f.filter(context.Background(), processes, types.DiscoveryManifest{}) require.NoError(t, err) require.NotNil(t, filtered) @@ -67,7 +67,7 @@ func TestShouldFilterWithCmdLineInsteadOfName(t *testing.T) { mockRecipeFetcher := recipes.NewMockRecipeFetcher() mockRecipeFetcher.FetchRecipesVal = r f := NewRegexProcessFilterer(mockRecipeFetcher) - filtered, err := f.filter(context.Background(), processes) + filtered, err := f.filter(context.Background(), processes, types.DiscoveryManifest{}) require.NoError(t, err) require.NotNil(t, filtered) diff --git a/internal/install/recipes/mock_recipe_fetcher.go b/internal/install/recipes/mock_recipe_fetcher.go index cce2b4d32..4d0cc4f68 100644 --- a/internal/install/recipes/mock_recipe_fetcher.go +++ b/internal/install/recipes/mock_recipe_fetcher.go @@ -41,7 +41,7 @@ func (f *MockRecipeFetcher) FetchRecipe(ctx context.Context, manifest *types.Dis return f.FetchRecipeVal, f.FetchRecipeErr } -func (f *MockRecipeFetcher) FetchRecipes(ctx context.Context) ([]types.Recipe, error) { +func (f *MockRecipeFetcher) FetchRecipes(ctx context.Context, manifest *types.DiscoveryManifest) ([]types.Recipe, error) { f.FetchRecipesCallCount++ return f.FetchRecipesVal, f.FetchRecipesErr } diff --git a/internal/install/recipes/recipe_fetcher.go b/internal/install/recipes/recipe_fetcher.go index 4dd381095..5892b9ccd 100644 --- a/internal/install/recipes/recipe_fetcher.go +++ b/internal/install/recipes/recipe_fetcher.go @@ -10,5 +10,5 @@ import ( type RecipeFetcher interface { FetchRecipe(context.Context, *types.DiscoveryManifest, string) (*types.Recipe, error) FetchRecommendations(context.Context, *types.DiscoveryManifest) ([]types.Recipe, error) - FetchRecipes(context.Context) ([]types.Recipe, error) + FetchRecipes(context.Context, *types.DiscoveryManifest) ([]types.Recipe, error) } diff --git a/internal/install/recipes/service_recipe_fetcher.go b/internal/install/recipes/service_recipe_fetcher.go index 67651cca9..204128857 100644 --- a/internal/install/recipes/service_recipe_fetcher.go +++ b/internal/install/recipes/service_recipe_fetcher.go @@ -103,9 +103,18 @@ func (f *ServiceRecipeFetcher) FetchRecommendations(ctx context.Context, manifes } // FetchRecipes fetches all available recipes from the recipe service. -func (f *ServiceRecipeFetcher) FetchRecipes(ctx context.Context) ([]types.Recipe, error) { +func (f *ServiceRecipeFetcher) FetchRecipes(ctx context.Context, manifest *types.DiscoveryManifest) ([]types.Recipe, error) { var resp recipeSearchQueryResult - if err := f.client.QueryWithResponseAndContext(ctx, recipeSearchQuery, nil, &resp); err != nil { + + criteria := recipeSearchInput{ + InstallTarget: createInstallTarget(manifest), + } + + vars := map[string]interface{}{ + "criteria": criteria, + } + + if err := f.client.QueryWithResponseAndContext(ctx, recipeSearchQuery, vars, &resp); err != nil { return nil, err } diff --git a/internal/install/recipes/service_recipe_fetcher_test.go b/internal/install/recipes/service_recipe_fetcher_test.go index 50f515d38..ce55cf92c 100644 --- a/internal/install/recipes/service_recipe_fetcher_test.go +++ b/internal/install/recipes/service_recipe_fetcher_test.go @@ -43,7 +43,7 @@ func TestFetchFilters(t *testing.T) { s := NewServiceRecipeFetcher(c) - recipes, err := s.FetchRecipes(context.Background()) + recipes, err := s.FetchRecipes(context.Background(), &types.DiscoveryManifest{}) require.NoError(t, err) require.NotNil(t, recipes) require.NotEmpty(t, recipes)