@@ -16,7 +16,6 @@ import (
16
16
"github.com/rs/zerolog/log"
17
17
"go.mondoo.com/cnquery/v12"
18
18
"go.mondoo.com/cnquery/v12/checksums"
19
- "go.mondoo.com/cnquery/v12/llx"
20
19
"go.mondoo.com/cnquery/v12/mqlc"
21
20
"go.mondoo.com/cnquery/v12/mrn"
22
21
"go.mondoo.com/cnquery/v12/providers-sdk/v1/resources"
@@ -402,9 +401,8 @@ func (c *bundleCache) error() error {
402
401
}
403
402
404
403
func (c * bundleCache ) compileQueries (queries []* Mquery , pack * QueryPack ) error {
405
- propsCache := map [string ]PropertyRef {}
406
404
for i := range queries {
407
- c .precompileQuery (queries [i ], pack , propsCache )
405
+ c .precompileQuery (queries [i ], pack )
408
406
}
409
407
410
408
// After the first pass we may have errors. We try to collect as many errors
@@ -416,7 +414,7 @@ func (c *bundleCache) compileQueries(queries []*Mquery, pack *QueryPack) error {
416
414
}
417
415
418
416
for i := range queries {
419
- c .compileQuery (queries [i ], propsCache )
417
+ c .compileQuery (queries [i ])
420
418
}
421
419
422
420
// The second pass on errors is done after we have compiled as much as possible.
@@ -427,7 +425,7 @@ func (c *bundleCache) compileQueries(queries []*Mquery, pack *QueryPack) error {
427
425
428
426
// precompileQuery indexes the query, turns UIDs into MRNs, compiles properties
429
427
// and filters, and pre-processes variants. Also makes sure the query isn't nil.
430
- func (c * bundleCache ) precompileQuery (query * Mquery , pack * QueryPack , propsCache map [ string ] PropertyRef ) {
428
+ func (c * bundleCache ) precompileQuery (query * Mquery , pack * QueryPack ) {
431
429
if query == nil {
432
430
c .errors = append (c .errors , errors .New ("received null query" ))
433
431
return
@@ -458,14 +456,6 @@ func (c *bundleCache) precompileQuery(query *Mquery, pack *QueryPack, propsCache
458
456
c .lookupQuery [query .Mrn ] = query
459
457
}
460
458
461
- // ensure MRNs for properties
462
- for i := range query .Props {
463
- if err := c .compileProp (query .Mrn , query .Props [i ], propsCache ); err != nil {
464
- c .errors = append (c .errors , errors .New ("failed to compile properties for query " + query .Mrn ))
465
- return
466
- }
467
- }
468
-
469
459
// filters have no dependencies, so we can compile them early
470
460
if err := query .Filters .Compile (c .ownerMrn , c .conf .CompilerConfig ); err != nil {
471
461
c .errors = append (c .errors , errors .New ("failed to compile filters for query " + query .Mrn ))
@@ -494,60 +484,25 @@ func (c *bundleCache) precompileQuery(query *Mquery, pack *QueryPack, propsCache
494
484
}
495
485
}
496
486
497
- type propsHandler struct {
498
- queryCache map [string ]PropertyRef
499
- packCache map [string ]PropertyRef
500
- query * Mquery
501
- }
502
-
503
- func (p * propsHandler ) Available () map [string ]* llx.Primitive {
504
- res := make (map [string ]* llx.Primitive , len (p .queryCache ))
505
- for k , v := range p .queryCache {
506
- res [k ] = & llx.Primitive {Type : v .Property .Type }
507
- }
508
- return res
509
- }
510
-
511
- func (p * propsHandler ) All () map [string ]* llx.Primitive {
512
- // note: this allocates possibly too much space, because we don't need as much
513
- // but the call is in errors and auto-complete, so it's rarer
514
- res := make (map [string ]* llx.Primitive , len (p .queryCache )+ len (p .packCache ))
515
- for k , v := range p .packCache {
516
- res [k ] = & llx.Primitive {Type : v .Property .Type }
517
- }
518
- for k , v := range p .queryCache {
519
- res [k ] = & llx.Primitive {Type : v .Property .Type }
520
- }
521
- return res
522
- }
523
-
524
- func (p * propsHandler ) Get (name string ) * llx.Primitive {
525
- // Property lookup happens on 2 layers:
526
- // 1. the property is part of the query definition, we are ll set
527
- // 2. the property is part of the pack definition, then we have to add it to the query
528
- ref , ok := p .queryCache [name ]
529
- if ok {
530
- return & llx.Primitive {Type : ref .Property .Type }
531
- }
532
-
533
- ref , ok = p .packCache [name ]
534
- if ! ok {
535
- return nil
536
- }
537
- p .query .Props = append (p .query .Props , ref .Property )
538
- return & llx.Primitive {Type : ref .Property .Type }
539
- }
540
-
541
487
// Note: you only want to run this, after you are sure that all connected
542
488
// dependencies have been processed. Properties must be compiled. Connected
543
489
// queries may not be ready yet, but we have to have precompiled them.
544
- func (c * bundleCache ) compileQuery (query * Mquery , propsCache map [string ]PropertyRef ) {
545
- props := & propsHandler {
546
- queryCache : propsCache ,
547
- packCache : c .lookupProps ,
548
- query : query ,
490
+ func (c * bundleCache ) compileQuery (query * Mquery ) {
491
+ props := & PropsResolver {
492
+ QueryCache : map [string ]PropertyRef {},
493
+ GlobalCache : c .lookupProps ,
494
+ Query : query ,
495
+ }
496
+
497
+ // ensure MRNs for properties
498
+ for i := range query .Props {
499
+ if err := c .compileProp (query .Mrn , query .Props [i ], props .QueryCache ); err != nil {
500
+ c .errors = append (c .errors , errors .New ("failed to compile properties for query " + query .Mrn ))
501
+ return
502
+ }
549
503
}
550
504
505
+ // now that everything is updated, we can update checksums and compile
551
506
_ , err := query .RefreshChecksumAndType (c .lookupQuery , props , c .conf .CompilerConfig )
552
507
if err != nil {
553
508
if c .conf .RemoveFailing {
0 commit comments