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

Generate label-based BOM for all API versions #105

Merged
merged 1 commit into from
Feb 8, 2022
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
13 changes: 5 additions & 8 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type Application struct {
Logger bard.Logger
BOM *libcnb.BOM
SBOMScanner sbom.SBOMScanner
BuildpackAPI string
}

func (a Application) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
Expand Down Expand Up @@ -123,14 +122,12 @@ func (a Application) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
return libcnb.Layer{}, fmt.Errorf("unable to create Build SBoM \n%w", err)
}

if a.BuildpackAPI == "0.6" || a.BuildpackAPI == "0.5" || a.BuildpackAPI == "0.4" || a.BuildpackAPI == "0.3" || a.BuildpackAPI == "0.2" || a.BuildpackAPI == "0.1" {
entry, err := a.Cache.AsBOMEntry()
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to generate build dependencies\n%w", err)
}
entry.Metadata["layer"] = a.Cache.Name()
a.BOM.Entries = append(a.BOM.Entries, entry)
entry, err := a.Cache.AsBOMEntry()
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to generate build dependencies\n%w", err)
}
entry.Metadata["layer"] = a.Cache.Name()
a.BOM.Entries = append(a.BOM.Entries, entry)

// Purge Workspace
a.Logger.Header("Removing source code")
Expand Down
28 changes: 22 additions & 6 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/buildpacks/libcnb"
. "github.com/onsi/gomega"
"github.com/paketo-buildpacks/libjvm"
"github.com/paketo-buildpacks/libpak"
"github.com/paketo-buildpacks/libpak/bard"
"github.com/paketo-buildpacks/libpak/effect"
Expand Down Expand Up @@ -85,10 +86,9 @@ func testApplication(t *testing.T, context spec.G, it spec.S) {
map[string]interface{}{},
libcnb.LayerTypes{Cache: true},
),
Logger: bard.Logger{},
BOM: bom,
SBOMScanner: sbomScanner,
BuildpackAPI: ctx.Buildpack.API,
Logger: bard.Logger{},
BOM: bom,
SBOMScanner: sbomScanner,
}
})

Expand Down Expand Up @@ -133,7 +133,24 @@ func testApplication(t *testing.T, context spec.G, it spec.S) {
Expect(filepath.Join(ctx.Application.Path, "fixture-marker")).To(BeARegularFile())

sbomScanner.AssertCalled(t, "ScanBuild", ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)
Expect(bom.Entries).To(HaveLen(0))
Expect(bom.Entries).To(HaveLen(1))
Expect(bom.Entries).To(Equal([]libcnb.BOMEntry{
libcnb.BOMEntry{
Name: "build-dependencies",
Metadata: map[string]interface{}{
"layer": "cache",
"dependencies": []libjvm.MavenJAR{
{
Name: "test-file",
Version: "1.1.1",
SHA256: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
},
},
},
Launch: false,
Build: true,
},
}))
})

context("contributes layer with ", func() {
Expand Down Expand Up @@ -285,7 +302,6 @@ func testApplication(t *testing.T, context spec.G, it spec.S) {
Expect(filepath.Join(ctx.Application.Path, "native-sources", "stub-executable.jar")).To(BeAnExistingFile())
Expect(filepath.Join(ctx.Application.Path, "code-sources", "source-stub-application.jar")).To(BeAnExistingFile())
Expect(filepath.Join(ctx.Application.Path, "code-sources", "source-stub-executable.jar")).To(BeAnExistingFile())

})
})
})
Expand Down
2 changes: 0 additions & 2 deletions factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func (f *ApplicationFactory) NewApplication(
bom *libcnb.BOM,
applicationPath string,
bomScanner sbom.SBOMScanner,
buildpackAPI string,
) (Application, error) {

app := Application{
Expand All @@ -49,7 +48,6 @@ func (f *ApplicationFactory) NewApplication(
Executor: f.Executor,
BOM: bom,
SBOMScanner: bomScanner,
BuildpackAPI: buildpackAPI,
}

expected, err := f.expectedMetadata(additionalMetadata, app)
Expand Down
2 changes: 0 additions & 2 deletions factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func testFactory(t *testing.T, context spec.G, it spec.S) {
},
}
bomScanner := sbom.NewSyftCLISBOMScanner(libcnb.Layers{}, executor, bard.Logger{})
buildpackAPI := "0.7"

application, err = applicationFactory.NewApplication(
map[string]interface{}{"addl-key": "addl-value"},
Expand All @@ -97,7 +96,6 @@ func testFactory(t *testing.T, context spec.G, it spec.S) {
nil,
appDir,
bomScanner,
buildpackAPI,
)
Expect(err).NotTo(HaveOccurred())
})
Expand Down