Skip to content

Commit 7eb236e

Browse files
ForestEckhardtryanmoran
authored andcommitted
Adds pURL, licenses, and CPE fields to the BOM generator
1 parent e64ce7b commit 7eb236e

File tree

3 files changed

+160
-20
lines changed

3 files changed

+160
-20
lines changed

postal/buildpack.go

+9
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,24 @@ import (
1010

1111
// Dependency is a representation of a buildpack dependency.
1212
type Dependency struct {
13+
// CPE is the Common Platform Enumerator for the dependency.
14+
CPE string `toml:"cpe"`
15+
1316
// DeprecationDate is the data upon which this dependency is considered deprecated.
1417
DeprecationDate time.Time `toml:"deprecation_date"`
1518

1619
// ID is the identifier used to specify the dependency.
1720
ID string `toml:"id"`
1821

22+
// Licenses is a list of SPDX license identifiers of licenses in the dependency.
23+
Licenses []string `toml:"licenses"`
24+
1925
// Name is the human-readable name of the dependency.
2026
Name string `toml:"name"`
2127

28+
// PURL is the package URL for the dependency.
29+
PURL string `toml:"purl"`
30+
2231
// SHA256 is the hex-encoded SHA256 checksum of the built dependency.
2332
SHA256 string `toml:"sha256"`
2433

postal/service.go

+12
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,22 @@ func (s Service) GenerateBillOfMaterials(dependencies ...Dependency) []packit.BO
196196
},
197197
}
198198

199+
if dependency.CPE != "" {
200+
entry.Metadata["cpe"] = dependency.CPE
201+
}
202+
199203
if (dependency.DeprecationDate != time.Time{}) {
200204
entry.Metadata["deprecation-date"] = dependency.DeprecationDate
201205
}
202206

207+
if dependency.Licenses != nil {
208+
entry.Metadata["licenses"] = dependency.Licenses
209+
}
210+
211+
if dependency.PURL != "" {
212+
entry.Metadata["purl"] = dependency.PURL
213+
}
214+
203215
entries = append(entries, entry)
204216
}
205217

postal/service_test.go

+139-20
Original file line numberDiff line numberDiff line change
@@ -957,25 +957,17 @@ version = "this is super not semver"
957957
})
958958

