Skip to content

Commit

Permalink
🐛 Let resolved policy tell you if something is a check
Browse files Browse the repository at this point in the history
The output was using an off-handed way of trying to determine if
something is a check. The reporting job type has this exact information.

Fixes #1540
  • Loading branch information
jaym committed Jan 10, 2025
1 parent 1e17bc1 commit 958283d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions cli/reporter/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func ConvertToJSON(data *policy.ReportCollection, out iox.OutputHelper) error {
return errors.New("cannot find resolved pack for " + id + " in report")
}

reportingJobByQrId := map[string]*policy.ReportingJob{}
for _, job := range resolved.CollectorJob.ReportingJobs {
reportingJobByQrId[job.QrId] = job
}

results := report.RawResults()
pre2 := ""
for qid, query := range resolved.ExecutionJob.Queries {
Expand All @@ -114,8 +119,10 @@ func ConvertToJSON(data *policy.ReportCollection, out iox.OutputHelper) error {
continue
}
// checks
if _, ok := report.Scores[qid]; ok {
continue
if rj, ok := reportingJobByQrId[mrn]; ok {
if !(rj.Type == policy.ReportingJob_DATA_QUERY || rj.Type == policy.ReportingJob_CHECK_AND_DATA_QUERY) {
continue
}
}

out.WriteString(pre2 + llx.PrettyPrintString(mrn) + ":")
Expand Down
11 changes: 9 additions & 2 deletions cli/reporter/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func ConvertToProto(data *policy.ReportCollection) (*Report, error) {
return nil, errors.New("cannot find resolved pack for " + id + " in report")
}

reportingJobByQrId := map[string]*policy.ReportingJob{}
for _, job := range resolved.CollectorJob.ReportingJobs {
reportingJobByQrId[job.QrId] = job
}

results := report.RawResults()
if resolved.ExecutionJob == nil {
continue
Expand All @@ -81,8 +86,10 @@ func ConvertToProto(data *policy.ReportCollection) (*Report, error) {
continue
}
// checks
if _, ok := report.Scores[qid]; ok {
continue
if rj, ok := reportingJobByQrId[mrn]; ok {
if !(rj.Type == policy.ReportingJob_DATA_QUERY || rj.Type == policy.ReportingJob_CHECK_AND_DATA_QUERY) {
continue
}
}

buf := &bytes.Buffer{}
Expand Down

0 comments on commit 958283d

Please sign in to comment.