Skip to content

ROX-30571: Make roxctl image scan print logic reusable#18658

Merged
dcaravel merged 2 commits intomasterfrom
dc/move-roxctl-scan-print
Apr 1, 2026
Merged

ROX-30571: Make roxctl image scan print logic reusable#18658
dcaravel merged 2 commits intomasterfrom
dc/move-roxctl-scan-print

Conversation

@dcaravel
Copy link
Copy Markdown
Contributor

@dcaravel dcaravel commented Jan 23, 2026

Description

This PR includes no functional changes - it moves the printing logic associated with roxctl image scan to a common location so that it can be reused by the roxctl sbom scan command that is introduced in (#18503).

PR created per request of Sensor & Ecosystem to split #18503 into multiple PRs

The new files in roxctl/common/scan/* are not new, they were moved from roxctl/image/scan so that they could be re-used. Minor tweaks were made to enable reuse. The files were moved as follows:

src dst
roxctl/image/scan/cve.go roxctl/common/scan/cve.go
roxctl/image/scan/cve_test.go roxctl/common/scan/cve_test.go
roxctl/image/scan/scan_errors.go roxctl/common/scan/errors.go
roxctl/image/scan/scan.go (printCVESummary() and printCVEWarning()) roxctl/common/scan/print.go
roxctl/image/scan/scan.go (sarifJSONPathExpressions) roxctl/common/scan/sarif.go

PR Stack:

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

No functional changes, existing tests apply

How I validated my change

See #18503

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Jan 23, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Consider returning a copy of AllSeverities from a helper (e.g. DefaultSeverities() []string) instead of exposing a mutable package-level slice, to avoid accidental modification by callers.
  • The cveSeverityFromString function silently maps unknown severity strings to LowCVESeverity; consider returning an error or a boolean flag instead so unexpected inputs don’t get coerced without visibility.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider returning a copy of `AllSeverities` from a helper (e.g. `DefaultSeverities() []string`) instead of exposing a mutable package-level slice, to avoid accidental modification by callers.
- The `cveSeverityFromString` function silently maps unknown severity strings to `LowCVESeverity`; consider returning an error or a boolean flag instead so unexpected inputs don’t get coerced without visibility.

## Individual Comments

### Comment 1
<location> `roxctl/common/scan/cve.go:25-34` </location>
<code_context>
 )

-func (c cveSeverity) String() string {
+var (
+	AllSeverities = []string{
+		LowCVESeverity.String(),
+		ModerateCVESeverity.String(),
</code_context>

<issue_to_address>
**suggestion (bug_risk):** AllSeverities being a mutable exported slice can be modified by callers and desynchronize validation logic.

External packages can currently append, remove, or reorder entries, which may cause Validate and other logic relying on the original set/order to behave incorrectly at runtime. Consider returning a copy via an accessor (e.g. `AllSeverities() []string`) or making the slice unexported and exposing a controlled API so supported severities remain immutable.

```suggestion
var (
	allSeverities = []string{
		LowCVESeverity.String(),
		ModerateCVESeverity.String(),
		ImportantCVESeverity.String(),
		CriticalCVESeverity.String(),
	}
)

// AllSeverities returns a copy of the supported CVE severity labels.
// Callers can safely use and modify the returned slice without affecting
// the internal canonical list.
func AllSeverities() []string {
	out := make([]string, len(allSeverities))
	copy(out, allSeverities)
	return out
}

type CVESeverity int
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dcaravel dcaravel force-pushed the dc/move-roxctl-scan-print branch from 172deec to 6b316e3 Compare January 23, 2026 15:19
@rhacs-bot
Copy link
Copy Markdown
Contributor

rhacs-bot commented Jan 23, 2026

Images are ready for the commit at 9ebda95.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-113-g9ebda95f29.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 23, 2026

Codecov Report

❌ Patch coverage is 66.07143% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.49%. Comparing base (b325e78) to head (9ebda95).
⚠️ Report is 417 commits behind head on master.

Files with missing lines Patch % Lines
roxctl/common/scan/print.go 0.00% 13 Missing ⚠️
roxctl/common/scan/cve.go 87.87% 4 Missing ⚠️
roxctl/common/scan/errors.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #18658      +/-   ##
==========================================
- Coverage   49.50%   49.49%   -0.02%     
==========================================
  Files        2667     2668       +1     
  Lines      201389   201385       -4     
==========================================
- Hits        99693    99668      -25     
- Misses      94254    94274      +20     
- Partials     7442     7443       +1     
Flag Coverage Δ
go-unit-tests 49.49% <66.07%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dcaravel dcaravel marked this pull request as ready for review January 23, 2026 22:44
@dcaravel dcaravel requested a review from a team as a code owner January 23, 2026 22:44
@dcaravel dcaravel requested a review from BradLugo January 23, 2026 22:45
@dcaravel dcaravel mentioned this pull request Jan 23, 2026
6 tasks
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dcaravel dcaravel force-pushed the dc/sbom-ingest-central-api branch from 01e65a6 to 09f9e5f Compare February 13, 2026 20:18
@dcaravel dcaravel requested a review from a team as a code owner February 13, 2026 20:18
Base automatically changed from dc/sbom-ingest-central-api to master February 13, 2026 23:36
@dcaravel dcaravel force-pushed the dc/move-roxctl-scan-print branch from 6b316e3 to ec5db7e Compare February 13, 2026 23:39
@dcaravel dcaravel force-pushed the dc/move-roxctl-scan-print branch from ec5db7e to 9ebda95 Compare February 13, 2026 23:42
@dcaravel dcaravel merged commit f042134 into master Apr 1, 2026
98 checks passed
@dcaravel dcaravel deleted the dc/move-roxctl-scan-print branch April 1, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants