From 66bfd34130be8e7c70338b2fdcb55c3b4ca223b7 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Sat, 23 Sep 2023 23:03:48 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20make=20filter=20queries=20option?= =?UTF-8?q?al?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Analogous to https://github.com/mondoohq/cnspec/pull/741 Also adjust naming of the filter function in the executor. This needs more deduplication of course, but a small step ... 🤏 Signed-off-by: Dominik Richter --- explorer/executor/executor.go | 12 ++++++------ explorer/scan/local_scanner.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/explorer/executor/executor.go b/explorer/executor/executor.go index b645ab4e5a..9b8e8033aa 100644 --- a/explorer/executor/executor.go +++ b/explorer/executor/executor.go @@ -9,6 +9,7 @@ import ( "sync" "time" + "github.com/rs/zerolog/log" "go.mondoo.com/cnquery" "go.mondoo.com/cnquery/cli/progress" "go.mondoo.com/cnquery/explorer" @@ -32,15 +33,16 @@ func RunExecutionJob( return res, res.runCode(job.Queries, timeout) } -func RunFilterQueries(runtime llx.Runtime, queries []*explorer.Mquery, timeout time.Duration) ([]*explorer.Mquery, []error) { - errs := []error{} +func ExecuteFilterQueries(runtime llx.Runtime, queries []*explorer.Mquery, timeout time.Duration) ([]*explorer.Mquery, []error) { equeries := map[string]*explorer.ExecutionQuery{} mqueries := map[string]*explorer.Mquery{} for i := range queries { query := queries[i] code, err := query.Compile(nil, runtime.Schema()) + // Errors for filter queries are common when they reference resources for + // providers that are not found on the system. if err != nil { - errs = append(errs, err) + log.Debug().Err(err).Str("mql", query.Mql).Msg("skipping filter query, not supported") continue } @@ -50,9 +52,6 @@ func RunFilterQueries(runtime llx.Runtime, queries []*explorer.Mquery, timeout t } mqueries[code.CodeV2.Id] = query } - if len(errs) != 0 { - return nil, errs - } instance := newInstance(runtime, nil) err := instance.runCode(equeries, timeout) @@ -62,6 +61,7 @@ func RunFilterQueries(runtime llx.Runtime, queries []*explorer.Mquery, timeout t instance.WaitUntilDone(timeout) + var errs []error res := []*explorer.Mquery{} for _, equery := range equeries { bundle := equery.Code diff --git a/explorer/scan/local_scanner.go b/explorer/scan/local_scanner.go index 2124c371bc..541777fd5f 100644 --- a/explorer/scan/local_scanner.go +++ b/explorer/scan/local_scanner.go @@ -672,7 +672,7 @@ func (s *localAssetScanner) runQueryPack() (*AssetReport, error) { // FilterQueries returns all queries whose result is truthy func (s *localAssetScanner) FilterQueries(queries []*explorer.Mquery, timeout time.Duration) ([]*explorer.Mquery, []error) { - return executor.RunFilterQueries(s.Runtime, queries, timeout) + return executor.ExecuteFilterQueries(s.Runtime, queries, timeout) } // UpdateFilters takes a list of test filters and runs them against the backend