remediation

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: GPL-3.0 Imports: 8 Imported by: ? 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 remediation provides domain models for remediation campaign management.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCampaignNotFound = fmt.Errorf("%w: remediation campaign not found", shared.ErrNotFound)
)

Errors

View Source
var ErrCampaignTicketNotFound = fmt.Errorf("%w: campaign ticket not found", shared.ErrNotFound)

ErrCampaignTicketNotFound is returned when no ticket links a campaign.

Functions

func DeriveKey added in v0.4.0

func DeriveKey(in KeyInput) (key, title string, ok bool)

DeriveKey computes the remediation-group key and a human-readable title for a finding. ok is false when the finding is not groupable (no shared fix signal).

Grouping precedence:

  1. SCA / package: group by component identity — one upgrade resolves every finding on that package. This is the strongest, most reliable signal.
  2. Host / infra: group by the normalized solution text (Nessus/Tenable "solution" — the patch that fixes a whole plugin family).

Types

type Campaign

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

Campaign tracks a remediation effort across multiple findings.

func NewCampaign

func NewCampaign(tenantID shared.ID, name string, priority CampaignPriority) (*Campaign, error)

NewCampaign creates a new remediation campaign.

func ReconstituteCampaign

func ReconstituteCampaign(
	id, tenantID shared.ID,
	name, description string,
	status CampaignStatus, priority CampaignPriority,
	findingFilter map[string]any,
	findingCount, resolvedCount int, progress float64,
	riskBefore, riskAfter, riskReduction *float64,
	assignedTo, assignedTeam *shared.ID,
	startDate, dueDate, completedAt *time.Time,
	tags []string, createdBy *shared.ID,
	createdAt, updatedAt time.Time,
) *Campaign

ReconstituteCampaign creates from persisted data.

func (*Campaign) Activate

func (c *Campaign) Activate() error

Activate transitions to active status.

func (*Campaign) AllFindingsResolved added in v0.2.0

func (c *Campaign) AllFindingsResolved() bool

AllFindingsResolved reports whether every finding in the campaign is resolved (progress at 100%). A zero-finding campaign is NOT treated as complete — an empty campaign is a misconfiguration, not an accomplishment.

func (*Campaign) AssignedTeam

func (c *Campaign) AssignedTeam() *shared.ID

func (*Campaign) AssignedTo

func (c *Campaign) AssignedTo() *shared.ID

func (*Campaign) Cancel

func (c *Campaign) Cancel() error

Cancel transitions to canceled. Terminal states (completed, already canceled) cannot be canceled — mirrors the guards on the other transitions.

func (*Campaign) Complete

func (c *Campaign) Complete() error

Complete transitions to completed.

func (*Campaign) CompletedAt

func (c *Campaign) CompletedAt() *time.Time

func (*Campaign) CreatedAt

func (c *Campaign) CreatedAt() time.Time

func (*Campaign) CreatedBy

func (c *Campaign) CreatedBy() *shared.ID

func (*Campaign) Description

func (c *Campaign) Description() string

func (*Campaign) DueDate

func (c *Campaign) DueDate() *time.Time

func (*Campaign) FindingCount

func (c *Campaign) FindingCount() int

func (*Campaign) FindingFilter

func (c *Campaign) FindingFilter() map[string]any

func (*Campaign) ID

func (c *Campaign) ID() shared.ID

Getters

func (*Campaign) IsOverdue

func (c *Campaign) IsOverdue() bool

IsOverdue returns true if past due date and not completed.

func (*Campaign) Name

func (c *Campaign) Name() string

func (*Campaign) Pause

func (c *Campaign) Pause() error

Pause transitions to paused.

func (*Campaign) Priority

func (c *Campaign) Priority() CampaignPriority

func (*Campaign) Progress

func (c *Campaign) Progress() float64

func (*Campaign) RecordRiskReduction

func (c *Campaign) RecordRiskReduction(before, after float64)

RecordRiskReduction records risk before/after for this campaign.

func (*Campaign) ResolvedCount

func (c *Campaign) ResolvedCount() int

func (*Campaign) RiskAfter

func (c *Campaign) RiskAfter() *float64

func (*Campaign) RiskBefore

func (c *Campaign) RiskBefore() *float64

func (*Campaign) RiskReduction

func (c *Campaign) RiskReduction() *float64

func (*Campaign) SetAssignment

func (c *Campaign) SetAssignment(assignedTo, assignedTeam *shared.ID)

SetAssignment sets who/what team is responsible.

func (*Campaign) SetCreatedBy

func (c *Campaign) SetCreatedBy(userID shared.ID)

SetCreatedBy sets the creator.

func (*Campaign) SetDescription added in v0.1.7

func (c *Campaign) SetDescription(desc string)

SetDescription sets campaign description.

func (*Campaign) SetDueDate added in v0.1.7

