Skip to content

Commit

Permalink
fix: add bom-ref to OrganizationalEntity/Contact
Browse files Browse the repository at this point in the history
Adds bom-ref to OrganizationalEntity and OrganizationalContact which was
added in CycloneDX 1.5

Signed-off-by: Tim Pickles <tim.pickles@snyk.io>
  • Loading branch information
snyk-tim committed May 29, 2024
1 parent 1586f07 commit 349fc8c
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 9 deletions.
32 changes: 32 additions & 0 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func (b *BOM) convert(specVersion SpecVersion) {
convertTools(b.Metadata.Tools, specVersion)
convertOrganizationalEntity(b.Metadata.Manufacture, specVersion)
convertOrganizationalEntity(b.Metadata.Supplier, specVersion)

if b.Metadata.Authors != nil {
for i := range *b.Metadata.Authors {
convertOrganizationalContact(&(*b.Metadata.Authors)[i], specVersion)
}
}
}

if b.Components != nil {
Expand Down Expand Up @@ -324,11 +330,31 @@ func convertOrganizationalEntity(org *OrganizationalEntity, specVersion SpecVers
return
}

if specVersion < SpecVersion1_5 {
org.BOMRef = ""

if org.Contact != nil {
for i := range *org.Contact {
convertOrganizationalContact(&(*org.Contact)[i], specVersion)
}
}
}

if specVersion < SpecVersion1_6 {
org.Address = nil
}
}

func convertOrganizationalContact(c *OrganizationalContact, specVersion SpecVersion) {
if c == nil {
return
}

if specVersion < SpecVersion1_5 {
c.BOMRef = ""
}
}

func convertModelCard(c *Component, specVersion SpecVersion) {
if c.ModelCard == nil {
return
Expand Down Expand Up @@ -364,6 +390,12 @@ func convertVulnerabilities(vulns *[]Vulnerability, specVersion SpecVersion) {
convertOrganizationalEntity(&(*vuln.Credits.Organizations)[i], specVersion)
}
}

if vuln.Credits.Individuals != nil {
for i := range *vuln.Credits.Individuals {
convertOrganizationalContact(&(*vuln.Credits.Individuals)[i], specVersion)
}
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions cyclonedx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,12 +1124,14 @@ type Note struct {
}

type OrganizationalContact struct {
Name string `json:"name,omitempty" xml:"name,omitempty"`
Email string `json:"email,omitempty" xml:"email,omitempty"`
Phone string `json:"phone,omitempty" xml:"phone,omitempty"`
BOMRef string `json:"bom-ref,omitempty" xml:"bom-ref,attr,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
Email string `json:"email,omitempty" xml:"email,omitempty"`
Phone string `json:"phone,omitempty" xml:"phone,omitempty"`
}

type OrganizationalEntity struct {
BOMRef string `json:"bom-ref,omitempty" xml:"bom-ref,attr,omitempty"`
Name string `json:"name" xml:"name"`
Address *PostalAddress `json:"address,omitempty" xml:"address,omitempty"`
URL *[]string `json:"url,omitempty" xml:"url,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"metadata": {
"authors": [
{
"bom-ref": "author-1",
"name": "Samantha Wright",
"email": "samantha.wright@example.com",
"phone": "800-555-1212"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"version": 1,
"metadata": {
"manufacture": {
"bom-ref": "manufacture-1",
"name": "Acme, Inc.",
"url": [
"https://example.com"
],
"contact": [
{
"bom-ref": "contact-1",
"name": "Acme Professional Services",
"email": "professional.services@example.com"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<bom xmlns="http://cyclonedx.org/schema/bom/1.6" serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1">
<metadata>
<authors>
<author>
<author bom-ref="contact-1">
<name>Samantha Wright</name>
<email>samantha.wright@example.com</email>
<phone>800-555-1212</phone>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.6" serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1">
<metadata>
<manufacture>
<manufacture bom-ref="manufacture-1">
<name>Acme, Inc.</name>
<url>https://example.com</url>
<contact>
<contact bom-ref="contact-1">
<name>Acme Professional Services</name>
<email>professional.services@example.com</email>
</contact>
Expand Down
1 change: 1 addition & 0 deletions testdata/valid-metadata-author.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"metadata": {
"authors": [
{
"bom-ref": "author-1",
"name": "Samantha Wright",
"email": "samantha.wright@example.com",
"phone": "800-555-1212"
Expand Down
2 changes: 1 addition & 1 deletion testdata/valid-metadata-author.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<bom serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1" xmlns="http://cyclonedx.org/schema/bom/1.6">
<metadata>
<authors>
<author>
<author bom-ref="contact-1">
<name>Samantha Wright</name>
<email>samantha.wright@example.com</email>
<phone>800-555-1212</phone>
Expand Down
2 changes: 2 additions & 0 deletions testdata/valid-metadata-manufacture.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"version": 1,
"metadata": {
"manufacture": {
"bom-ref": "manufacture-1",
"name": "Acme, Inc.",
"url": [
"https://example.com"
],
"contact": [
{
"bom-ref": "contact-1",
"name": "Acme Professional Services",
"email": "professional.services@example.com"
}
Expand Down
4 changes: 2 additions & 2 deletions testdata/valid-metadata-manufacture.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0"?>
<bom serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1" xmlns="http://cyclonedx.org/schema/bom/1.6">
<metadata>
<manufacture>
<manufacture bom-ref="manufacture-1">
<name>Acme, Inc.</name>
<url>https://example.com</url>
<contact>
<contact bom-ref="contact-1">
<name>Acme Professional Services</name>
<email>professional.services@example.com</email>
</contact>
Expand Down

0 comments on commit 349fc8c

Please sign in to comment.