Skip to content

Commit

Permalink
🧹 expose runtime on scanner (#861)
Browse files Browse the repository at this point in the history
Allow us to more easily reconfigure it when needed.

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus authored Oct 19, 2023
1 parent 94f702e commit dc78d57
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions policy/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ func NewPolicyMrn(namespace string, uid string) string {

// ValidateBundle and check queries, relationships, MRNs, and versions
func (s *LocalServices) ValidateBundle(ctx context.Context, bundle *Bundle) (*Empty, error) {
_, err := bundle.Compile(ctx, s.runtime.Schema(), s.DataLake)
_, err := bundle.Compile(ctx, s.Runtime.Schema(), s.DataLake)
return globalEmpty, err
}

// SetBundle stores a bundle of policies and queries in this marketplace
func (s *LocalServices) SetBundle(ctx context.Context, bundle *Bundle) (*Empty, error) {
// See https://gitlab.com/mondoolabs/mondoo/-/issues/595

bundleMap, err := bundle.Compile(ctx, s.runtime.Schema(), s.DataLake)
bundleMap, err := bundle.Compile(ctx, s.Runtime.Schema(), s.DataLake)
if err != nil {
return globalEmpty, err
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func (s *LocalServices) PreparePolicy(ctx context.Context, policyObj *Policy, bu
s.DataLake.GetValidatedPolicy,
s.DataLake.GetQuery,
bundle,
s.runtime.Schema(),
s.Runtime.Schema(),
)
if err != nil {
return nil, nil, err
Expand Down
14 changes: 7 additions & 7 deletions policy/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (s *LocalServices) SetProps(ctx context.Context, req *explorer.PropsReq) (*
// validate that the queries compile and fill in checksums
for i := range req.Props {
prop := req.Props[i]
code, err := prop.RefreshChecksumAndType(s.runtime.Schema())
code, err := prop.RefreshChecksumAndType(s.Runtime.Schema())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -446,7 +446,7 @@ func (s *LocalServices) tryResolve(ctx context.Context, bundleMrn string, assetF

// phase 1: resolve asset filters and see if we can find a cached policy
// trying first with all asset filters
allFiltersChecksum, err := ChecksumAssetFilters(assetFilters, s.runtime.Schema())
allFiltersChecksum, err := ChecksumAssetFilters(assetFilters, s.Runtime.Schema())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -484,7 +484,7 @@ func (s *LocalServices) tryResolve(ctx context.Context, bundleMrn string, assetF
assetFiltersMap[matchingFilters[i].CodeId] = struct{}{}
}

assetFiltersChecksum, err := ChecksumAssetFilters(matchingFilters, s.runtime.Schema())
assetFiltersChecksum, err := ChecksumAssetFilters(matchingFilters, s.Runtime.Schema())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -888,7 +888,7 @@ func (s *LocalServices) policyGroupToJobs(ctx context.Context, group *PolicyGrou
if base, ok := cache.global.bundleMap.Queries[check.Mrn]; ok {
check = check.Merge(base)
err := check.RefreshChecksum(ctx,
s.runtime.Schema(),
s.Runtime.Schema(),
explorer.QueryMap(cache.global.bundleMap.Queries).GetQuery,
)
if err != nil {
Expand Down Expand Up @@ -945,7 +945,7 @@ func (s *LocalServices) policyGroupToJobs(ctx context.Context, group *PolicyGrou
if base, ok := cache.global.bundleMap.Queries[query.Mrn]; ok {
query = query.Merge(base)
err := query.RefreshChecksum(ctx,
s.runtime.Schema(),
s.Runtime.Schema(),
explorer.QueryMap(cache.global.bundleMap.Queries).GetQuery,
)
if err != nil {
Expand Down Expand Up @@ -1211,7 +1211,7 @@ func (s *LocalServices) jobsToQueries(ctx context.Context, policyMrn string, cac
}
}

executionQuery, dataChecksum, err := mquery2executionQuery(prop, nil, map[string]string{}, collectorJob, false, s.runtime.Schema())
executionQuery, dataChecksum, err := mquery2executionQuery(prop, nil, map[string]string{}, collectorJob, false, s.Runtime.Schema())
if err != nil {
return nil, nil, errors.New("resolver> failed to compile query for MRN " + prop.Mrn + ": " + err.Error())
}
Expand All @@ -1226,7 +1226,7 @@ func (s *LocalServices) jobsToQueries(ctx context.Context, policyMrn string, cac
}
}

executionQuery, _, err := mquery2executionQuery(query, propTypes, propToChecksums, collectorJob, !isDataQuery, s.runtime.Schema())
executionQuery, _, err := mquery2executionQuery(query, propTypes, propToChecksums, collectorJob, !isDataQuery, s.Runtime.Schema())
if err != nil {
return nil, nil, errors.New("resolver> failed to compile query for MRN " + query.Mrn + ": " + err.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions policy/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type LocalServices struct {
DataLake DataLake
Upstream *Services
Incognito bool
runtime llx.Runtime
Runtime llx.Runtime
}

// NewLocalServices initializes a reasonably configured local services struct
Expand All @@ -50,7 +50,7 @@ func NewLocalServices(datalake DataLake, uuid string, runtime llx.Runtime) *Loca
DataLake: datalake,
Upstream: nil,
Incognito: false,
runtime: runtime,
Runtime: runtime,
}
}

Expand Down Expand Up @@ -80,5 +80,5 @@ func NewRemoteServices(addr string, auth []ranger.ClientPlugin, httpClient *http
}

func (l *LocalServices) Schema() llx.Schema {
return l.runtime.Schema()
return l.Runtime.Schema()
}

0 comments on commit dc78d57

Please sign in to comment.