From f285d4252c945d29f3d216639bec3f680c242445 Mon Sep 17 00:00:00 2001 From: Christian Zunker <827818+czunker@users.noreply.github.com> Date: Fri, 10 Mar 2023 13:07:19 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20progress=20for=20unscored?= =?UTF-8?q?=20assets=20(#424)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before, the progress bars looked like this, when unscored assets where included: ``` kube-system/coredns ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 0% score: U mondoo-operator/mondoo-client-scan-api ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 0% score: U mondoo-operator/mondoo-operator-controller-manager ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 0% score: U mondoo-operator/mondoo-client-k8s-scan ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% score: A mondoo-operator/mondoo-client-node-minikube ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% score: A 5/5 scanned ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━────────────────────────────────────────────────────────────────────────────────────────────────────────────── 40% ``` Now, it looks like this: ``` kube-system/coredns ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── n/a score: U mondoo-operator/mondoo-client-scan-api ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── n/a score: U mondoo-operator/mondoo-operator-controller-manager ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── n/a score: U mondoo-operator/mondoo-client-k8s-scan ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% score: A mondoo-operator/mondoo-client-node-minikube ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% score: A 2/5 scanned 3/5 n/a ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% ``` --------- Signed-off-by: Christian Zunker --- cli/reporter/print_compact.go | 26 ++++++++++++++------------ policy/scan/local_scanner.go | 6 +++++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/cli/reporter/print_compact.go b/cli/reporter/print_compact.go index 31f8d033..25248732 100644 --- a/cli/reporter/print_compact.go +++ b/cli/reporter/print_compact.go @@ -373,20 +373,22 @@ func (r *defaultReporter) printAssetQueries(resolved *policy.ResolvedPolicy, rep r.out.Write([]byte(NewLineCharacter)) } - r.out.Write([]byte("Controls:" + NewLineCharacter)) - for id, score := range report.Scores { - _, ok := resolved.CollectorJob.ReportingQueries[id] - if !ok { - continue - } + if len(report.Scores) > 0 { + r.out.Write([]byte("Controls:" + NewLineCharacter)) + for id, score := range report.Scores { + _, ok := resolved.CollectorJob.ReportingQueries[id] + if !ok { + continue + } - query, ok := queries[id] - if !ok { - r.out.Write([]byte("Couldn't find any queries for incoming value for " + id)) - continue - } + query, ok := queries[id] + if !ok { + r.out.Write([]byte("Couldn't find any queries for incoming value for " + id)) + continue + } - r.printControl(score, query, asset, resolved, report, results) + r.printControl(score, query, asset, resolved, report, results) + } } } diff --git a/policy/scan/local_scanner.go b/policy/scan/local_scanner.go index 2f4b8051..2269c6b4 100644 --- a/policy/scan/local_scanner.go +++ b/policy/scan/local_scanner.go @@ -601,7 +601,11 @@ func (s *localAssetScanner) run() (*AssetReport, error) { return ar, err } s.ProgressReporter.Score(report.Score.Rating().Letter()) - s.ProgressReporter.Completed() + if report.Score.Rating().Letter() == "U" { + s.ProgressReporter.NotApplicable() + } else { + s.ProgressReporter.Completed() + } log.Debug().Str("asset", s.job.Asset.Mrn).Msg("scan complete") ar.Report = report