Skip to content

Commit

Permalink
Switch bom to sbom (#761) (#763)
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Emengo <aemengo@vmware.com>

Co-authored-by: Anthony Emengo <aemengo@vmware.com>
Co-authored-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
3 people authored Nov 15, 2021
1 parent b1a2a7c commit 196f637
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (a *Analyzer) Analyze() (platform.AnalyzedMetadata, error) {
if api.MustParse(a.Platform.API()).AtLeast("0.8") {
if appMeta.BOM != nil && appMeta.BOM.SHA != "" {
if err := a.restorePreviousLayer(appMeta.BOM.SHA); err != nil {
return platform.AnalyzedMetadata{}, errors.Wrap(err, "retrieving launch BOM layer")
return platform.AnalyzedMetadata{}, errors.Wrap(err, "retrieving launch sBOM layer")
}
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func (a *Analyzer) Analyze() (platform.AnalyzedMetadata, error) {
if api.MustParse(a.Platform.API()).AtLeast("0.8") {
if cacheMeta.BOM.SHA != "" {
if err := a.restoreCacheLayer(cacheMeta.BOM.SHA); err != nil {
return platform.AnalyzedMetadata{}, errors.Wrap(err, "retrieving cache BOM layer")
return platform.AnalyzedMetadata{}, errors.Wrap(err, "retrieving cache sBOM layer")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func testAnalyzerBuilder(platformAPI string) func(t *testing.T, when spec.G, it
layer, err := factory.DirLayer("launch.sbom", filepath.Join(layersDir, "sbom", "launch"))
h.AssertNil(t, err)
h.AssertNil(t, image.AddLayerWithDiffID(layer.TarPath, layer.Digest))
h.AssertNil(t, image.SetLabel("io.buildpacks.lifecycle.metadata", fmt.Sprintf(`{"bom": {"sha":"%s"}}`, layer.Digest)))
h.AssertNil(t, image.SetLabel("io.buildpacks.lifecycle.metadata", fmt.Sprintf(`{"sbom": {"sha":"%s"}}`, layer.Digest)))

h.AssertNil(t, os.RemoveAll(filepath.Join(layersDir, "sbom")))
})
Expand Down
2 changes: 1 addition & 1 deletion builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (b *Builder) Build() (*platform.BuildMetadata, error) {
}

if b.PlatformAPI.AtLeast("0.8") {
b.Logger.Debug("Copying BOM files")
b.Logger.Debug("Copying sBOM files")
err = b.copyBOMFiles(config.LayersDir, bomFiles)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
}, nil)

_, err := builder.Build()
h.AssertError(t, err, fmt.Sprintf("unsupported bom format: '%s'", bomFilePath2))
h.AssertError(t, err, fmt.Sprintf("unsupported sbom format: '%s'", bomFilePath2))
})

when("build metadata", func() {
Expand Down
10 changes: 5 additions & 5 deletions buildpack/bomfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ type BOMFile struct {
}

// Name() returns the destination filename for a given BOM file
// cdx files should be renamed to "bom.cdx.json"
// spdx files should be renamed to "bom.spdx.json"
// syft files should be renamed to "bom.syft.json"
// cdx files should be renamed to "sbom.cdx.json"
// spdx files should be renamed to "sbom.spdx.json"
// syft files should be renamed to "sbom.syft.json"
// If the BOM is neither cdx, spdx, nor syft, the 2nd return argument
// will return an error to indicate an unsupported format
func (b *BOMFile) Name() (string, error) {
Expand All @@ -46,7 +46,7 @@ func (b *BOMFile) Name() (string, error) {
case mediaTypeSyft:
return "sbom.syft.json", nil
default:
return "", errors.Errorf("unsupported bom format: '%s'", b.Path)
return "", errors.Errorf("unsupported sbom format: '%s'", b.Path)
}
}

Expand Down Expand Up @@ -79,7 +79,7 @@ func validateMediaTypes(bp GroupBuildpack, bomfiles []BOMFile, sbomMediaTypes []
mediaType := bomFile.mediaType()
switch mediaType {
case mediaTypeUnsupported:
return errors.Errorf("unsupported bom format: '%s'", bomFile.Path)
return errors.Errorf("unsupported sbom format: '%s'", bomFile.Path)
default:
if !contains(sbomMediaTypes, mediaType) {
return errors.Errorf("sbom type '%s' not declared for buildpack: '%s'", mediaType, bp.String())
Expand Down
2 changes: 1 addition & 1 deletion buildpack/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
filepath.Join(layersDir, buildpackID, fmt.Sprintf("%s.sbom.some-unknown-format.json", layerName)))

_, err := bpTOML.Build(buildpack.Plan{}, config, mockEnv)
h.AssertError(t, err, fmt.Sprintf("unsupported bom format: '%s'", filepath.Join(layersDir, buildpackID, fmt.Sprintf("%s.sbom.some-unknown-format.json", layerName))))
h.AssertError(t, err, fmt.Sprintf("unsupported sbom format: '%s'", filepath.Join(layersDir, buildpackID, fmt.Sprintf("%s.sbom.some-unknown-format.json", layerName))))
})

it("returns an error for any undeclared BOM media type", func() {
Expand Down
4 changes: 2 additions & 2 deletions exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func testExporter(t *testing.T, when spec.G, it spec.S) {
fakeAppImage.AddPreviousLayer("launch.sbom-digest", "")
h.AssertNil(t, json.Unmarshal([]byte(`
{
"bom": {
"sbom": {
"sha": "launch.sbom-digest"
},
"buildpacks": [
Expand Down Expand Up @@ -821,7 +821,7 @@ version = "4.5.6"
var result struct {
BOM struct {
SHA string `json:"sha"`
} `json:"bom"`
} `json:"sbom"`
}

data, err := fakeAppImage.Label("io.buildpacks.lifecycle.metadata")
Expand Down
2 changes: 1 addition & 1 deletion platform/cache.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package platform

type CacheMetadata struct {
BOM LayerMetadata `json:"bom"`
BOM LayerMetadata `json:"sbom"`
Buildpacks []BuildpackLayersMetadata `json:"buildpacks"`
}

Expand Down
4 changes: 2 additions & 2 deletions platform/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ImageIdentifier struct {
// NOTE: This struct MUST be kept in sync with `LayersMetadataCompat`
type LayersMetadata struct {
App []LayerMetadata `json:"app" toml:"app"`
BOM *LayerMetadata `json:"bom,omitempty" toml:"bom,omitempty"`
BOM *LayerMetadata `json:"sbom,omitempty" toml:"sbom,omitempty"`
Buildpacks []BuildpackLayersMetadata `json:"buildpacks" toml:"buildpacks"`
Config LayerMetadata `json:"config" toml:"config"`
Launcher LayerMetadata `json:"launcher" toml:"launcher"`
Expand All @@ -42,7 +42,7 @@ type LayersMetadata struct {
// guaranteed, yet the original struct data must be maintained.
type LayersMetadataCompat struct {
App interface{} `json:"app" toml:"app"`
BOM *LayerMetadata `json:"bom,omitempty" toml:"bom,omitempty"`
BOM *LayerMetadata `json:"sbom,omitempty" toml:"sbom,omitempty"`
Buildpacks []BuildpackLayersMetadata `json:"buildpacks" toml:"buildpacks"`
Config LayerMetadata `json:"config" toml:"config"`
Launcher LayerMetadata `json:"launcher" toml:"launcher"`
Expand Down
4 changes: 2 additions & 2 deletions restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ func (r *Restorer) restoreSBOMFunc(bomType string) func(path string, info fs.Fil
var bomRegex *regexp.Regexp

if runtime.GOOS == "windows" {
bomRegex = regexp.MustCompile(fmt.Sprintf(`%s\\(.+)\\(.+)\\(bom.+json)`, bomType))
bomRegex = regexp.MustCompile(fmt.Sprintf(`%s\\(.+)\\(.+)\\(sbom.+json)`, bomType))
} else {
bomRegex = regexp.MustCompile(fmt.Sprintf(`%s/(.+)/(.+)/(bom.+json)`, bomType))
bomRegex = regexp.MustCompile(fmt.Sprintf(`%s/(.+)/(.+)/(sbom.+json)`, bomType))
}

return func(path string, info fs.FileInfo, err error) error {
Expand Down
8 changes: 4 additions & 4 deletions restorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,19 +697,19 @@ func testRestorerBuilder(buildpackAPI, platformAPI string) func(t *testing.T, wh
it("restores the previous image SBOM layer", func() {
h.AssertNil(t, restorer.Restore(testCache))

got := h.MustReadFile(t, filepath.Join(layersDir, "buildpack.id", "cache-true.bom.cdx.json"))
got := h.MustReadFile(t, filepath.Join(layersDir, "buildpack.id", "cache-true.sbom.cdx.json"))
want := `{"key": "some-cache-bom-content"}`
h.AssertEq(t, string(got), want)

got = h.MustReadFile(t, filepath.Join(layersDir, "buildpack.id", "launch-true.bom.cdx.json"))
got = h.MustReadFile(t, filepath.Join(layersDir, "buildpack.id", "launch-true.sbom.cdx.json"))
want = `{"key": "some-launch-bom-content"}`
h.AssertEq(t, string(got), want)

got = h.MustReadFile(t, filepath.Join(layersDir, "escaped_buildpack_id", "launch-true.bom.cdx.json"))
got = h.MustReadFile(t, filepath.Join(layersDir, "escaped_buildpack_id", "launch-true.sbom.cdx.json"))
want = `{"key": "some-escaped-launch-bom-content"}`
h.AssertEq(t, string(got), want)

h.AssertPathDoesNotExist(t, filepath.Join(layersDir, "undetected-buildpack.id", "launch-true.bom.cdx.json"))
h.AssertPathDoesNotExist(t, filepath.Join(layersDir, "undetected-buildpack.id", "launch-true.sbom.cdx.json"))
h.AssertPathDoesNotExist(t, filepath.Join(layersDir, "sbom"))
})
})
Expand Down

0 comments on commit 196f637

Please sign in to comment.