959959
context("GenerateBillOfMaterials", func() {
960-
var deprecationDate time.Time
961-
962-
it.Before(func() {
963-
var err error
964-
deprecationDate, err = time.Parse(time.RFC3339, "2022-04-01T00:00:00Z")
965-
Expect(err).NotTo(HaveOccurred())
966-
})
967960

968961
it("returns a list of BOMEntry values", func() {
969962
entries := service.GenerateBillOfMaterials(
970963
postal.Dependency{
971-
DeprecationDate: deprecationDate,
972-
ID: "some-entry",
973-
Name: "Some Entry",
974-
SHA256: "some-sha",
975-
Source: "some-source",
976-
Stacks: []string{"some-stack"},
977-
URI: "some-uri",
978-
Version: "1.2.3",
964+
ID: "some-entry",
965+
Name: "Some Entry",
966+
SHA256: "some-sha",
967+
Source: "some-source",
968+
Stacks: []string{"some-stack"},
969+
URI: "some-uri",
970+
Version: "1.2.3",
979971
},
980972
postal.Dependency{
981973
ID: "other-entry",
@@ -991,11 +983,10 @@ version = "this is super not semver"
991983
{
992984
Name: "Some Entry",
993985
Metadata: map[string]interface{}{
994-
"deprecation-date": deprecationDate,
995-
"sha256": "some-sha",
996-
"stacks": []string{"some-stack"},
997-
"uri": "some-uri",
998-
"version": "1.2.3",
986+
"sha256": "some-sha",
987+
"stacks": []string{"some-stack"},
988+
"uri": "some-uri",
989+
"version": "1.2.3",
999990
},
1000991
},
1001992
{
@@ -1009,5 +1000,133 @@ version = "this is super not semver"
10091000
},
10101001
}))
10111002
})
1003+
1004+
context("when there is a CPE", func() {
1005+
it("generates a BOM with the CPE", func() {
1006+
entries := service.GenerateBillOfMaterials(
1007+
postal.Dependency{
1008+
CPE: "some-cpe",
1009+
ID: "some-entry",
1010+
Name: "Some Entry",
1011+
SHA256: "some-sha",
1012+
Source: "some-source",
1013+
Stacks: []string{"some-stack"},
1014+
URI: "some-uri",
1015+
Version: "1.2.3",
1016+
},
1017+
)
1018+
1019+
Expect(entries).To(Equal([]packit.BOMEntry{
1020+
{
1021+
Name: "Some Entry",
1022+
Metadata: map[string]interface{}{
1023+
"cpe": "some-cpe",
1024+
"sha256": "some-sha",
1025+
"stacks": []string{"some-stack"},
1026+
"uri": "some-uri",
1027+
"version": "1.2.3",
1028+
},
1029+
},
1030+
}))
1031+
})
1032+
})
1033+
1034+
context("when there is a deprecation date", func() {
1035+
var deprecationDate time.Time
1036+
1037+
it.Before(func() {
1038+
var err error
1039+
deprecationDate, err = time.Parse(time.RFC3339, "2022-04-01T00:00:00Z")
1040+
Expect(err).NotTo(HaveOccurred())
1041+
})
1042+
1043+
it("generates a BOM with the deprecation date", func() {
1044+
entries := service.GenerateBillOfMaterials(
1045+
postal.Dependency{
1046+
DeprecationDate: deprecationDate,
1047+
ID: "some-entry",
1048+
Name: "Some Entry",
1049+
SHA256: "some-sha",
1050+
Source: "some-source",
1051+
Stacks: []string{"some-stack"},
1052+
URI: "some-uri",
1053+
Version: "1.2.3",
1054+
},
1055+
)
1056+
1057+
Expect(entries).To(Equal([]packit.BOMEntry{
1058+
{
1059+
Name: "Some Entry",
1060+
Metadata: map[string]interface{}{
1061+
"deprecation-date": deprecationDate,
1062+
"sha256": "some-sha",
1063+
"stacks": []string{"some-stack"},
1064+
"uri": "some-uri",
1065+
"version": "1.2.3",
1066+
},
1067+
},
1068+
}))
1069+
})
1070+
})
1071+
1072+
context("when there is license information", func() {
1073+
it("generates a BOM with the license information", func() {
1074+
entries := service.GenerateBillOfMaterials(
1075+
postal.Dependency{
1076+
ID: "some-entry",
1077+
Licenses: []string{"some-license"},
1078+
Name: "Some Entry",
1079+
SHA256: "some-sha",
1080+
Source: "some-source",
1081+
Stacks: []string{"some-stack"},
1082+
URI: "some-uri",
1083+
Version: "1.2.3",
1084+
},
1085+
)
1086+
1087+
Expect(entries).To(Equal([]packit.BOMEntry{
1088+
{
1089+
Name: "Some Entry",
1090+
Metadata: map[string]interface{}{
1091+
"licenses": []string{"some-license"},
1092+
"sha256": "some-sha",
1093+
"stacks": []string{"some-stack"},
1094+
"uri": "some-uri",
1095+
"version": "1.2.3",
1096+
},
1097+
},
1098+
}))
1099+
})
1100+
})
1101+
1102+
context("when there is a pURL", func() {
1103+
it("generates a BOM with the pURL", func() {
1104+
entries := service.GenerateBillOfMaterials(
1105+
postal.Dependency{
1106+
ID: "some-entry",
1107+
Name: "Some Entry",
1108+
PURL: "some-purl",
1109+
SHA256: "some-sha",
1110+
Source: "some-source",
1111+
Stacks: []string{"some-stack"},
1112+
URI: "some-uri",
1113+
Version: "1.2.3",
1114+
},
1115+
)
1116+
1117+
Expect(entries).To(Equal([]packit.BOMEntry{
1118+
{
1119+
Name: "Some Entry",
1120+
Metadata: map[string]interface{}{
1121+
"purl": "some-purl",
1122+
"sha256": "some-sha",
1123+
"stacks": []string{"some-stack"},
1124+
"uri": "some-uri",
1125+
"version": "1.2.3",
1126+
},
1127+
},
1128+
}))
1129+
})
1130+
})
10121131
})
10131132
}

0 commit comments

Comments
 (0)