Documentation
¶
Overview ¶
Copyright (C) 2025 l3montree GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
Index ¶
- Constants
- Variables
- func ArtifactPurl(scanner string, assetName string) string
- func BeautifyPURL(pURL string) (string, error)
- func ConvertToSemver(originalVersion string) (string, error)
- func DeepSort(el any) any
- func FixFixedVersion(purl string, fixedVersion *string) *string
- func MapCDXToEventType(a *cdx.VulnerabilityAnalysis) string
- func MapCDXToVulnStatus(a *cdx.VulnerabilityAnalysis) string
- func PackageToPurl(ecosystem, packageName string) string
- func Purl(component cdx.Component) string
- func PurlToEcosystem(purlType string) string
- func Purlify(artifactName string, assetVersionName string) string
- func RemoveOriginTypePrefixIfExists(origin string) (nodeType, string)
- func SemverCompare(v1, v2 string) int
- func SemverSort(versions []string)
- func SortStringsSlice(slice []string) []string
- func StructuralCompareCdxBoms(a, b *cdx.BOM) error
- type CdxBom
- func FromCdxBom(bom *cdx.BOM, artifactName, ref string, informationSource string) *CdxBom
- func FromComponents(...) *CdxBom
- func FromNormalizedCdxBom(bom *cdx.BOM, ...) *CdxBom
- func FromVulnerabilities(...) *CdxBom
- func MergeCdxBoms(metadata *cdx.Metadata, artifactName string, boms ...*CdxBom) *CdxBom
- func (bom *CdxBom) AddChild(parent *TreeNode[cdxBomNode], child *TreeNode[cdxBomNode])
- func (bom *CdxBom) AddDirectChildWhichInheritsChildren(parent cdxBomNode, child cdxBomNode)
- func (bom *CdxBom) AddSourceChildrenToTarget(source *TreeNode[cdxBomNode], target *TreeNode[cdxBomNode])
- func (bom *CdxBom) CalculateDepth() map[string]int
- func (bom *CdxBom) CountParentTypes() map[string]map[nodeType]int
- func (bom *CdxBom) EjectMinimalDependencyTree() *minimalTreeNode
- func (bom *CdxBom) EjectSBOM(assetID *uuid.UUID) *cdx.BOM
- func (bom *CdxBom) EjectVex(assetID *uuid.UUID) *cdx.BOM
- func (bom *CdxBom) GetAllParentNodes(nodeID string) []string
- func (bom *CdxBom) GetComponents() *[]cdx.Component
- func (bom *CdxBom) GetComponentsIncludingFakeNodes() *[]cdx.Component
- func (bom *CdxBom) GetCsafRootPurls() []string
- func (bom *CdxBom) GetDependencies() *[]cdx.Dependency
- func (bom *CdxBom) GetDependenciesIncludingFakeNodes() *[]cdx.Dependency
- func (bom *CdxBom) GetDependenciesOfComponent(componentRef string) *cdx.Dependency
- func (bom *CdxBom) GetDirectDependencies() *[]cdx.Dependency
- func (bom *CdxBom) GetInformationSourceNodes() []*TreeNode[cdxBomNode]
- func (bom *CdxBom) GetInformationSources() []string
- func (bom *CdxBom) GetMetadata() *cdx.Metadata
- func (bom *CdxBom) GetTransitiveDependencies() *[]cdx.Dependency
- func (bom *CdxBom) GetVulnerabilities() *[]cdx.Vulnerability
- func (bom *CdxBom) InformationFromVexOrMultipleSBOMs() []string
- func (bom *CdxBom) ReplaceOrAddInformationSourceNode(subTree *TreeNode[cdxBomNode])
- func (bom *CdxBom) ReplaceRoot(newRoot cdxBomNode)
- type CdxComponent
- type Node
- type Tree
- func (tree *Tree[Element]) AddChild(parent *TreeNode[Element], child *TreeNode[Element])
- func (tree *Tree[Element]) AddDirectChildWhichInheritsChildren(parent Element, child Element)
- func (tree *Tree[Element]) AddSourceChildrenToTarget(source *TreeNode[Element], target *TreeNode[Element])
- func (tree *Tree[Data]) Reachable(id string) bool
- func (tree *Tree[Data]) RenderToMermaid() string
- func (tree *Tree[Element]) ReplaceNode(old *TreeNode[Element], new *TreeNode[Element])
- func (tree *Tree[Element]) ReplaceRoot(node Element)
- func (tree *Tree[Element]) ReplaceSubtree(other *TreeNode[Element])
- func (tree *Tree[Element]) Visitable() ([]string, []string)
- type TreeNode
Constants ¶
const ( NodeTypeComponent nodeType = "component" NodeTypeSbomInformationSource nodeType = "sbom" NodeTypeVexInformationSource nodeType = "vex" NodeTypeCSAFInformationSource nodeType = "csaf" NodeTypeUnknown nodeType = "unknown" )
Variables ¶
var PURLEcosystems = map[string]string{
"Alpine": "apk",
"crates.io": "cargo",
"Debian": "deb",
"Go": "golang",
"Hackage": "hackage",
"Hex": "hex",
"Maven": "maven",
"npm": "npm",
"NuGet": "nuget",
"OSS-Fuzz": "generic",
"Packagist": "composer",
"Pub": "pub",
"PyPI": "pypi",
"RubyGems": "gem",
}
var ValidSemverRegex = regexp.MustCompile(`^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
Regex for validating a correct semver.
Functions ¶
func ArtifactPurl ¶
func BeautifyPURL ¶
function to make purl look more visually appealing
func ConvertToSemver ¶
ConvertToSemver converts various version formats to semantic versioning format. It handles: - Epoch prefixes (e.g., "2:1.2.3" -> "1.2.3") - "v" prefixes (e.g., "v1.2.3" -> "1.2.3") - Pre-release identifiers with "-" (e.g., "1.2.3-rc1") - Build metadata with "+" (e.g., "1.2.3+build1") - Tilde versions "~" (e.g., "1.2.3~rc1" -> "1.2.3-rc1") - Missing version segments (e.g., "1.2" -> "1.2.0")
Returns an error if: - Version contains invalid characters (only 0-9 and . allowed in version part) - Version has more than 3 numeric segments
func DeepSort ¶
this is a deep sort function that sorts all maps and slices recursively it is REALLY expensive, so use it wisely! it treats any arrays as sets and sorts them by their canonical JSON representation
func FixFixedVersion ¶
func MapCDXToEventType ¶
func MapCDXToEventType(a *cdx.VulnerabilityAnalysis) string
func MapCDXToVulnStatus ¶
func MapCDXToVulnStatus(a *cdx.VulnerabilityAnalysis) string
map CycloneDX Analysis State / Response to internal status strings used by CreateVulnEventAndApply
func PackageToPurl ¶
func PurlToEcosystem ¶
func SemverCompare ¶
func SemverSort ¶
func SemverSort(versions []string)
func SortStringsSlice ¶
Types ¶
type CdxBom ¶
type CdxBom struct {
// contains filtered or unexported fields
}
func FromCdxBom ¶
func FromComponents ¶
func FromComponents(assetSlug, artifactName, assetVersionName, assetVersionSlug, projectSlug, orgSlug, frontendURL string, components []CdxComponent, licenseOverwrites map[string]string) *CdxBom
func FromNormalizedCdxBom ¶
func FromVulnerabilities ¶
func FromVulnerabilities(assetSlug, artifactName, assetVersionName, assetVersionSlug, projectSlug, orgSlug, frontendURL string, vulns []cdx.Vulnerability) *CdxBom
func MergeCdxBoms ¶
func (*CdxBom) AddDirectChildWhichInheritsChildren ¶
func (bom *CdxBom) AddDirectChildWhichInheritsChildren(parent cdxBomNode, child cdxBomNode)
func (*CdxBom) AddSourceChildrenToTarget ¶
func (*CdxBom) CalculateDepth ¶
func (*CdxBom) CountParentTypes ¶
func (*CdxBom) EjectMinimalDependencyTree ¶
func (bom *CdxBom) EjectMinimalDependencyTree() *minimalTreeNode
func (*CdxBom) GetAllParentNodes ¶
func (*CdxBom) GetComponents ¶
func (*CdxBom) GetComponentsIncludingFakeNodes ¶
func (*CdxBom) GetCsafRootPurls ¶
this returns direct csaf children of csaf information source nodes since csaf does not scope transitive dependencies but we might be able to redistribute found cves to the subtree reachable from those purls.
func (*CdxBom) GetDependencies ¶
func (bom *CdxBom) GetDependencies() *[]cdx.Dependency
func (*CdxBom) GetDependenciesIncludingFakeNodes ¶
func (bom *CdxBom) GetDependenciesIncludingFakeNodes() *[]cdx.Dependency
func (*CdxBom) GetDependenciesOfComponent ¶
func (bom *CdxBom) GetDependenciesOfComponent(componentRef string) *cdx.Dependency
func (*CdxBom) GetDirectDependencies ¶
func (bom *CdxBom) GetDirectDependencies() *[]cdx.Dependency
func (*CdxBom) GetInformationSourceNodes ¶
func (*CdxBom) GetInformationSources ¶
func (*CdxBom) GetMetadata ¶
func (*CdxBom) GetTransitiveDependencies ¶
func (bom *CdxBom) GetTransitiveDependencies() *[]cdx.Dependency
func (*CdxBom) GetVulnerabilities ¶
func (bom *CdxBom) GetVulnerabilities() *[]cdx.Vulnerability
func (*CdxBom) InformationFromVexOrMultipleSBOMs ¶
func (*CdxBom) ReplaceOrAddInformationSourceNode ¶
func (*CdxBom) ReplaceRoot ¶
func (bom *CdxBom) ReplaceRoot(newRoot cdxBomNode)
type CdxComponent ¶
type Tree ¶
type Tree[Element Node] struct { Root *TreeNode[Element] `json:"root"` // contains filtered or unexported fields }
func BuildDependencyTree ¶
func (*Tree[Element]) AddDirectChildWhichInheritsChildren ¶
func (tree *Tree[Element]) AddDirectChildWhichInheritsChildren(parent Element, child Element)
func (*Tree[Element]) AddSourceChildrenToTarget ¶
func (*Tree[Data]) RenderToMermaid ¶
func (*Tree[Element]) ReplaceNode ¶
func (*Tree[Element]) ReplaceRoot ¶
func (tree *Tree[Element]) ReplaceRoot(node Element)