Skip to content

Commit e05048b

Browse files
authored
breaking: Simplify SBOM result class [TAROT-3624] (#103)
The aim of this simplification is to be independent of the SBOM format itself at this point. Downstream consumers decide if they want to unmarshal the SBOM (and how) based on it's format and spec version. No scala tools are producing SBOMs, so none need to actually change. No scala tool is even using a version of this library that includes SBOMs. However, golang tools can already produce SBOMs, so the [golang seed](https://github.com/codacy/codacy-engine-golang-seed/blob/master/result.go) needs to be updated. `codacy-trivy` will also need to be updated to match the new format. There will be a point when deploying new versions for worker and `codacy-trivy` when SBOM parsing will be broken but that is OK because: - SBOM parsing failures do not result in analysis failures - We only need SBOM parsing working during the night (SCA)
1 parent e4cff6d commit e05048b

File tree

1 file changed

+9
-94
lines changed
  • codacy-plugins-api/src/main/scala/com/codacy/plugins/api/results

1 file changed

+9
-94
lines changed

codacy-plugins-api/src/main/scala/com/codacy/plugins/api/results/Result.scala

Lines changed: 9 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package com.codacy.plugins.api.results
22

33
import com.codacy.plugins.api.{ErrorMessage, Source}
44

5-
import java.time.Instant
6-
75
sealed trait Result
86

97
object Result {
@@ -39,106 +37,23 @@ object Result {
3937
* A SBOM declares the inventory of components used to build a software artifact, including any open source and
4038
* proprietary software components.
4139
*
42-
* This class models CycloneDX 1.6 BOM format.
43-
*
44-
* @param bomFormat The format of the SBOM.
40+
* @param bomFormat The format of the SBOM. Currently only [[https://cyclonedx.org/ CycloneDX]] specification in JSON
41+
* format is supported.
4542
* @param specVersion The version of the SBOM format used to build this SBOM.
46-
* @param metadata SBOM metadata.
47-
* @param components A list of software components.
48-
* @param dependencies Document dependency relationships between components.
49-
* @see https://github.com/CycloneDX/cyclonedx-core-java/blob/master/src/main/resources/bom-1.6.schema.json
43+
* @param sbom The actual SBOM content. To be parsed by downstream consumers according to [[bomFormat]] and
44+
* [[specVersion]].
5045
*/
51-
case class SBOM(bomFormat: SBOM.BOMFormat.Value,
52-
specVersion: String,
53-
metadata: SBOM.Metadata,
54-
components: List[SBOM.Component],
55-
dependencies: List[SBOM.Dependency])
56-
extends Result
46+
case class SBOM(bomFormat: SBOM.BOMFormat.Value, specVersion: String, sbom: String) extends Result
5747

5848
object SBOM {
49+
50+
/** An enum representing the supported BOM formats. */
5951
type BOMFormat = BOMFormat.Value
6052
object BOMFormat extends Enumeration {
61-
val CycloneDX: Value = Value("CycloneDX")
62-
}
6353

64-
/** SBOM metadata.
65-
*
66-
* @param timestamp When the SBOM file was generated.
67-
* @param tools The tools used in the SBOM creation.
68-
* @param component The artifact that the SBOM describes.
69-
*/
70-
case class Metadata(timestamp: Instant, tools: Tools, component: Component)
71-
72-
case class Tools(components: List[Tool])
73-
74-
/** A tool used in SBOM generation. E.g. Trivy.
75-
*
76-
* @param `type` The tool type.
77-
* @param name The tool name.
78-
* @param group The tool group. E.g. com.codacy.
79-
* @param version The tool version.
80-
*/
81-
case class Tool(`type`: Component.Type, name: String, group: String, version: String)
82-
83-
/** A software or hardware component used to build a software artifact.
84-
*
85-
* @param `bom-ref` An identifier used to reference the component elsewhere in the SBOM. Unique within the SBOM.
86-
* @param `type` The type of component.
87-
* @param name The component name.
88-
* @param group The component group.
89-
* @param version The component version.
90-
* @param purl The package URL. See https://github.com/package-url/purl-spec
91-
* @param properties A list of component properties as name-value pairs.
92-
* @param licenses Component licenses.
93-
*/
94-
case class Component(`bom-ref`: String,
95-
`type`: Component.Type,
96-
name: String,
97-
group: Option[String],
98-
version: Option[String],
99-
purl: Option[String],
100-
properties: List[Property],
101-
licenses: Option[List[LicenseType]])
102-
103-
object Component {
104-
type Type = Type.Value
105-
object Type extends Enumeration {
106-
val Application: Value = Value("application")
107-
val Framework: Value = Value("framework")
108-
val Library: Value = Value("library")
109-
val Container: Value = Value("container")
110-
val Platform: Value = Value("platform")
111-
val OperatingSystem: Value = Value("operating-system")
112-
val Device: Value = Value("device")
113-
val DeviceDrive: Value = Value("device-driver")
114-
val Firmware: Value = Value("firmware")
115-
val File: Value = Value("file")
116-
val MachineLearningModel: Value = Value("machine-learning-model")
117-
val Data: Value = Value("data")
118-
val CryptographicAsset: Value = Value("cryptographic-asset")
119-
}
54+
/** [[https://cyclonedx.org/ CycloneDX]] specification in JSON format. */
55+
val CycloneDXJSON: Value = Value("CycloneDXJSON")
12056
}
121-
122-
/** A name-value pair representing a piece of information not officially supported by the SBOM schema. */
123-
case class Property(name: String, value: String)
124-
125-
/** Licenses can be either an expresion ([[LicenseExpression]]) or an identified license ([[LicenseWrapper]]). */
126-
sealed trait LicenseType
127-
case class LicenseWrapper(license: License) extends LicenseType
128-
case class LicenseExpression(expression: String, `bom-ref`: Option[String]) extends LicenseType
129-
130-
/** A software license.
131-
*
132-
* `id` and `name` cannot both be undefined.
133-
*/
134-
case class License(id: Option[String], name: Option[String])
135-
136-
/** Documents a dependency relationship between components.
137-
*
138-
* @param ref The reference to a component. Same as [[Component.`bom-ref`]].
139-
* @param dependsOn References to other components this component depends on.
140-
*/
141-
case class Dependency(ref: String, dependsOn: List[String])
14257
}
14358

14459
type Level = Level.Value

0 commit comments

Comments
 (0)