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

feat(1.6): add License.Acknowledgement #167

Merged
merged 1 commit into from
May 17, 2024
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
17 changes: 14 additions & 3 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,18 @@ func convertEvidence(c *Component, specVersion SpecVersion) {
return
}

for i := range *c.Evidence.Occurrences {
occ := &(*c.Evidence.Occurrences)[i]
if specVersion < SpecVersion1_6 {
for i := range *c.Evidence.Occurrences {
occ := &(*c.Evidence.Occurrences)[i]

if specVersion < SpecVersion1_6 {
occ.Line = nil
occ.Offset = nil
occ.Symbol = ""
occ.AdditionalContext = ""
}
}

convertLicenses(c.Evidence.Licenses, specVersion)
}

func convertCompositions(comps *[]Composition, specVersion SpecVersion) {
Expand Down Expand Up @@ -286,6 +288,15 @@ func convertLicenses(licenses *Licenses, specVersion SpecVersion) {
}
}
}

if specVersion < SpecVersion1_6 {
for i := range *licenses {
choice := &(*licenses)[i]
if choice.License != nil {
choice.License.Acknowledgement = ""
}
}
}
}

func convertVulnerabilities(vulns *[]Vulnerability, specVersion SpecVersion) {
Expand Down
24 changes: 24 additions & 0 deletions convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,27 @@ func Test_componentConverter_convertEvidence(t *testing.T) {
assert.Zero(t, occ.AdditionalContext)
})
}

func Test_convertLicenses(t *testing.T) {
t.Run("spec 1.5 and lower", func(t *testing.T) {
bom := NewBOM()
bom.Metadata = &Metadata{
Licenses: &Licenses{
{License: &License{Name: "Apache License 2.0", Acknowledgement: LicenseAcknowledgementDeclared}},
},
}
bom.Components = &[]Component{
{
Name: "foo",
Licenses: &Licenses{
{License: &License{Name: "Apache License 2.0", Acknowledgement: LicenseAcknowledgementConcluded}},
},
},
}

bom.convert(SpecVersion1_5)

assert.Zero(t, (*bom.Metadata.Licenses)[0].License.Acknowledgement)
assert.Zero(t, (*(*bom.Components)[0].Licenses)[0].License.Acknowledgement)
})
}
24 changes: 16 additions & 8 deletions cyclonedx.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type BOM struct {
Vulnerabilities *[]Vulnerability `json:"vulnerabilities,omitempty" xml:"vulnerabilities>vulnerability,omitempty"`
Annotations *[]Annotation `json:"annotations,omitempty" xml:"annotations>annotation,omitempty"`
Formulation *[]Formula `json:"formulation,omitempty" xml:"formulation>formula,omitempty"`
Definitions *Definitions `json:"definitions" xml:"definitions,omitempty"`
Definitions *Definitions `json:"definitions,omitempty" xml:"definitions,omitempty"`
Copy link
Contributor Author

@mcombuechen mcombuechen May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated fix for something that I missed in #161 .

}

func NewBOM() *BOM {
Expand Down Expand Up @@ -539,15 +539,23 @@ type JSFPublicKey struct {
}

type License struct {
BOMRef string `json:"bom-ref,omitempty" xml:"bom-ref,attr,omitempty"`
ID string `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
Text *AttachedText `json:"text,omitempty" xml:"text,omitempty"`
URL string `json:"url,omitempty" xml:"url,omitempty"`
Licensing *Licensing `json:"licensing,omitempty" xml:"licensing,omitempty"`
Properties *[]Property `json:"properties,omitempty" xml:"properties>property,omitempty"`
BOMRef string `json:"bom-ref,omitempty" xml:"bom-ref,attr,omitempty"`
ID string `json:"id,omitempty" xml:"id,omitempty"`
Name string `json:"name,omitempty" xml:"name,omitempty"`
Acknowledgement LicenseAcknowledgement `json:"acknowledgement,omitempty" xml:"acknowledgement,attr,omitempty"`
Text *AttachedText `json:"text,omitempty" xml:"text,omitempty"`
URL string `json:"url,omitempty" xml:"url,omitempty"`
Licensing *Licensing `json:"licensing,omitempty" xml:"licensing,omitempty"`
Properties *[]Property `json:"properties,omitempty" xml:"properties>property,omitempty"`
}

type LicenseAcknowledgement string

const (
LicenseAcknowledgementDeclared LicenseAcknowledgement = "declared"
LicenseAcknowledgementConcluded LicenseAcknowledgement = "concluded"
)

type Licenses []LicenseChoice

type LicenseChoice struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"license": {
"bom-ref": "acme-license-1",
"name": "Acme Commercial License",
"acknowledgement": "concluded",
"licensing": {
"altIds": [
"acme",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"licenses": [
{
"license": {
"name": "Apache License 2.0"
"name": "Apache License 2.0",
"acknowledgement": "concluded"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<name>cryptographic-provider</name>
<version>2.2.0</version>
<licenses>
<license bom-ref="acme-license-1">
<license bom-ref="acme-license-1" acknowledgement="concluded">
<name>Acme Commercial License</name>
<licensing>
<altIds>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<hash alg="SHA-512">e8f33e424f3f4ed6db76a482fde1a5298970e442c531729119e37991884bdffab4f9426b7ee11fccd074eeda0634d71697d6f88a460dce0ac8d627a29f7d1282</hash>
</hashes>
<licenses>
<license>
<license acknowledgement="concluded">
<name>Apache License 2.0</name>
</license>
</licenses>
Expand Down
1 change: 1 addition & 0 deletions testdata/valid-license-licensing.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"license": {
"bom-ref": "acme-license-1",
"name": "Acme Commercial License",
"acknowledgement": "concluded",
"licensing": {
"altIds": [
"acme", "acme-license"
Expand Down
2 changes: 1 addition & 1 deletion testdata/valid-license-licensing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<name>cryptographic-provider</name>
<version>2.2.0</version>
<licenses>
<license bom-ref="acme-license-1">
<license bom-ref="acme-license-1" acknowledgement="concluded">
<name>Acme Commercial License</name>
<licensing>
<altIds>
Expand Down
3 changes: 2 additions & 1 deletion testdata/valid-license-name.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"licenses": [
{
"license": {
"name": "Apache License 2.0"
"name": "Apache License 2.0",
"acknowledgement": "concluded"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion testdata/valid-license-name.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<hash alg="SHA-512">e8f33e424f3f4ed6db76a482fde1a5298970e442c531729119e37991884bdffab4f9426b7ee11fccd074eeda0634d71697d6f88a460dce0ac8d627a29f7d1282</hash>
</hashes>
<licenses>
<license>
<license acknowledgement="concluded">
<name>Apache License 2.0</name>
</license>
</licenses>
Expand Down