Skip to content

Commit

Permalink
Show OS name in cve report
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Feb 19, 2024
1 parent 2a507d0 commit 2b847cd
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions cmd/generate-cve-report/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func main() {

type CVEReport struct {
Ref string
OS string
Critical Stats
High Stats
Medium Stats
Expand All @@ -65,6 +66,20 @@ type Stats struct {
Other int
}

func (s Stats) PrettyPrint() string {
b, a := "0", "0"
if s.OS >= 0 {
b = strconv.Itoa(s.OS)
}
if s.Other >= 0 {
a = strconv.Itoa(s.Other)
}
if s.OS > 0 {
return fmt.Sprintf("**%s**, %s", b, a)
}
return fmt.Sprintf("%s, %s", b, a)
}

func (s Stats) String() string {
b, a := "0", "0"
if s.OS >= 0 {
Expand All @@ -91,6 +106,7 @@ func (r CVEReport) NoCVE() bool {
func (r CVEReport) Headers() []string {
return []string{
"Image Ref",
"OS",
"Critical<br>(os, other)",
"High<br>(os, other)",
"Medium<br>(os, other)",
Expand All @@ -102,8 +118,9 @@ func (r CVEReport) Headers() []string {
func (r CVEReport) Strings() []string {
return []string{
r.Ref,
r.Critical.String(),
r.High.String(),
r.OS,
r.Critical.PrettyPrint(),
r.High.PrettyPrint(),
r.Medium.String(),
r.Low.String(),
r.Unknown.String(),
Expand Down Expand Up @@ -154,6 +171,8 @@ func gatherReport(sh *shell.Session, ref string) (CVEReport, error) {
}

func setReport(report *trivy.SingleReport, result *CVEReport) {
result.OS = fmt.Sprintf("%s %s", report.Metadata.Os.Family, report.Metadata.Os.Name)

for _, rpt := range report.Results {
for _, tv := range rpt.Vulnerabilities {
switch tv.Severity {
Expand Down

0 comments on commit 2b847cd

Please sign in to comment.