Skip to content

Commit

Permalink
de-dupe
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 committed Sep 23, 2024
1 parent add9085 commit 3d3930e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/internal/packager/sbom/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ func (b *Builder) createImageSBOM(ctx context.Context, img v1.Image, src string)
Reference: refInfo.Reference,
})

cfg := syft.DefaultCreateSBOMConfig()
cfg.ToolName = "zarf"
cfg.ToolVersion = config.CLIVersion
cfg := getDefaultSyftConfig()
sbom, err := syft.CreateSBOM(ctx, syftSrc, cfg)
if err != nil {
return nil, err
Expand Down Expand Up @@ -213,10 +211,7 @@ func (b *Builder) createFileSBOM(ctx context.Context, componentSBOM layout.Compo
return nil, err
}

cfg := syft.DefaultCreateSBOMConfig()
cfg.ToolName = "zarf"
cfg.ToolVersion = config.CLIVersion

cfg := getDefaultSyftConfig()
sbom, err := syft.CreateSBOM(ctx, fileSrc, cfg)
if err != nil {
return nil, err
Expand Down Expand Up @@ -253,7 +248,8 @@ func (b *Builder) createFileSBOM(ctx context.Context, componentSBOM layout.Compo

artifact := sbom.SBOM{
Descriptor: sbom.Descriptor{
Name: "zarf",
Name: "zarf",
Version: config.CLIVersion,
},
Source: parentSource.Describe(),
Artifacts: sbom.Artifacts{
Expand Down Expand Up @@ -292,3 +288,10 @@ func (b *Builder) createSBOMFile(filename string) (*os.File, error) {
path := filepath.Join(b.outputDir, b.getNormalizedFileName(filename))
return os.Create(path)
}

func getDefaultSyftConfig() *syft.CreateSBOMConfig {
cfg := syft.DefaultCreateSBOMConfig()
cfg.ToolName = "zarf"
cfg.ToolVersion = config.CLIVersion
return cfg
}

0 comments on commit 3d3930e

Please sign in to comment.