Documentation
¶
Overview ¶
Package scainternal holds helpers shared by `krci sca` verbs (validation, enum sets, Dependency-Track error hint, table cells, paging footer).
Index ¶
- Constants
- func BoolYesNo(b bool) string
- func ExpandSeverityFlag(raw []string) []string
- func FormatRisk(r float32) string
- func FormatVulnCounts(m *portal.SCAMetrics) output.Cell
- func HandleError(ios *iostreams.IOStreams, outputFormat string, err error) error
- func InclusiveFromSet(set []string) []string
- func InclusiveSeverities(min string) []string
- func OrDash(s string) string
- func PageFooter(noun string, total, pageIndex, pageSize int) string
- func SeverityColor(severity string) output.Cell
- func ValidateCodebaseCommand(cmd *cobra.Command, outputFormat, codebase, branch string) error
- func ValidateNonEmptyFlag(name string, changed bool, value string) error
- func ValidatePageBounds(page, pageSize int) error
- func ValidateSeverityCSV(values []string) ([]string, error)
Constants ¶
const ( SeverityCritical = "CRITICAL" SeverityHigh = "HIGH" SeverityMedium = "MEDIUM" SeverityLow = "LOW" SeverityInfo = "INFO" SeverityUnassigned = "UNASSIGNED" )
Canonical Dep-Track severity values.
const BranchFlagUsage = "branch name (maps to the Dep-Track project 'version' field). " +
"Defaults to the project's spec.defaultBranch. " +
"Run 'krci sca list --search=<project>' to discover all recorded versions."
BranchFlagUsage is the verbatim help text for `--branch` across every per-codebase sca verb. Spec Requirement "Codebase + Branch Addressing" mandates this exact string so users always see the same Dep-Track `version` field explanation.
const EmptyPlaceholder = "—"
EmptyPlaceholder is the em-dash shown in sca table cells for a missing value.
const FindingsServerCap = 1000
FindingsServerCap is the maximum number of rows the portal returns from the unpaginated `sca findings` endpoint. Mirrors the server-side ceiling documented in the OpenAPI spec; the help text and truncation footer must stay in sync with it.
const MaxPageSize = 500
MaxPageSize is the upper bound on `--page-size` for every paginated sca verb. Matches the OpenAPI ceiling.
const SeverityFlagUsage = "minimum severity to include (inclusive). " +
"One of: critical, high, medium, low, info. Case-insensitive. " +
"'high' returns high+critical; 'medium' returns medium+high+critical; etc. " +
"INFO includes UNASSIGNED."
SeverityFlagUsage is the verbatim help text for `--severity` across the verbs that expose it. Spec design §D4 mandates this exact string: it enumerates the allowed values and explains the inclusive semantics.
Variables ¶
This section is empty.
Functions ¶
func BoolYesNo ¶
BoolYesNo renders a bool as the lowercase "yes" / "no" used by every sca table column.
func ExpandSeverityFlag ¶
ExpandSeverityFlag is the composite helper for run functions: it validates the raw `--severity` flag values (silently ignoring the error — callers are expected to run ValidateSeverityCSV in RunE first) and returns the inclusive "min and above" expansion. nil input returns nil so the caller can skip filtering without a branch on slice length.
func FormatRisk ¶
FormatRisk renders a Dep-Track risk score, using EmptyPlaceholder for zero.
func FormatVulnCounts ¶
func FormatVulnCounts(m *portal.SCAMetrics) output.Cell
FormatVulnCounts renders the C/H/M/L vulnerability counts column. The styled form is yellow when critical+high > 0.
func HandleError ¶
HandleError is render.HandleError with portal.ErrUpstreamUnavailable prefixed by the Dependency-Track hint.
func InclusiveFromSet ¶
InclusiveFromSet returns the inclusive severity set derived from an already-validated `--severity` value list. When several thresholds are supplied, it takes the least-severe one ("medium" when "critical,medium" is supplied) so the expansion pulls everything at or above medium — matching the intent of "include all of these severities plus higher ones".
func InclusiveSeverities ¶
InclusiveSeverities returns the severities that should be included when the user supplies `--severity=<min>`. The return set is "min and above": e.g. `HIGH` → `{CRITICAL, HIGH}`; `INFO` → `{CRITICAL, HIGH, MEDIUM, LOW, INFO, UNASSIGNED}`. An unknown min returns nil so callers can treat that as "no filter" (already validated upstream).
severityOrder is in descending severity (CRITICAL first); we walk from the start through `min` inclusive.
func OrDash ¶
OrDash returns s when non-empty, otherwise EmptyPlaceholder. sca cells use this, not output.OrDash, which returns output.EmptyCell.
func PageFooter ¶
PageFooter formats the paging summary printed below a paginated sca table.
func SeverityColor ¶ added in v0.20.0
SeverityColor colors a Dep-Track vulnerability severity, matched case-insensitively. An unknown severity is made printable on one row and left unstyled.
func ValidateCodebaseCommand ¶
ValidateCodebaseCommand validates a per-codebase sca verb's inputs in order: output format, Kubernetes-name codebase, non-empty --branch when supplied. sca verbs take no --pr, so there is no scope-mutex step.
func ValidateNonEmptyFlag ¶
ValidateNonEmptyFlag rejects a flag that was explicitly supplied with an empty value. changed is true when the flag was set on the command line.
func ValidatePageBounds ¶
ValidatePageBounds rejects out-of-range --page / --page-size values. Shared between every paginated sca verb so the ceiling is enforced uniformly.
func ValidateSeverityCSV ¶
ValidateSeverityCSV canonicalises the comma-separated / repeatable values in values to upper-case Dep-Track severities. Empty input returns nil. An unknown value returns an error listing the accepted values.
The function returns validated values in input order with duplicates collapsed — this makes the test expectations stable.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package scatestutil holds helpers shared by the krci sca verb tests.
|
Package scatestutil holds helpers shared by the krci sca verb tests. |