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

Add source file info to SBOM viewer and better track nested files #1865

Merged
merged 3 commits into from
Jun 30, 2023
Merged
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 src/internal/packager/sbom/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ func (b *Builder) createFileSBOM(componentSBOM types.ComponentSBOM, component st
}

for pkg := range cat.Enumerate() {
containsSource := false

// See if the source locations for this package contain the file Zarf indexed
for _, location := range pkg.Locations.ToSlice() {
if location.RealPath == fileSource.Metadata.Path {
containsSource = true
}
}

// If the locations do not contain the source file (i.e. the package was inside a tarball), add the file source
if !containsSource {
sourceLocation := source.NewLocation(fileSource.Metadata.Path)
pkg.Locations.Add(sourceLocation)
}

catalog.Add(pkg)
}

Expand Down
8 changes: 4 additions & 4 deletions src/internal/packager/sbom/viewer/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const mailtoMaintainerReplace = `&nbsp;|&nbsp;&nbsp;<a href="mailto:$1">$1</a>`;

document.body.appendChild(artifactsTable);

function fileList(metadata) {
if (metadata) {
const list = (metadata.files || []).map((file) => file.path || '').filter((test) => test);
function fileList(files, artifactName) {
if (files) {
const list = (files || []).map((file) => file.path || '').filter((test) => test);

if (list.length > 0) {
flatList = list.sort().join('<br>');
return `<a href="#" onClick="showModal('${
metadata.package || metadata.name
artifactName
}','${flatList}')">${list.length} files</a>`;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/internal/packager/sbom/viewer/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ function loadDataTable(artifacts, dataTable) {
artifact.type,
artifact.name,
artifact.version,
fileList(artifact.metadata),
fileList(artifact.locations, artifact.name),
(artifact.metadata && fileList(artifact.metadata.files, artifact.name)) || '-',
(artifact.metadata && artifact.metadata.description) || '-',
((artifact.metadata && artifact.metadata.maintainer) || '-').replace(
/\u003c(.*)\u003e/,
Expand All @@ -98,7 +99,7 @@ function loadDataTable(artifacts, dataTable) {
});

const data = {
headings: ['Difference', 'Type', 'Name', 'Version', 'Files', 'Notes', 'Maintainer', 'Size'],
headings: ['Difference', 'Type', 'Name', 'Version', 'Sources', 'Package Files', 'Notes', 'Maintainer', 'Size'],
data: transformedData
};

Expand Down
5 changes: 3 additions & 2 deletions src/internal/packager/sbom/viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ function initData() {
artifact.type,
artifact.name,
artifact.version,
fileList(artifact.metadata),
fileList(artifact.locations, artifact.name),
(artifact.metadata && fileList(artifact.metadata.files, artifact.name)) || '-',
(artifact.metadata && artifact.metadata.description) || '-',
((artifact.metadata && artifact.metadata.maintainer) || '-').replace(
/\u003c(.*)\u003e/,
Expand All @@ -26,7 +27,7 @@ function initData() {
});

const data = {
headings: ['Type', 'Name', 'Version', 'Files', 'Notes', 'Maintainer', 'Size'],
headings: ['Type', 'Name', 'Version', 'Sources', 'Package Files', 'Notes', 'Maintainer', 'Size'],
data: transformedData
};

Expand Down