func (c *Campaign) SetDueDate(d *time.Time)

SetDueDate sets campaign due date.

func (*Campaign) SetFindingFilter

func (c *Campaign) SetFindingFilter(filter map[string]any)

SetFindingFilter sets the filter criteria for this campaign's findings.

func (*Campaign) SetName added in v0.1.7

func (c *Campaign) SetName(name string)

SetName sets campaign name.

func (*Campaign) SetPriority added in v0.1.7

func (c *Campaign) SetPriority(p CampaignPriority)

SetPriority sets campaign priority.

func (*Campaign) SetStartDate added in v0.4.0

func (c *Campaign) SetStartDate(d *time.Time)

SetStartDate sets campaign start date.

func (*Campaign) SetTags

func (c *Campaign) SetTags(tags []string)

SetTags sets campaign tags.

func (*Campaign) SetTimeline

func (c *Campaign) SetTimeline(startDate, dueDate *time.Time)

SetTimeline sets start and due dates.

func (*Campaign) StartDate

func (c *Campaign) StartDate() *time.Time

func (*Campaign) StartValidation

func (c *Campaign) StartValidation() error

StartValidation transitions to validating (re-scanning to verify fixes).

func (*Campaign) Status

func (c *Campaign) Status() CampaignStatus

func (*Campaign) Tags

func (c *Campaign) Tags() []string

func (*Campaign) TenantID

func (c *Campaign) TenantID() shared.ID

func (*Campaign) TryAutoComplete added in v0.2.0

func (c *Campaign) TryAutoComplete() (bool, error)

TryAutoComplete attempts the active/validating → completed transition when all findings are resolved. this is what turns "every finding in my campaign hit resolved" into an actual campaign-level event without an operator clicking Complete.

Returns (true, nil) on successful auto-complete. Returns (false, nil) when not yet eligible — callers should treat this as a normal no-op, not an error. Returns (_, err) for genuine state-machine or validation failures.

func (*Campaign) Update

func (c *Campaign) Update(name, description string, priority CampaignPriority)

Update sets mutable fields.

func (*Campaign) UpdateProgress

func (c *Campaign) UpdateProgress(findingCount, resolvedCount int)

UpdateProgress updates finding counts and progress percentage.

func (*Campaign) UpdatedAt

func (c *Campaign) UpdatedAt() time.Time

type CampaignFilter

type CampaignFilter struct {
	TenantID *shared.ID
	Status   *CampaignStatus
	Priority *CampaignPriority
	Search   *string
}

CampaignFilter defines criteria for listing campaigns.

type CampaignPriority

type CampaignPriority string

CampaignPriority defines urgency levels.

const (
	CampaignPriorityCritical CampaignPriority = "critical"
	CampaignPriorityHigh     CampaignPriority = "high"
	CampaignPriorityMedium   CampaignPriority = "medium"
	CampaignPriorityLow      CampaignPriority = "low"
)

type CampaignRepository

type CampaignRepository interface {
	Create(ctx context.Context, campaign *Campaign) error
	GetByID(ctx context.Context, tenantID, id shared.ID) (*Campaign, error)
	Update(ctx context.Context, campaign *Campaign) error
	Delete(ctx context.Context, tenantID, id shared.ID) error
	List(ctx context.Context, filter CampaignFilter, page pagination.Pagination) (pagination.Result[*Campaign], error)

	// ListNonTerminal returns campaigns that are not in a terminal state
	// (completed/canceled) across all tenants, ordered by least-recently
	// updated first, up to limit. Used by the progress-reconcile controller
	// to refresh finding counts and auto-complete. limit <= 0 means a
	// repository-chosen default.
	ListNonTerminal(ctx context.Context, limit int) ([]*Campaign, error)
}

CampaignRepository defines persistence for remediation campaigns.

type CampaignStatus

type CampaignStatus string

CampaignStatus defines lifecycle states.

const (
	CampaignStatusDraft      CampaignStatus = "draft"
	CampaignStatusActive     CampaignStatus = "active"
	CampaignStatusPaused     CampaignStatus = "paused"
	CampaignStatusValidating CampaignStatus = "validating"
	CampaignStatusCompleted  CampaignStatus = "completed"
	CampaignStatusCanceled   CampaignStatus = "canceled"
)

type CampaignTicket added in v0.3.0

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

CampaignTicket links a remediation campaign to an external tracker issue (currently a Jira epic). At most one ticket per (campaign, provider).

func NewCampaignTicket added in v0.3.0

func NewCampaignTicket(tenantID, campaignID shared.ID, provider, issueKey, issueURL string) (*CampaignTicket, error)

NewCampaignTicket creates a new campaign↔issue link.

func ReconstituteCampaignTicket added in v0.3.0

func ReconstituteCampaignTicket(id, tenantID, campaignID shared.ID, provider, issueKey, issueURL string, createdAt, updatedAt time.Time) *CampaignTicket

