Skip to content

Commit

Permalink
🐛 make filter queries optional
Browse files Browse the repository at this point in the history
Analogous to mondoohq/cnspec#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 <[email protected]>
  • Loading branch information
arlimus committed Sep 24, 2023
1 parent 71b7530 commit 66bfd34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions explorer/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion explorer/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 66bfd34

Please sign in to comment.