Documentation
¶
Overview ¶
Package component provides the component domain model for software dependencies.
Index ¶
- Constants
- Variables
- func AlreadyExistsError(purl string) error
- func BuildPURL(ecosystem Ecosystem, namespace, name, version string) string
- func NotFoundByPURLError(purl string) error
- func NotFoundError(id shared.ID) error
- type AssetDependency
- func (ad *AssetDependency) AssetID() shared.ID
- func (ad *AssetDependency) Component() *Component
- func (ad *AssetDependency) ComponentID() shared.ID
- func (ad *AssetDependency) CreatedAt() time.Time
- func (ad *AssetDependency) DependencyType() DependencyType
- func (ad *AssetDependency) Depth() int
- func (ad *AssetDependency) ID() shared.ID
- func (ad *AssetDependency) ManifestFile() string
- func (ad *AssetDependency) ParentComponentID() *shared.ID
- func (ad *AssetDependency) Path() string
- func (ad *AssetDependency) SetComponent(c *Component)
- func (ad *AssetDependency) SetDependencyType(t DependencyType)
- func (ad *AssetDependency) SetDepth(depth int)
- func (ad *AssetDependency) SetManifestFile(f string)
- func (ad *AssetDependency) SetParentComponentID(parentID *shared.ID) error
- func (ad *AssetDependency) SetPath(p string)
- func (ad *AssetDependency) TenantID() shared.ID
- func (ad *AssetDependency) UpdatedAt() time.Time
- type Component
- func (c *Component) CreatedAt() time.Time
- func (c *Component) Description() string
- func (c *Component) Ecosystem() Ecosystem
- func (c *Component) Homepage() string
- func (c *Component) ID() shared.ID
- func (c *Component) License() string
- func (c *Component) Metadata() map[string]any
- func (c *Component) Name() string
- func (c *Component) PURL() string
- func (c *Component) SetMetadata(key string, value any) error
- func (c *Component) SetPURL(purl string)
- func (c *Component) UpdateDescription(desc string)
- func (c *Component) UpdateHomepage(url string)
- func (c *Component) UpdateLicense(license string)
- func (c *Component) UpdatedAt() time.Time
- func (c *Component) Version() string
- func (c *Component) VulnerabilityCount() int
- type ComponentStats
- type DependencyType
- type Ecosystem
- type EcosystemStats
- type Filter
- func (f Filter) WithAssetID(id shared.ID) Filter
- func (f Filter) WithDependencyTypes(types ...DependencyType) Filter
- func (f Filter) WithEcosystems(ecosystems ...Ecosystem) Filter
- func (f Filter) WithHasVulnerabilities(has bool) Filter
- func (f Filter) WithLicenses(licenses ...string) Filter
- func (f Filter) WithName(name string) Filter
- func (f Filter) WithStatuses(statuses ...Status) Filter
- func (f Filter) WithTenantID(id shared.ID) Filter
- type LicenseStats
- type Repository
- type Status
- type VulnerableComponent
Constants ¶
const ( // MaxMetadataSize is the maximum allowed size for component metadata (64KB) MaxMetadataSize = 64 * 1024 // MaxMetadataKeys is the maximum number of keys in metadata MaxMetadataKeys = 100 )
Security limits
Variables ¶
var ( ErrComponentNotFound = fmt.Errorf("component %w", shared.ErrNotFound) ErrComponentAlreadyExists = fmt.Errorf("component %w", shared.ErrAlreadyExists) ErrDependencyNotFound = fmt.Errorf("dependency %w", shared.ErrNotFound) )
Domain errors for component.
Functions ¶
func AlreadyExistsError ¶
AlreadyExistsError returns an already exists error with the component PURL.
func BuildPURL ¶
BuildPURL builds a Package URL (PURL) for a component. Format: pkg:ecosystem/namespace/name@version
func NotFoundByPURLError ¶
NotFoundByPURLError returns a not found error with the component PURL.
func NotFoundError ¶
NotFoundError returns a not found error with the component ID.
Types ¶
type AssetDependency ¶
type AssetDependency struct {
// contains filtered or unexported fields
}
AssetDependency represents a component usage by an asset.
func NewAssetDependency ¶
func NewAssetDependency( tenantID, assetID, componentID shared.ID, path string, depType DependencyType, ) (*AssetDependency, error)
NewAssetDependency creates a link between asset and component. Default depth is 1 (direct dependency). Use SetDepth() for transitive deps.
func ReconstituteAssetDependency ¶
func ReconstituteAssetDependency( id, tenantID, assetID, componentID shared.ID, path string, depType DependencyType, manifestFile string, parentComponentID *shared.ID, depth int, createdAt, updatedAt time.Time, ) *AssetDependency
ReconstituteAssetDependency recreates a dependency link.
func (*AssetDependency) AssetID ¶
func (ad *AssetDependency) AssetID() shared.ID
func (*AssetDependency) Component ¶
func (ad *AssetDependency) Component() *Component
func (*AssetDependency) ComponentID ¶
func (ad *AssetDependency) ComponentID() shared.ID
func (*AssetDependency) CreatedAt ¶
func (ad *AssetDependency) CreatedAt() time.Time
func (*AssetDependency) DependencyType ¶
func (ad *AssetDependency) DependencyType() DependencyType
func (*AssetDependency) Depth ¶
func (ad *AssetDependency) Depth() int
func (*AssetDependency) ID ¶
func (ad *AssetDependency) ID() shared.ID
func (*AssetDependency) ManifestFile ¶
func (ad *AssetDependency) ManifestFile() string
func (*AssetDependency) ParentComponentID ¶
func (ad *AssetDependency) ParentComponentID() *shared.ID
func (*AssetDependency) Path ¶
func (ad *AssetDependency) Path() string
func (*AssetDependency) SetComponent ¶
func (ad *AssetDependency) SetComponent(c *Component)
func (*AssetDependency) SetDependencyType ¶ added in v0.1.2
func (ad *AssetDependency) SetDependencyType(t DependencyType)
SetDependencyType updates the dependency type.
func (*AssetDependency) SetDepth ¶
func (ad *AssetDependency) SetDepth(depth int)
SetDepth sets the dependency depth for risk scoring.
func (*AssetDependency) SetManifestFile ¶ added in v0.1.2
func (ad *AssetDependency) SetManifestFile(f string)
SetManifestFile updates the manifest file.
func (*AssetDependency) SetParentComponentID ¶
func (ad *AssetDependency) SetParentComponentID(parentID *shared.ID) error
SetParentComponentID sets the parent dependency ID for transitive deps. Returns error if attempting to create a circular dependency (self-reference).
func (*AssetDependency) SetPath ¶ added in v0.1.2
func (ad *AssetDependency) SetPath(p string)
SetPath updates the dependency path.
func (*AssetDependency) TenantID ¶
func (ad *AssetDependency) TenantID() shared.ID
func (*AssetDependency) UpdatedAt ¶
func (ad *AssetDependency) UpdatedAt() time.Time
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
Component represents a unique software package (Global).
func NewComponent ¶
NewComponent creates a new Global Component.
func Reconstitute ¶
func Reconstitute( id shared.ID, name string, version string, ecosystem Ecosystem, purl string, license string, description string, homepage string, vulnerabilityCount int, metadata map[string]any, createdAt time.Time, updatedAt time.Time, ) *Component
Reconstitute recreates a Component from persistence.
func (*Component) Description ¶
Description returns the description.
func (*Component) SetMetadata ¶
SetMetadata sets a metadata key-value pair with size validation. Returns error if metadata exceeds size limits (DoS prevention).
func (*Component) SetPURL ¶
SetPURL overrides the generated PURL with a custom one. Use this when the agent provides a more accurate PURL.
func (*Component) UpdateDescription ¶
func (*Component) UpdateHomepage ¶
func (*Component) UpdateLicense ¶
func (*Component) VulnerabilityCount ¶
VulnerabilityCount returns the vulnerability count.
type ComponentStats ¶
type ComponentStats struct {
TotalComponents int `json:"total_components"`
DirectDependencies int `json:"direct_dependencies"`
TransitiveDependencies int `json:"transitive_dependencies"`
VulnerableComponents int `json:"vulnerable_components"`
// Extended stats from findings analysis
TotalVulnerabilities int `json:"total_vulnerabilities"`
OutdatedComponents int `json:"outdated_components"`
CisaKevComponents int `json:"cisa_kev_components"`
VulnBySeverity map[string]int `json:"vuln_by_severity"` // critical, high, medium, low
LicenseRisks map[string]int `json:"license_risks"` // critical, high, medium, low
}
ComponentStats aggregates counts for dashboard.
type DependencyType ¶
type DependencyType string
DependencyType represents whether a dependency is direct or transitive.
const ( DependencyTypeDirect DependencyType = "direct" DependencyTypeTransitive DependencyType = "transitive" DependencyTypeDev DependencyType = "dev" DependencyTypeOptional DependencyType = "optional" )
func ParseDependencyType ¶
func ParseDependencyType(s string) (DependencyType, error)
ParseDependencyType parses a string into a DependencyType. Handles mapping from various scanner formats (e.g., Trivy uses "indirect", "transit").
func (DependencyType) IsValid ¶
func (d DependencyType) IsValid() bool
IsValid checks if the dependency type is valid.
func (DependencyType) String ¶
func (d DependencyType) String() string
String returns the string representation.
type Ecosystem ¶
type Ecosystem string
Ecosystem represents the package ecosystem.
const ( EcosystemNPM Ecosystem = "npm" EcosystemMaven Ecosystem = "maven" EcosystemPyPI Ecosystem = "pypi" EcosystemGo Ecosystem = "go" EcosystemCargo Ecosystem = "cargo" EcosystemNuGet Ecosystem = "nuget" EcosystemRubyGems Ecosystem = "rubygems" EcosystemComposer Ecosystem = "composer" EcosystemHex Ecosystem = "hex" EcosystemCocoaPods Ecosystem = "cocoapods" EcosystemSwiftPM Ecosystem = "swiftpm" EcosystemPub Ecosystem = "pub" EcosystemCran Ecosystem = "cran" EcosystemOther Ecosystem = "other" )
func ParseEcosystem ¶
ParseEcosystem parses a string into an Ecosystem.
func (Ecosystem) ManifestFile ¶
ManifestFile returns the typical manifest file for this ecosystem.
type EcosystemStats ¶
type EcosystemStats struct {
Ecosystem string `json:"ecosystem"`
Total int `json:"total"`
Vulnerable int `json:"vulnerable"`
Outdated int `json:"outdated"`
ManifestFile string `json:"manifest_file"`
}
EcosystemStats represents statistics for a single ecosystem.
type Filter ¶
type Filter struct {
TenantID *shared.ID // Filter components used by tenant
AssetID *shared.ID // Filter components used by asset
Name *string
PURL *string
Ecosystems []Ecosystem
DependencyTypes []DependencyType
Statuses []Status
Licenses []string
HasVulnerabilities *bool
}
Filter defines criteria for filtering components.
func (Filter) WithDependencyTypes ¶
func (f Filter) WithDependencyTypes(types ...DependencyType) Filter
func (Filter) WithEcosystems ¶
func (Filter) WithHasVulnerabilities ¶
func (Filter) WithLicenses ¶
func (Filter) WithStatuses ¶
type LicenseStats ¶
type LicenseStats struct {
LicenseID string `json:"license_id"` // SPDX identifier
Name string `json:"name"` // Human-readable name
Category string `json:"category"` // permissive, copyleft, weak-copyleft, proprietary, public-domain, unknown
Risk string `json:"risk"` // critical, high, medium, low, none, unknown
URL *string `json:"url,omitempty"` // Link to license text (SPDX URL)
Count int `json:"count"` // Number of components using this license
}
LicenseStats represents statistics for a single license.
type Repository ¶
type Repository interface {
// Global Component Operations
Upsert(ctx context.Context, comp *Component) (shared.ID, error)
GetByPURL(ctx context.Context, purl string) (*Component, error)
GetByID(ctx context.Context, id shared.ID) (*Component, error)
// License Operations
// LinkLicenses links licenses to a component and returns the count of newly linked licenses.
LinkLicenses(ctx context.Context, componentID shared.ID, licenses []string) (linked int, err error)
// Asset Dependency Operations (Links)
LinkAsset(ctx context.Context, dep *AssetDependency) error
GetDependency(ctx context.Context, id shared.ID) (*AssetDependency, error)
UpdateDependency(ctx context.Context, dep *AssetDependency) error
DeleteDependency(ctx context.Context, id shared.ID) error
DeleteByAssetID(ctx context.Context, assetID shared.ID) error
// GetExistingDependencyByPURL retrieves an existing asset_component by asset and component PURL.
// Used for parent lookup during rescan when parent component exists from previous scan.
// Returns nil, nil if not found.
GetExistingDependencyByPURL(ctx context.Context, assetID shared.ID, purl string) (*AssetDependency, error)
// GetExistingDependencyByComponentID retrieves an existing asset_component by asset, component, and path.
// Used for duplicate detection during ingestion.
// Returns nil, nil if not found.
GetExistingDependencyByComponentID(ctx context.Context, assetID shared.ID, componentID shared.ID, path string) (*AssetDependency, error)
// UpdateAssetDependencyParent updates the parent_component_id and depth of an asset_component.
// Used in three-pass ingestion to set parent references after all components are inserted.
UpdateAssetDependencyParent(ctx context.Context, id shared.ID, parentID shared.ID, depth int) error
// ListComponents retrieves global components (optionally filtered by usage).
ListComponents(ctx context.Context, filter Filter, page pagination.Pagination) (pagination.Result[*Component], error)
// ListDependencies retrieves dependencies for an asset (joined with component details).
ListDependencies(ctx context.Context, assetID shared.ID, page pagination.Pagination) (pagination.Result[*AssetDependency], error)
// GetStats retrieves aggregated component statistics.
GetStats(ctx context.Context, tenantID shared.ID) (*ComponentStats, error)
// GetEcosystemStats retrieves per-ecosystem statistics.
GetEcosystemStats(ctx context.Context, tenantID shared.ID) ([]EcosystemStats, error)
// GetVulnerableComponents retrieves components with vulnerability details.
GetVulnerableComponents(ctx context.Context, tenantID shared.ID, limit int) ([]VulnerableComponent, error)
// GetLicenseStats retrieves license statistics for a tenant.
GetLicenseStats(ctx context.Context, tenantID shared.ID) ([]LicenseStats, error)
}
Repository defines the interface for component persistence.
type Status ¶
type Status string
Status represents the component status.
func ParseStatus ¶
ParseStatus parses a string into a Status.
type VulnerableComponent ¶
type VulnerableComponent struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Ecosystem string `json:"ecosystem"`
PURL string `json:"purl"`
License string `json:"license,omitempty"`
// Vulnerability breakdown
CriticalCount int `json:"critical_count"`
HighCount int `json:"high_count"`
MediumCount int `json:"medium_count"`
LowCount int `json:"low_count"`
TotalCount int `json:"total_count"`
InCisaKev bool `json:"in_cisa_kev"`
}
VulnerableComponent represents a component with vulnerability details for display.