Skip to content

Commit

Permalink
fix(regression): populate p.sbomViewFiles on deploy and mirror (#…
Browse files Browse the repository at this point in the history
…2386)

## Description
Refactoring that took place in
#2223 introduced a bug on
`deploy` where the user is not prompted to view SBOMs. This occurs
because `p.sbomViewFiles` is not being populated correctly. This PR
fixes this issue by populating `p.sbomViewFiles`.

## Related Issue
N/A

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [ ] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
lucasrod16 committed Mar 19, 2024
1 parent b8c83c5 commit 6d2378d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/pkg/layout/sbom.go
Expand Up @@ -69,15 +69,16 @@ func (s *SBOMs) Archive() (err error) {
}

// StageSBOMViewFiles copies SBOM viewer HTML files to the Zarf SBOM directory.
func (s *SBOMs) StageSBOMViewFiles() (warnings []string, err error) {
func (s *SBOMs) StageSBOMViewFiles() (sbomViewFiles, warnings []string, err error) {
if s.IsTarball() {
return nil, fmt.Errorf("unable to process the SBOM files for this package: %s is a tarball", s.Path)
return nil, nil, fmt.Errorf("unable to process the SBOM files for this package: %s is a tarball", s.Path)
}

// If SBOMs were loaded, temporarily place them in the deploy directory
if !helpers.InvalidPath(s.Path) {
if _, err := filepath.Glob(filepath.Join(s.Path, "sbom-viewer-*")); err != nil {
return nil, err
sbomViewFiles, err = filepath.Glob(filepath.Join(s.Path, "sbom-viewer-*"))
if err != nil {
return nil, nil, err
}

if _, err := s.OutputSBOMFiles(SBOMDir, ""); err != nil {
Expand All @@ -87,7 +88,7 @@ func (s *SBOMs) StageSBOMViewFiles() (warnings []string, err error) {
}
}

return warnings, nil
return sbomViewFiles, warnings, nil
}

// OutputSBOMFiles outputs SBOM files into outputDir.
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/packager/deploy.go
Expand Up @@ -54,7 +54,8 @@ func (p *Packager) Deploy() (err error) {
return err
}

sbomWarnings, err := p.layout.SBOMs.StageSBOMViewFiles()
var sbomWarnings []string
p.sbomViewFiles, sbomWarnings, err = p.layout.SBOMs.StageSBOMViewFiles()
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/packager/mirror.go
Expand Up @@ -27,7 +27,8 @@ func (p *Packager) Mirror() (err error) {
return err
}

sbomWarnings, err := p.layout.SBOMs.StageSBOMViewFiles()
var sbomWarnings []string
p.sbomViewFiles, sbomWarnings, err = p.layout.SBOMs.StageSBOMViewFiles()
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions src/test/e2e/20_zarf_init_test.go
Expand Up @@ -69,6 +69,7 @@ func TestZarfInit(t *testing.T) {
_, initStdErr, err := e2e.Zarf("init", "--components="+initComponents, "--nodeport", "31337", "-l", "trace", "--confirm")
require.NoError(t, err)
require.Contains(t, initStdErr, "an inventory of all software contained in this package")
require.NotContains(t, initStdErr, "This package does NOT contain an SBOM. If you require an SBOM, please contact the creator of this package to request a version that includes an SBOM.")

logText := e2e.GetLogFileContents(t, e2e.StripMessageFormatting(initStdErr))

Expand Down

0 comments on commit 6d2378d

Please sign in to comment.