Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(output): display base image info on HTML output #1487

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/output/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,21 @@ func testOutputWithVulnerabilities(t *testing.T, run outputTestRunner) {
}
}

// func testOutputWithVulnerabilitiesContainer(t *testing.T, run outputTestRunner) {
// t.Helper()

// tests := []outputTestCase{
// {
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// t.Parallel()

// run(t, tt.args)
// })
// }
// }

func testOutputWithLicenseViolations(t *testing.T, run outputTestRunner) {
t.Helper()

Expand Down
1 change: 1 addition & 0 deletions internal/output/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func PrintHTMLResults(vulnResult *models.VulnerabilityResults, outputWriter io.W
return a + b
},
"getFilteredVulnReasons": getFilteredVulnReasons,
"getBaseImageNames": getBaseImageNames,
}

tmpl := template.Must(template.New("").Funcs(funcMap).ParseFS(templates, TemplateDir))
Expand Down
56 changes: 56 additions & 0 deletions internal/output/html/base_image_template.gohtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

<div id="base-image-section">
<table id="base-image-table">
<tr>
<th></th>
<th class="base-image-title">OS version:</th>
<th>{{ .ImageInfo.OS }}</th>
</tr>
{{ $totalVuln := .VulnTypeSummary.All }}
{{ range .ImageInfo.AllBaseImages}}

<tr {{ if gt .Count.AnalysisCount.Regular 0}}
id="base-image-summary-{{ .Index }}"
class="base-image-summary"
onclick="showBaseImageLayer('{{ .Index }}')"
{{ end }}>
<td class="icon-td">
{{ if gt .Count.AnalysisCount.Regular 0}}
<div class="expand-icon">
<i class="material-icons">play_arrow</i>
</div>
{{ end }}
</td>
<td class="base-image-title">
{{ if eq .Index 0}}
Your image:
{{ else }}
Base image {{ .Index }}:
{{ end }}
</td>
<td>
{{ getBaseImageNames . }}<span class="base-image-title"> ({{ .Count.AnalysisCount.Regular }}/{{ $totalVuln }} vulnerabilities)</span>
</td>
</tr>

<tr>
<td></td>
<td colspan="100%">
<div id="base-image-details-{{ .Index }}" class="base-image-details">
{{ range .AllLayers }}
<div title="{{ .LayerDiffID}}" class="layer-entry" >
<p><span class="base-image-title">{{ .Index }}</span> {{ .LayerCommand }}</p>
{{ if gt .Count.AnalysisCount.Regular 0 }}
{{ template "severity_summary_template.gohtml".Count.SeverityCount }}
{{ end }}
</div>
{{ end }}
</div>
</td>
</tr>

{{ end }}

</table>

