Documentation
¶
Overview ¶
Package usecases contains all business logic for ScanVault. Use cases orchestrate boundary interfaces and enforce domain rules — they must not import anything from the presentation or persistence layers.
Index ¶
- type Cleaner
- type CleanupConfig
- type ScanUseCases
- func (s *ScanUseCases) CreateScan(ctx context.Context, imageName, imageTag, imageDigest string, ...) (*entities.Scan, bool, error)
- func (s *ScanUseCases) GetCVEAffectedImages(ctx context.Context, cveID string) ([]entities.AffectedImage, error)
- func (s *ScanUseCases) GetFixableSummary(ctx context.Context, imageName string, from, to *time.Time) (*entities.FixableSummary, error)
- func (s *ScanUseCases) GetLatestScan(ctx context.Context, imageName string) (*entities.Scan, error)
- func (s *ScanUseCases) GetScanByID(ctx context.Context, id string) (*entities.Scan, error)
- func (s *ScanUseCases) GetTopCVEs(ctx context.Context, imageName, severity string, limit int, ...) ([]entities.TopCVE, error)
- func (s *ScanUseCases) GetVulnerabilitySummary(ctx context.Context, imageName string, from, to *time.Time) (*entities.VulnerabilitySummary, error)
- func (s *ScanUseCases) GetVulnerabilityTrends(ctx context.Context, imageName, bucket string, from, to *time.Time) ([]entities.VulnerabilityTrendPoint, error)
- func (s *ScanUseCases) ListAllPage(ctx context.Context, imageName, tag string, limit, offset int) ([]entities.Scan, error)
- func (s *ScanUseCases) ListByImage(ctx context.Context, imageName string, limit, offset int, paginate bool) ([]entities.Scan, error)
- func (s *ScanUseCases) ListByImageWithSeverity(ctx context.Context, imageName, severity string, limit, offset int, ...) ([]entities.Scan, error)
- func (s *ScanUseCases) ListByTag(ctx context.Context, tag string, limit, offset int, paginate bool) ([]entities.Scan, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cleaner ¶
type Cleaner struct {
// contains filtered or unexported fields
}
Cleaner is a background worker that periodically removes old scan records according to the configured retention policies.
func NewCleaner ¶
func NewCleaner(cfg CleanupConfig, store boundary.ScanCleaner, logger zerolog.Logger) *Cleaner
NewCleaner creates a new Cleaner. Call Start() to begin the background loop.
type CleanupConfig ¶
type CleanupConfig struct {
// Interval between cleanup runs. Default: 1h.
Interval time.Duration
// MaxAge deletes scans older than this duration (e.g. 72h).
// 0 disables age-based cleanup.
MaxAge time.Duration
// KeepPerImage retains only the N most recent scans per image name.
// 0 disables count-based cleanup.
KeepPerImage int
}
CleanupConfig holds the retention policies for the cleanup worker. Zero values disable the corresponding policy.
type ScanUseCases ¶
type ScanUseCases struct {
// contains filtered or unexported fields
}
ScanUseCases orchestrates all scan-related business operations.
func NewScanUseCases ¶
func NewScanUseCases( persister boundary.ScanPersister, retriever boundary.ScanRetriever, analytics boundary.ScanAnalytics, ) *ScanUseCases
NewScanUseCases creates a new ScanUseCases, injecting its dependencies through the boundary interfaces (dependency inversion).
func (*ScanUseCases) CreateScan ¶
func (s *ScanUseCases) CreateScan( ctx context.Context, imageName, imageTag, imageDigest string, scanResult json.RawMessage, vuln entities.VulnCounts, vulns []entities.Vulnerability, ) (*entities.Scan, bool, error)
CreateScan stores a new scan record and its vulnerability rows.
func (*ScanUseCases) GetCVEAffectedImages ¶
func (s *ScanUseCases) GetCVEAffectedImages(ctx context.Context, cveID string) ([]entities.AffectedImage, error)
GetCVEAffectedImages returns all images currently exposed to a specific CVE.
func (*ScanUseCases) GetFixableSummary ¶
func (s *ScanUseCases) GetFixableSummary(ctx context.Context, imageName string, from, to *time.Time) (*entities.FixableSummary, error)
GetFixableSummary returns how many current vulnerabilities have a known fix.
func (*ScanUseCases) GetLatestScan ¶
GetLatestScan returns the most recent scan for the given image name.
func (*ScanUseCases) GetScanByID ¶
GetScanByID returns a scan by its UUID.
func (*ScanUseCases) GetTopCVEs ¶
func (s *ScanUseCases) GetTopCVEs(ctx context.Context, imageName, severity string, limit int, from, to *time.Time) ([]entities.TopCVE, error)
GetTopCVEs returns the most common CVEs across all images.
func (*ScanUseCases) GetVulnerabilitySummary ¶
func (s *ScanUseCases) GetVulnerabilitySummary(ctx context.Context, imageName string, from, to *time.Time) (*entities.VulnerabilitySummary, error)
GetVulnerabilitySummary returns aggregate vulnerability counts.
func (*ScanUseCases) GetVulnerabilityTrends ¶
func (s *ScanUseCases) GetVulnerabilityTrends(ctx context.Context, imageName, bucket string, from, to *time.Time) ([]entities.VulnerabilityTrendPoint, error)
GetVulnerabilityTrends returns vulnerability counts bucketed by day or week.
func (*ScanUseCases) ListAllPage ¶
func (s *ScanUseCases) ListAllPage(ctx context.Context, imageName, tag string, limit, offset int) ([]entities.Scan, error)
ListAllPage returns all scans with optional image/tag filters and pagination.
func (*ScanUseCases) ListByImage ¶
func (s *ScanUseCases) ListByImage(ctx context.Context, imageName string, limit, offset int, paginate bool) ([]entities.Scan, error)
ListByImage returns scans for an image, with optional pagination.
func (*ScanUseCases) ListByImageWithSeverity ¶
func (s *ScanUseCases) ListByImageWithSeverity(ctx context.Context, imageName, severity string, limit, offset int, paginate bool) ([]entities.Scan, error)
ListByImageWithSeverity returns scans for an image filtered by severity, with optional pagination.