Documentation
¶
Overview ¶
Package remediation provides domain models for remediation campaign management.
Index ¶
- Variables
- func DeriveKey(in KeyInput) (key, title string, ok bool)
- type Campaign
- func (c *Campaign) Activate() error
- func (c *Campaign) AllFindingsResolved() bool
- func (c *Campaign) AssignedTeam() *shared.ID
- func (c *Campaign) AssignedTo() *shared.ID
- func (c *Campaign) Cancel() error
- func (c *Campaign) Complete() error
- func (c *Campaign) CompletedAt() *time.Time
- func (c *Campaign) CreatedAt() time.Time
- func (c *Campaign) CreatedBy() *shared.ID
- func (c *Campaign) Description() string
- func (c *Campaign) DueDate() *time.Time
- func (c *Campaign) FindingCount() int
- func (c *Campaign) FindingFilter() map[string]any
- func (c *Campaign) ID() shared.ID
- func (c *Campaign) IsOverdue() bool
- func (c *Campaign) Name() string
- func (c *Campaign) Pause() error
- func (c *Campaign) Priority() CampaignPriority
- func (c *Campaign) Progress() float64
- func (c *Campaign) RecordRiskReduction(before, after float64)
- func (c *Campaign) ResolvedCount() int
- func (c *Campaign) RiskAfter() *float64
- func (c *Campaign) RiskBefore() *float64
- func (c *Campaign) RiskReduction() *float64
- func (c *Campaign) SetAssignment(assignedTo, assignedTeam *shared.ID)
- func (c *Campaign) SetCreatedBy(userID shared.ID)
- func (c *Campaign) SetDescription(desc string)
- func (c *Campaign) SetDueDate(d *time.Time)
- func (c *Campaign) SetFindingFilter(filter map[string]any)
- func (c *Campaign) SetName(name string)
- func (c *Campaign) SetPriority(p CampaignPriority)
- func (c *Campaign) SetStartDate(d *time.Time)
- func (c *Campaign) SetTags(tags []string)
- func (c *Campaign) SetTimeline(startDate, dueDate *time.Time)
- func (c *Campaign) StartDate() *time.Time
- func (c *Campaign) StartValidation() error
- func (c *Campaign) Status() CampaignStatus
- func (c *Campaign) Tags() []string
- func (c *Campaign) TenantID() shared.ID
- func (c *Campaign) TryAutoComplete() (bool, error)
- func (c *Campaign) Update(name, description string, priority CampaignPriority)
- func (c *Campaign) UpdateProgress(findingCount, resolvedCount int)
- func (c *Campaign) UpdatedAt() time.Time
- type CampaignFilter
- type CampaignPriority
- type CampaignRepository
- type CampaignStatus
- type CampaignTicket
- func (t *CampaignTicket) CampaignID() shared.ID
- func (t *CampaignTicket) CreatedAt() time.Time
- func (t *CampaignTicket) ID() shared.ID
- func (t *CampaignTicket) IssueKey() string
- func (t *CampaignTicket) IssueURL() string
- func (t *CampaignTicket) Provider() string
- func (t *CampaignTicket) TenantID() shared.ID
- func (t *CampaignTicket) UpdatedAt() time.Time
- type CampaignTicketRepository
- type Group
- type KeyInput
- type KeyRepository
Constants ¶
This section is empty.
Variables ¶
var (
ErrCampaignNotFound = fmt.Errorf("%w: remediation campaign not found", shared.ErrNotFound)
)
Errors
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
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:
- SCA / package: group by component identity — one upgrade resolves every finding on that package. This is the strongest, most reliable signal.
- 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 ¶
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) AllFindingsResolved ¶ added in v0.2.0
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 (*Campaign) AssignedTo ¶
func (*Campaign) Cancel ¶
Cancel transitions to canceled. Terminal states (completed, already canceled) cannot be canceled — mirrors the guards on the other transitions.
func (*Campaign) CompletedAt ¶
func (*Campaign) Description ¶
func (*Campaign) FindingCount ¶
func (*Campaign) FindingFilter ¶
func (*Campaign) Priority ¶
func (c *Campaign) Priority() CampaignPriority
func (*Campaign) RecordRiskReduction ¶
RecordRiskReduction records risk before/after for this campaign.
func (*Campaign) ResolvedCount ¶
func (*Campaign) RiskBefore ¶
func (*Campaign) RiskReduction ¶
func (*Campaign) SetAssignment ¶
SetAssignment sets who/what team is responsible.
func (*Campaign) SetCreatedBy ¶
SetCreatedBy sets the creator.
func (*Campaign) SetDescription ¶ added in v0.1.7
SetDescription sets campaign description.
func (*Campaign) SetDueDate ¶ added in v0.1.7
SetDueDate sets campaign due date.
func (*Campaign) SetFindingFilter ¶
SetFindingFilter sets the filter criteria for this campaign's findings.
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
SetStartDate sets campaign start date.
func (*Campaign) SetTimeline ¶
SetTimeline sets start and due dates.
func (*Campaign) StartValidation ¶
StartValidation transitions to validating (re-scanning to verify fixes).
func (*Campaign) Status ¶
func (c *Campaign) Status() CampaignStatus
func (*Campaign) TryAutoComplete ¶ added in v0.2.0
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 ¶
UpdateProgress updates finding counts and progress percentage.
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.