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 and source sha256 to postal dependency bom generation #213

Merged
merged 3 commits into from
Jul 28, 2021
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
6 changes: 5 additions & 1 deletion postal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ func (s Service) GenerateBillOfMaterials(dependencies ...Dependency) []packit.BO
entry := packit.BOMEntry{
Name: dependency.Name,
Metadata: map[string]interface{}{
"sha256": dependency.SHA256,
"sha256": dependency.SHA256,
"source": map[string]string{
"sha256": dependency.SourceSHA256,
"uri": dependency.Source,
},
"stacks": dependency.Stacks,
"uri": dependency.URI,
"version": dependency.Version,
Expand Down
130 changes: 80 additions & 50 deletions postal/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,29 +961,35 @@ version = "this is super not semver"
it("returns a list of BOMEntry values", func() {
entries := service.GenerateBillOfMaterials(
postal.Dependency{
ID: "some-entry",
Name: "Some Entry",
SHA256: "some-sha",
Source: "some-source",
Stacks: []string{"some-stack"},
URI: "some-uri",
Version: "1.2.3",
ID: "some-entry",
Name: "Some Entry",
SHA256: "some-sha",
Source: "some-source",
SourceSHA256: "some-source-sha",
Stacks: []string{"some-stack"},
URI: "some-uri",
Version: "1.2.3",
},
postal.Dependency{
ID: "other-entry",
Name: "Other Entry",
SHA256: "other-sha",
Source: "other-source",
Stacks: []string{"other-stack"},
URI: "other-uri",
Version: "4.5.6",
ID: "other-entry",
Name: "Other Entry",
SHA256: "other-sha",
Source: "other-source",
SourceSHA256: "other-source-sha",
Stacks: []string{"other-stack"},
URI: "other-uri",
Version: "4.5.6",
},
)
Expect(entries).To(Equal([]packit.BOMEntry{
{
Name: "Some Entry",
Metadata: map[string]interface{}{
"sha256": "some-sha",
"sha256": "some-sha",
"source": map[string]string{
"sha256": "some-source-sha",
"uri": "some-source",
},
"stacks": []string{"some-stack"},
"uri": "some-uri",
"version": "1.2.3",
Expand All @@ -992,7 +998,11 @@ version = "this is super not semver"
{
Name: "Other Entry",
Metadata: map[string]interface{}{
"sha256": "other-sha",
"sha256": "other-sha",
"source": map[string]string{
"sha256": "other-source-sha",
"uri": "other-source",
},
"stacks": []string{"other-stack"},
"uri": "other-uri",
"version": "4.5.6",
Expand All @@ -1005,23 +1015,28 @@ version = "this is super not semver"
it("generates a BOM with the CPE", func() {
entries := service.GenerateBillOfMaterials(
postal.Dependency{
CPE: "some-cpe",
ID: "some-entry",
Name: "Some Entry",
SHA256: "some-sha",
Source: "some-source",
Stacks: []string{"some-stack"},
URI: "some-uri",
Version: "1.2.3",
CPE: "some-cpe",
ID: "some-entry",
Name: "Some Entry",
SHA256: "some-sha",
Source: "some-source",
SourceSHA256: "some-source-sha",
Stacks: []string{"some-stack"},
URI: "some-uri",
Version: "1.2.3",
},
)

Expect(entries).To(Equal([]packit.BOMEntry{
{
Name: "Some Entry",
Metadata: map[string]interface{}{
"cpe": "some-cpe",
"sha256": "some-sha",
"cpe": "some-cpe",
"sha256": "some-sha",
"source": map[string]string{
"sha256": "some-source-sha",
"uri": "some-source",
},
"stacks": []string{"some-stack"},
"uri": "some-uri",
"version": "1.2.3",
Expand All @@ -1048,6 +1063,7 @@ version = "this is super not semver"
Name: "Some Entry",
SHA256: "some-sha",
Source: "some-source",
SourceSHA256: "some-source-sha",
Stacks: []string{"some-stack"},
URI: "some-uri",
Version: "1.2.3",
Expand All @@ -1060,9 +1076,13 @@ version = "this is super not semver"
Metadata: map[string]interface{}{
"deprecation-date": deprecationDate,
"sha256": "some-sha",
"stacks": []string{"some-stack"},
"uri": "some-uri",
"version": "1.2.3",
"source": map[string]string{
"sha256": "some-source-sha",
"uri": "some-source",
},
"stacks": []string{"some-stack"},
"uri": "some-uri",
"version": "1.2.3",
},
},
}))
Expand All @@ -1073,14 +1093,15 @@ version = "this is super not semver"
it("generates a BOM with the license information", func() {
entries := service.GenerateBillOfMaterials(
postal.Dependency{
ID: "some-entry",
Licenses: []string{"some-license"},
Name: "Some Entry",
SHA256: "some-sha",
Source: "some-source",
Stacks: []string{"some-stack"},
URI: "some-uri",
Version: "1.2.3",
ID: "some-entry",
Licenses: []string{"some-license"},
Name: "Some Entry",
SHA256: "some-sha",
Source: "some-source",
SourceSHA256: "some-source-sha",
Stacks: []string{"some-stack"},
URI: "some-uri",
Version: "1.2.3",
},
)

Expand All @@ -1090,9 +1111,13 @@ version = "this is super not semver"
Metadata: map[string]interface{}{
"licenses": []string{"some-license"},
"sha256": "some-sha",
"stacks": []string{"some-stack"},
"uri": "some-uri",
"version": "1.2.3",
"source": map[string]string{
"sha256": "some-source-sha",
"uri": "some-source",
},
"stacks": []string{"some-stack"},
"uri": "some-uri",
"version": "1.2.3",
},
},
}))
Expand All @@ -1103,23 +1128,28 @@ version = "this is super not semver"
it("generates a BOM with the pURL", func() {
entries := service.GenerateBillOfMaterials(
postal.Dependency{
ID: "some-entry",
Name: "Some Entry",
PURL: "some-purl",
SHA256: "some-sha",
Source: "some-source",
Stacks: []string{"some-stack"},
URI: "some-uri",
Version: "1.2.3",
ID: "some-entry",
Name: "Some Entry",
PURL: "some-purl",
SHA256: "some-sha",
Source: "some-source",
SourceSHA256: "some-source-sha",
Stacks: []string{"some-stack"},
URI: "some-uri",
Version: "1.2.3",
},
)

Expect(entries).To(Equal([]packit.BOMEntry{
{
Name: "Some Entry",
Metadata: map[string]interface{}{
"purl": "some-purl",
"sha256": "some-sha",
"purl": "some-purl",
"sha256": "some-sha",
"source": map[string]string{
"sha256": "some-source-sha",
"uri": "some-source",
},
"stacks": []string{"some-stack"},
"uri": "some-uri",
"version": "1.2.3",
Expand Down