usecases

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

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.

func (*Cleaner) Start

func (c *Cleaner) Start(ctx context.Context)

Start runs the cleanup loop in a goroutine until ctx is cancelled or Stop() is called.

func (*Cleaner) Stop

func (c *Cleaner) Stop()

Stop signals the cleanup worker to exit.

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

func (s *ScanUseCases) GetLatestScan(ctx context.Context, imageName string) (*entities.Scan, error)

GetLatestScan returns the most recent scan for the given image name.

func (*ScanUseCases) GetScanByID

func (s *ScanUseCases) GetScanByID(ctx context.Context, id string) (*entities.Scan, error)

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.

func (*ScanUseCases) ListByTag

func (s *ScanUseCases) ListByTag(ctx context.Context, tag string, limit, offset int, paginate bool) ([]entities.Scan, error)

ListByTag returns scans for a tag, with optional pagination.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL