reclassify

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: GPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reclassify provides the runtime glue that connects priority-change producers (threat-intel refresh, control CRUD, rule CRUD) to the PriorityReclassifyController's queue/Reclassifier contracts.

The package lives under internal/app so the app-layer wire sites (services.go) can see it directly; controller itself imports app for unrelated reasons, so placing the adapters in `app` directly would introduce a cycle. Keep new code here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryQueue

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

MemoryQueue is a minimal in-process ReclassifyQueue. It is intentionally unbounded (slice-backed) but tolerates burst enqueues cheaply — the controller drains at Interval=5m with BatchSize=64, so backlog in practice is small. When the API scales beyond a single replica, swap this for a Redis or Postgres queue; the interface is stable.

Order: FIFO. Dedup: none (controller-side dedup is cheaper — two enqueues for the same (tenant,asset) do the same work twice but don't produce duplicate priority_changed events thanks to the publisher's "no transition = no publish" guard).

func NewMemoryQueue

func NewMemoryQueue() *MemoryQueue

NewMemoryQueue constructs an empty queue.

func (*MemoryQueue) DequeueBatch

func (q *MemoryQueue) DequeueBatch(_ context.Context, max int) ([]controller.ReclassifyRequest, error)

DequeueBatch pops up to max requests. Returns an empty slice (nil error) when empty.

func (*MemoryQueue) Enqueue

Enqueue adds a request. Safe for concurrent use.

func (*MemoryQueue) Len

func (q *MemoryQueue) Len() int

Len is exposed for observability/dashboards. Safe for concurrent use.

type PriorityClassifier

type PriorityClassifier interface {
	ClassifyFinding(ctx context.Context, tenantID shared.ID, finding *vulnerability.Finding, a *asset.Asset) error
}

PriorityClassifier is the narrow surface the reclassifier needs from PriorityClassificationService. Narrow to keep tests cheap.

type Reclassifier

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

Reclassifier implements controller.Reclassifier. It turns a scope (AssetIDs, CVEIDs) into concrete Finding+Asset pairs and delegates to the classifier. The classifier already handles priority_changed event emission via its attached publisher — so a sweep that re-confirms the same class is silent, and a sweep that moves a class fans out correctly.

Two scopes are handled:

  • AssetIDs non-empty → reclassify exactly those assets (control-change and asset-change publishers).
  • AssetIDs empty → whole-tenant sweep: list the tenant's open findings, collect their distinct assets, and reclassify each. This is what the KEV/EPSS-refresh producers (which enqueue per-tenant with no AssetIDs) and the periodic sweep producer rely on.

func NewReclassifier

func NewReclassifier(
	findings vulnerability.FindingRepository,
	assets asset.Repository,
	classifier PriorityClassifier,
	log *logger.Logger,
) *Reclassifier

NewReclassifier wires deps.

func (*Reclassifier) ReclassifyForRequest

func (r *Reclassifier) ReclassifyForRequest(
	ctx context.Context,
	req controller.ReclassifyRequest,
) (int, error)

ReclassifyForRequest satisfies controller.Reclassifier.

Strategy:

  1. If req.AssetIDs is non-empty → iterate each asset, page findings, classify. This is the control-change / asset-change path.
  2. Otherwise → treat as a whole-tenant sweep: page the tenant's open findings, collect their distinct asset IDs, and reclassify each. This is the KEV/EPSS-refresh and periodic-sweep path.

func (*Reclassifier) SetSLARecomputer added in v0.4.0

func (r *Reclassifier) SetSLARecomputer(s SLARecomputer)

SetSLARecomputer wires the SLA-deadline recomputer used after a finding is reclassified, so an escalation (e.g. new KEV listing → P0) tightens the deadline. Optional: nil → deadlines are left unchanged by the sweep.

type SLARecomputer added in v0.4.0

type SLARecomputer interface {
	ApplyBatch(ctx context.Context, tenantID shared.ID, findings []*vulnerability.Finding) error
}

SLARecomputer recomputes a finding's SLA deadline from its (possibly just escalated) priority class. Implemented by *sla.Applier. When a sweep moves a finding to a higher priority — e.g. a CVE newly listed in KEV → P0 — the SLA deadline must tighten to match; without this the deadline stays at the laxer, pre-escalation value and escalation never fires on time.

Jump to

Keyboard shortcuts

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