statestore

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrScanNotFound = errors.New("scan not found")

ErrScanNotFound is returned by GetLastScan when no scan record exists for the given digest. This is a normal condition indicating the image has never been scanned before. Callers should use errors.Is() to check for this specific error.

Functions

This section is empty.

Types

type SQLiteStore

type SQLiteStore struct {
	// contains filtered or unexported fields
}

SQLiteStore implements StateStore using SQLite

func NewSQLiteStore

func NewSQLiteStore(dbPath string) (*SQLiteStore, error)

NewSQLiteStore creates a new SQLite state store

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close closes the database connection

func (*SQLiteStore) GetImagesByCVE

func (s *SQLiteStore) GetImagesByCVE(ctx context.Context, cveID string) ([]*ScanRecord, error)

GetImagesByCVE returns all images affected by a specific CVE

func (*SQLiteStore) GetLastScan

func (s *SQLiteStore) GetLastScan(ctx context.Context, digest string) (*ScanRecord, error)

GetLastScan retrieves the most recent scan for a digest with vulnerabilities

func (*SQLiteStore) GetScanHistory

func (s *SQLiteStore) GetScanHistory(ctx context.Context, digest string, limit int) ([]*ScanRecord, error)

GetScanHistory returns scan history for a digest with full details

func (*SQLiteStore) ListDueForRescan

func (s *SQLiteStore) ListDueForRescan(ctx context.Context, interval time.Duration) ([]string, error)

ListDueForRescan returns digests that need rescanning

func (*SQLiteStore) ListScans

func (s *SQLiteStore) ListScans(ctx context.Context, filter ScanFilter) ([]*ScanRecord, error)

ListScans returns scan records with optional filters

func (*SQLiteStore) ListTolerations

func (s *SQLiteStore) ListTolerations(ctx context.Context, filter TolerationFilter) ([]*types.TolerationInfo, error)

ListTolerations returns tolerated CVEs with optional filters Returns one entry per unique repository + CVE ID combination

func (*SQLiteStore) QueryVulnerabilities

func (s *SQLiteStore) QueryVulnerabilities(ctx context.Context, filter VulnFilter) ([]*types.VulnerabilityRecord, error)

QueryVulnerabilities searches vulnerabilities across all scans

func (*SQLiteStore) RecordScan

func (s *SQLiteStore) RecordScan(ctx context.Context, record *ScanRecord) error

RecordScan saves scan results with full vulnerability details in a transaction

type ScanFilter

type ScanFilter struct {
	Repository   string
	PolicyPassed *bool
	Limit        int
	Offset       int
}

ScanFilter defines criteria for listing scans

type ScanRecord

type ScanRecord struct {
	Digest            string
	Repository        string
	Tag               string
	ScannedAt         time.Time
	CriticalVulnCount int
	HighVulnCount     int
	MediumVulnCount   int
	LowVulnCount      int
	PolicyPassed      bool
	Signed            bool
	SBOMAttested      bool
	VulnAttested      bool
	Vulnerabilities   []types.VulnerabilityRecord // Using canonical type
	ToleratedCVEs     []types.ToleratedCVE        // Using canonical type
	ErrorMessage      string
}

ScanRecord represents a complete scan result for an image digest

type StateStore

type StateStore interface {
	// RecordScan saves scan results with full vulnerability details
	RecordScan(ctx context.Context, record *ScanRecord) error

	// GetLastScan retrieves the most recent scan for a digest with vulnerabilities
	GetLastScan(ctx context.Context, digest string) (*ScanRecord, error)
}

StateStore defines the core interface for persisting scan results. This interface contains only the methods used by the worker for recording and checking scan state. For querying and reporting, use StateStoreQuery.

type StateStoreQuery

type StateStoreQuery interface {
	StateStore

	// GetScanHistory returns scan history for a digest with full details
	GetScanHistory(ctx context.Context, digest string, limit int) ([]*ScanRecord, error)

	// QueryVulnerabilities searches vulnerabilities across all scans
	QueryVulnerabilities(ctx context.Context, filter VulnFilter) ([]*types.VulnerabilityRecord, error)

	// GetImagesByCVE returns all images affected by a specific CVE
	GetImagesByCVE(ctx context.Context, cveID string) ([]*ScanRecord, error)

	// ListScans returns scan records with optional filters
	ListScans(ctx context.Context, filter ScanFilter) ([]*ScanRecord, error)

	// ListTolerations returns tolerated CVEs with optional filters
	ListTolerations(ctx context.Context, filter TolerationFilter) ([]*types.TolerationInfo, error)
}

StateStoreQuery defines the extended interface for querying scan data. This interface is primarily used by the API layer for reporting and analysis. Implementations should also implement StateStore for core functionality.

type TolerationFilter

type TolerationFilter struct {
	CVEID        string
	Repository   string
	Expired      *bool
	ExpiringSoon *bool // Within 7 days
	Limit        int
}

TolerationFilter defines criteria for listing tolerations

type VulnFilter

type VulnFilter struct {
	CVEID       string
	Severity    string
	PackageName string
	Repository  string
	Limit       int
}

VulnFilter defines criteria for querying vulnerabilities

Jump to

Keyboard shortcuts

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