ReconstituteCampaignTicket rebuilds a CampaignTicket from persisted data.

func (*CampaignTicket) CampaignID added in v0.3.0

func (t *CampaignTicket) CampaignID() shared.ID

func (*CampaignTicket) CreatedAt added in v0.3.0

func (t *CampaignTicket) CreatedAt() time.Time

func (*CampaignTicket) ID added in v0.3.0

func (t *CampaignTicket) ID() shared.ID

func (*CampaignTicket) IssueKey added in v0.3.0

func (t *CampaignTicket) IssueKey() string

func (*CampaignTicket) IssueURL added in v0.3.0

func (t *CampaignTicket) IssueURL() string

func (*CampaignTicket) Provider added in v0.3.0

func (t *CampaignTicket) Provider() string

func (*CampaignTicket) TenantID added in v0.3.0

func (t *CampaignTicket) TenantID() shared.ID

func (*CampaignTicket) UpdatedAt added in v0.3.0

func (t *CampaignTicket) UpdatedAt() time.Time

type CampaignTicketRepository added in v0.3.0

type CampaignTicketRepository interface {
	Create(ctx context.Context, t *CampaignTicket) error
	// GetByCampaignAndProvider returns the link for a campaign+provider, or
	// ErrCampaignTicketNotFound.
	GetByCampaignAndProvider(ctx context.Context, tenantID, campaignID shared.ID, provider string) (*CampaignTicket, error)
	// GetByIssueKey returns the link for a provider issue key (the inbound
	// direction: webhook → campaign), or ErrCampaignTicketNotFound.
	GetByIssueKey(ctx context.Context, tenantID shared.ID, provider, issueKey string) (*CampaignTicket, error)
	// ListByCampaignIDs returns the links for the given campaigns, keyed by
	// campaign id string. Used to enrich a campaign list without N+1 lookups.
	// Campaigns with no link are simply absent from the map.
	ListByCampaignIDs(ctx context.Context, tenantID shared.ID, campaignIDs []shared.ID) (map[string]*CampaignTicket, error)
}

CampaignTicketRepository persists campaign↔issue links.

type Group added in v0.4.0

type Group struct {
	Key            string         `json:"key"`
	Title          string         `json:"title"`
	FindingCount   int            `json:"finding_count"`
	AssetCount     int            `json:"asset_count"`
	SeverityCounts map[string]int `json:"severity_counts"`
	FixAvailable   bool           `json:"fix_available"`
}

Group is one remediation group: the set of open findings a single fix resolves.

type KeyInput added in v0.4.0

type KeyInput struct {
	// ComponentKey is a stable package identity (purl, or name@ecosystem) when
	// the finding is on a dependency/package. Empty for non-SCA findings.
	ComponentKey string
	// FixAvailable reports that a fix/upgrade is known (a fixed version exists,
	// or the scanner supplied a fix). Only groupable fixes form SCA groups.
	FixAvailable bool
	// SolutionText is the remediation recommendation / Nessus <solution> — the
	// fallback grouping signal for host/infra findings.
	SolutionText string
}

KeyInput carries the finding signals used to derive a remediation group key. Primitives only, so the derivation stays decoupled from the vulnerability package and is trivially unit-testable.

type KeyRepository added in v0.4.0

type KeyRepository interface {
	// Upsert records (or refreshes) a finding's remediation key. Idempotent on
	// finding_id, so re-ingesting a finding keeps its key current.
	Upsert(ctx context.Context, tenantID, findingID shared.ID, key, title string) error

	// Delete removes a finding's key (e.g. when it becomes ungroupable). Deleting
	// the finding itself CASCADE-removes the row.
	Delete(ctx context.Context, findingID shared.ID) error

	// ListGroups returns groups rolled up over the tenant's OPEN findings.
	// excludeStatuses are the closed finding statuses to leave out; pentest
	// findings are always excluded (they own their lifecycle).
	ListGroups(ctx context.Context, tenantID shared.ID, excludeStatuses []string) ([]Group, error)

	// OpenFindingIDs returns the tenant's open, non-pentest finding IDs in a group
	// — the set a "resolve group" action transitions.
	OpenFindingIDs(ctx context.Context, tenantID shared.ID, key string, excludeStatuses []string) ([]shared.ID, error)

	// CountByKey returns (total, resolved) non-pentest findings sharing the key —
	// total across all statuses, resolved being those in closedStatuses. Used to
	// track a solution-family campaign's progress without a generic FindingFilter.
	CountByKey(ctx context.Context, tenantID shared.ID, key string, closedStatuses []string) (total, resolved int64, err error)
}

KeyRepository persists per-finding remediation keys and answers group queries. It owns the finding_remediation_keys side-table; it never writes findings.

Jump to

Keyboard shortcuts

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