Skip to content

Commit d7e68f3

Browse files
committed
feat(spec1-5): add support for lifecycles
Signed-off-by: nscuro <nscuro@protonmail.com>
1 parent b038935 commit d7e68f3

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed

convert.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func (b *BOM) convert(specVersion SpecVersion) {
5858
b.Metadata.Properties = nil
5959
}
6060

61+
if specVersion < SpecVersion1_5 {
62+
b.Metadata.Lifecycles = nil
63+
}
64+
6165
recurseComponent(b.Metadata.Component, componentConverter(specVersion))
6266
convertLicenses(b.Metadata.Licenses, specVersion)
6367
if b.Metadata.Tools != nil {

cyclonedx.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,24 @@ type Licensing struct {
394394
Expiration string `json:"expiration,omitempty" xml:"expiration,omitempty"`
395395
}
396396

397+
type Lifecycle struct {
398+
Name string `json:"name,omitempty" xml:"name,omitempty"`
399+
Phase LifecyclePhase `json:"phase,omitempty" xml:"phase,omitempty"`
400+
Description string `json:"description,omitempty" xml:"description,omitempty"`
401+
}
402+
403+
type LifecyclePhase string
404+
405+
const (
406+
LifecyclePhaseBuild LifecyclePhase = "build"
407+
LifecyclePhaseDecommission LifecyclePhase = "decommission"
408+
LifecyclePhaseDesign LifecyclePhase = "design"
409+
LifecyclePhaseDiscovery LifecyclePhase = "discovery"
410+
LifecyclePhaseOperations LifecyclePhase = "operations"
411+
LifecyclePhasePostBuild LifecyclePhase = "post-build"
412+
LifecyclePhasePreBuild LifecyclePhase = "pre-build"
413+
)
414+
397415
// MediaType defines the official media types for CycloneDX BOMs.
398416
// See https://cyclonedx.org/specification/overview/#registered-media-types
399417
type MediaType int
@@ -414,6 +432,7 @@ func (mt MediaType) WithVersion(specVersion SpecVersion) (string, error) {
414432

415433
type Metadata struct {
416434
Timestamp string `json:"timestamp,omitempty" xml:"timestamp,omitempty"`
435+
Lifecycles *[]Lifecycle `json:"lifecycles,omitempty" xml:"lifecycles>lifecycle,omitempty"`
417436
Tools *[]Tool `json:"tools,omitempty" xml:"tools>tool,omitempty"`
418437
Authors *[]OrganizationalContact `json:"authors,omitempty" xml:"authors>author,omitempty"`
419438
Component *Component `json:"component,omitempty" xml:"component,omitempty"`
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"bomFormat": "CycloneDX",
3+
"specVersion": "1.5",
4+
"serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79",
5+
"version": 1,
6+
"metadata": {
7+
"lifecycles": [
8+
{
9+
"phase": "build"
10+
},
11+
{
12+
"phase": "post-build"
13+
},
14+
{
15+
"name": "platform-integration-testing",
16+
"description": "Integration testing specific to the runtime platform"
17+
}
18+
]
19+
},
20+
"components": []
21+
}
22+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.5" serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1">
3+
<metadata>
4+
<lifecycles>
5+
<lifecycle>
6+
<phase>build</phase>
7+
</lifecycle>
8+
<lifecycle>
9+
<phase>post-build</phase>
10+
</lifecycle>
11+
<lifecycle>
12+
<name>platform-integration-testing</name>
13+
<description>Integration testing specific to the runtime platform</description>
14+
</lifecycle>
15+
</lifecycles>
16+
</metadata>
17+
</bom>

testdata/valid-lifecycle.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"bomFormat": "CycloneDX",
3+
"specVersion": "1.5",
4+
"serialNumber": "urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79",
5+
"version": 1,
6+
"metadata": {
7+
"lifecycles": [
8+
{
9+
"phase": "build"
10+
},
11+
{
12+
"phase": "post-build"
13+
},
14+
{
15+
"name": "platform-integration-testing",
16+
"description": "Integration testing specific to the runtime platform"
17+
}
18+
]
19+
},
20+
"components": []
21+
}

testdata/valid-lifecycle.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<bom serialNumber="urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79" version="1" xmlns="http://cyclonedx.org/schema/bom/1.5">
3+
<metadata>
4+
<lifecycles>
5+
<lifecycle>
6+
<phase>build</phase>
7+
</lifecycle>
8+
<lifecycle>
9+
<phase>post-build</phase>
10+
</lifecycle>
11+
<lifecycle>
12+
<name>platform-integration-testing</name>
13+
<description>Integration testing specific to the runtime platform</description>
14+
</lifecycle>
15+
</lifecycles>
16+
</metadata>
17+
<components />
18+
</bom>

0 commit comments

Comments
 (0)