storage

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package storage persists scans and findings. It provides an in-memory ring buffer backend for the hot path and a pure-Go SQLite backend for durability.

Index

Constants

View Source
const DefaultMemoryCapacity = 100

DefaultMemoryCapacity is how many scans the memory store keeps.

Variables

View Source
var ErrNotFound = errors.New("storage: not found")

ErrNotFound is returned when a scan or finding does not exist.

Functions

This section is empty.

Types

type FindingFilter

type FindingFilter struct {
	ScanID      string
	Severity    *core.Severity
	Category    *core.Category
	Status      core.Status
	Fingerprint string
	Limit       int
}

FindingFilter narrows ListFindings. Zero values mean "any".

type Memory

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

Memory is a fixed-size ring buffer of scans. When full, the oldest scan is overwritten. It is the hot-path store and the fallback with no DB.

func NewMemory

func NewMemory(capacity int) *Memory

NewMemory returns a ring buffer holding up to capacity scans.

func (*Memory) Close

func (m *Memory) Close() error

func (*Memory) GetScan

func (m *Memory) GetScan(_ context.Context, id string) (core.ScanResult, error)

func (*Memory) LatestScan

func (m *Memory) LatestScan(_ context.Context, target string) (core.ScanResult, error)

func (*Memory) ListFindings

func (m *Memory) ListFindings(_ context.Context, f FindingFilter) ([]core.Finding, error)

func (*Memory) ListScans

func (m *Memory) ListScans(_ context.Context, limit int) ([]core.ScanResult, error)

func (*Memory) Prune

func (m *Memory) Prune(_ context.Context, before time.Time) (int, error)

func (*Memory) SaveScan

func (m *Memory) SaveScan(_ context.Context, s core.ScanResult) error

type SQLite

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

SQLite is a durable Store backed by pure-Go SQLite (no CGo).

func OpenSQLite

func OpenSQLite(path string) (*SQLite, error)

OpenSQLite opens (or creates) the database at path and migrates the schema.

func (*SQLite) Close

func (s *SQLite) Close() error

func (*SQLite) GetScan

func (s *SQLite) GetScan(ctx context.Context, id string) (core.ScanResult, error)

func (*SQLite) LatestScan

func (s *SQLite) LatestScan(ctx context.Context, target string) (core.ScanResult, error)

func (*SQLite) ListFindings

func (s *SQLite) ListFindings(ctx context.Context, f FindingFilter) ([]core.Finding, error)

func (*SQLite) ListScans

func (s *SQLite) ListScans(ctx context.Context, limit int) ([]core.ScanResult, error)

func (*SQLite) Prune

func (s *SQLite) Prune(ctx context.Context, before time.Time) (int, error)

func (*SQLite) SaveScan

func (s *SQLite) SaveScan(ctx context.Context, sc core.ScanResult) error

type Store

type Store interface {
	// SaveScan inserts or replaces a scan, including its findings.
	SaveScan(ctx context.Context, s core.ScanResult) error
	GetScan(ctx context.Context, id string) (core.ScanResult, error)
	// ListScans returns scans newest first, without findings populated.
	ListScans(ctx context.Context, limit int) ([]core.ScanResult, error)
	// LatestScan returns the newest scan for a target name.
	LatestScan(ctx context.Context, target string) (core.ScanResult, error)
	ListFindings(ctx context.Context, f FindingFilter) ([]core.Finding, error)
	// Prune deletes scans that finished before the cutoff and returns how many.
	Prune(ctx context.Context, before time.Time) (int, error)
	Close() error
}

Store persists scans and findings. Implementations are safe for concurrent use.

Jump to

Keyboard shortcuts

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