mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
- Resolves #2974 - add detailed instructions re: updating schemas (a necessary task when a new CycloneDX spec version becomes available). - The DefaultVersion constant has been updated to "1.6" -- it's not clear to me how this is used at this time (it may be redundant given other code), but effectively unless a specific spec version is configured, `syft` will emit the "most recent" spec version available for cyclonedx. Users who wish to pin back to a "older" specVersion (e.g. to preserve compatibilty with utilities that have not yet bumped to latest) can either set this in a syft config file or pass a name@spec_version pair to the output flag (e.g. `-o cyclonedx-json@1.5=some-1.5-spec-bom.cdx.json`) - Regenerate relevant .golden files (there seems to be a way to do this via flags, but I couldn't quite figure out the right set to pass correctly, esp. since (as a relative go novice) I found it difficult to run just a single test file. I ended up "brute-forcing it" by changing the *updateSnapshot val to "true" and running it in Goland. A brief comment giving an example of regenerating fixtures usage would be helpful. Signed-off-by: Rajan Agaskar <ragaskar@gmail.com>
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package cyclonedxutil
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/CycloneDX/cyclonedx-go"
|
|
|
|
"github.com/anchore/syft/syft/sbom"
|
|
)
|
|
|
|
const (
|
|
XMLFormatID sbom.FormatID = "cyclonedx-xml"
|
|
JSONFormatID sbom.FormatID = "cyclonedx-json"
|
|
)
|
|
|
|
func SupportedVersions(id sbom.FormatID) []string {
|
|
versions := []string{
|
|
"1.2",
|
|
"1.3",
|
|
"1.4",
|
|
"1.5",
|
|
"1.6",
|
|
}
|
|
|
|
if id != JSONFormatID {
|
|
// JSON format not supported for version < 1.2
|
|
versions = append([]string{"1.0", "1.1"}, versions...)
|
|
}
|
|
|
|
return versions
|
|
}
|
|
|
|
func SpecVersionFromString(v string) (cyclonedx.SpecVersion, error) {
|
|
switch v {
|
|
case "1.0":
|
|
return cyclonedx.SpecVersion1_0, nil
|
|
case "1.1":
|
|
return cyclonedx.SpecVersion1_1, nil
|
|
case "1.2":
|
|
return cyclonedx.SpecVersion1_2, nil
|
|
case "1.3":
|
|
return cyclonedx.SpecVersion1_3, nil
|
|
case "1.4":
|
|
return cyclonedx.SpecVersion1_4, nil
|
|
case "1.5":
|
|
return cyclonedx.SpecVersion1_5, nil
|
|
case "1.6":
|
|
return cyclonedx.SpecVersion1_6, nil
|
|
}
|
|
return -1, fmt.Errorf("unsupported CycloneDX version %q", v)
|
|
}
|
|
|
|
func VersionFromSpecVersion(spec cyclonedx.SpecVersion) string {
|
|
switch spec {
|
|
case cyclonedx.SpecVersion1_0:
|
|
return "1.0"
|
|
case cyclonedx.SpecVersion1_1:
|
|
return "1.1"
|
|
case cyclonedx.SpecVersion1_2:
|
|
return "1.2"
|
|
case cyclonedx.SpecVersion1_3:
|
|
return "1.3"
|
|
case cyclonedx.SpecVersion1_4:
|
|
return "1.4"
|
|
case cyclonedx.SpecVersion1_5:
|
|
return "1.5"
|
|
case cyclonedx.SpecVersion1_6:
|
|
return "1.6"
|
|
}
|
|
return ""
|
|
}
|