</div>
9 changes: 6 additions & 3 deletions internal/output/html/filter_template.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
<p>All layers ({{ .VulnCount.AnalysisCount.Regular }})</p>
{{ template "severity_summary_template.gohtml" .VulnCount.SeverityCount }}
</div>
{{ range .AllLayers }}
<div title="{{ .LayerID}}" class="filter-option layer-filter-option">
<p>{{ .Index }} {{ .LayerCommand }}</p>
{{ range .ImageInfo.AllLayers }}
{{ if gt .Count.AnalysisCount.Regular 0 }}
<div title="{{ .LayerDiffID}}" class="filter-option layer-filter-option">
<p>
{{ .Index }} {{ .LayerCommand }}</p>
{{ template "severity_summary_template.gohtml".Count.SeverityCount }}
</div>
{{ end }}
{{ end }}
</div>
</div>
{{ end }}
Expand Down
16 changes: 8 additions & 8 deletions internal/output/html/package_table_template.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{{ range $rowIndex, $element := . }}
{{ $index := uniqueID }}
<tr class="table-tr package-tr {{if $element.LayerDetail }}has-layer-info"
data-layer="{{ $element.LayerDetail.LayerID }}{{ end }}" id="table-tr-{{ $index }}" onclick="showPackageDetails('{{ $index }}')">
data-layer="{{ $element.LayerDetail.LayerDiffID }}{{ end }}" id="table-tr-{{ $index }}" onclick="showPackageDetails('{{ $index }}')">
<td class="icon-td">
<div class="expand-icon">
<i class="material-icons">play_arrow</i>
Expand Down Expand Up @@ -55,19 +55,19 @@
<tr>
<td colspan="100%">
<div id="table-tr-{{ $index }}-details" class="package-details">
{{ if and $element.LayerDetail (not (eq $element.LayerDetail.LayerID "")) }}
{{ if and $element.LayerDetail (not (eq $element.LayerDetail.LayerDiffID "")) }}
<div class="layer-command-container">
<span class="package-detail-title">Layer introduced in:</span>
{{ if ne $element.LayerDetail.LayerCommandDetailed "" }}
<div class="tooltip">{{ $element.LayerDetail.LayerCommand }}
<span class="tooltiptext">{{ $element.LayerDetail.LayerCommandDetailed }}</span>
{{ if ne $element.LayerDetail.LayerInfo.LayerCommandDetailed "" }}
<div class="tooltip">{{ $element.LayerDetail.LayerInfo.LayerCommand }}
<span class="tooltiptext">{{ $element.LayerDetail.LayerInfo.LayerCommandDetailed }}</span>
</div>
{{ else }}
<div>{{ $element.LayerDetail.LayerCommand }}</div>
<div>{{ $element.LayerDetail.LayerInfo.LayerCommand }}</div>
{{ end }}
</div>
<p><span class="package-detail-title">Layer ID:</span> {{ $element.LayerDetail.LayerID }}</p>
<p><span class="package-detail-title">In base image:</span> {{ $element.LayerDetail.InBaseImage }}</p>
<p><span class="package-detail-title">Layer ID:</span> {{ $element.LayerDetail.LayerInfo.LayerDiffID }}</p>
<p><span class="package-detail-title">In base image:</span> {{ if eq $element.LayerDetail.LayerInfo.BaseImageIndex 0}} False {{ else }} True ({{ getBaseImageNames $element.LayerDetail.BaseImageInfo }}){{ end }}</p>
{{ end }}
{{ template "vuln_table_template.gohtml" $element }}
</div>
Expand Down
4 changes: 4 additions & 0 deletions internal/output/html/report_template.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<div id="summary-tab" class="tab">
{{ template "filter_template.gohtml" .}}

{{ if .IsContainerScanning }}
{{ template "base_image_template.gohtml" .}}
{{end}}

<div class="search-box">
<div class="search-icon">
<i class="material-icons">search</i>
Expand Down
18 changes: 18 additions & 0 deletions internal/output/html/script.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<script>
function showBaseImageLayer(imageID) {
var detailElementID = "base-image-details-" + imageID
var detailsElement = document.getElementById(detailElementID);

const icon = document.querySelector(
`#base-image-summary-${imageID} .material-icons`
); // Select the icon within the row
if (detailsElement.style.display !== "block") {
detailsElement.style.display = "block";
icon.style.transform = "rotate(90deg)"; // Rotate 90 degrees
icon.style.transition = "transform 0.2s ease"; // Add smooth transition
} else {
detailsElement.style.display = "none";
icon.style.transform = "rotate(0deg)"; // Rotate back to 0 degrees
icon.style.transition = "transform 0.2s ease"; // Add smooth transition
}
}

function showPackageDetails(detailsId) {
var detailsElement = document.getElementById(
"table-tr-" + detailsId + "-details"
Expand Down
58 changes: 50 additions & 8 deletions internal/output/html/style.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@
margin-top: 20px;
}

details summary {
cursor: pointer;
}

details p {
margin-left: 10px;
}

header {
display: flex;
align-items: center;
Expand Down Expand Up @@ -521,4 +513,54 @@
.flex-box {
display: flex;
}

/* new added */
.base-icon .tooltiptext {
margin-left: 0px;
background-color: #292929;
}

div.title {
visibility: hidden;
}

#base-image-section {
margin-top: 30px;
border: 1px solid #fff;
border-radius: 8px;
padding: 10px 20px;
max-height: 400px;
overflow-y: visible;
overflow-x: hidden;
}

#base-image-table {
width: 100%;
}

#base-image-table th {
text-align: left;
height: 30px;
}

.layer-entry {
display: flex;
justify-content: space-between;
margin: 0 10px;
border-bottom: 1px dotted #666666;
}

.base-image-summary {
cursor: pointer;
}

.base-image-details {
display: none;
}

.base-image-title {
width: 150px;
color: #9aa0a6;
height: 20px;
}
</style>
Loading
Loading