Documentation
¶
Overview ¶
Package suppression provides domain logic for platform-controlled false positive management.
Index ¶
- Variables
- type ApproveRuleInput
- type CreateRuleInput
- type FindingMatch
- type FindingSuppression
- type RejectRuleInput
- type Repository
- type Rule
- func (r *Rule) Approve(approvedBy shared.ID) error
- func (r *Rule) ApprovedAt() *time.Time
- func (r *Rule) ApprovedBy() *shared.ID
- func (r *Rule) AssetID() *shared.ID
- func (r *Rule) CreatedAt() time.Time
- func (r *Rule) Description() string
- func (r *Rule) Expire()
- func (r *Rule) ExpiresAt() *time.Time
- func (r *Rule) HasCriteria() bool
- func (r *Rule) ID() shared.ID
- func (r *Rule) IsActive() bool
- func (r *Rule) IsExpired() bool
- func (r *Rule) Matches(f FindingMatch) bool
- func (r *Rule) Name() string
- func (r *Rule) PathPattern() string
- func (r *Rule) Reject(rejectedBy shared.ID, reason string) error
- func (r *Rule) RejectedAt() *time.Time
- func (r *Rule) RejectedBy() *shared.ID
- func (r *Rule) RejectionReason() string
- func (r *Rule) RequestedAt() time.Time
- func (r *Rule) RequestedBy() shared.ID
- func (r *Rule) RuleID() string
- func (r *Rule) SetAssetID(assetID *shared.ID)
- func (r *Rule) SetDescription(description string)
- func (r *Rule) SetExpiresAt(expiresAt *time.Time)
- func (r *Rule) SetName(name string)
- func (r *Rule) SetPathPattern(pattern string)
- func (r *Rule) SetRuleIDPattern(pattern string)
- func (r *Rule) SetToolName(toolName string)
- func (r *Rule) Status() RuleStatus
- func (r *Rule) SuppressionType() SuppressionType
- func (r *Rule) TenantID() shared.ID
- func (r *Rule) ToolName() string
- func (r *Rule) UpdatedAt() time.Time
- func (r *Rule) Validate() error
- type RuleData
- type RuleFilter
- type RuleStatus
- type Service
- func (s *Service) ApplySuppression(ctx context.Context, findingID, ruleID shared.ID) error
- func (s *Service) ApproveRule(ctx context.Context, input ApproveRuleInput) (*Rule, error)
- func (s *Service) CheckSuppression(ctx context.Context, tenantID shared.ID, match FindingMatch) ([]*Rule, error)
- func (s *Service) CreateRule(ctx context.Context, input CreateRuleInput) (*Rule, error)
- func (s *Service) DeleteRule(ctx context.Context, tenantID, ruleID, deletedBy shared.ID) error
- func (s *Service) ExpireRules(ctx context.Context) (int64, error)
- func (s *Service) GetRule(ctx context.Context, tenantID, ruleID shared.ID) (*Rule, error)
- func (s *Service) ListActiveRules(ctx context.Context, tenantID shared.ID) ([]*Rule, error)
- func (s *Service) ListPendingRules(ctx context.Context, tenantID shared.ID) ([]*Rule, error)
- func (s *Service) ListRules(ctx context.Context, tenantID shared.ID, filter RuleFilter) ([]*Rule, error)
- func (s *Service) RejectRule(ctx context.Context, input RejectRuleInput) (*Rule, error)
- func (s *Service) UpdateRule(ctx context.Context, input UpdateRuleInput) (*Rule, error)
- type SuppressionType
- type UpdateRuleInput
Constants ¶
This section is empty.
Variables ¶
var ( ErrRuleNotFound = errors.New("suppression rule not found") ErrRuleAlreadyExists = errors.New("suppression rule already exists") ErrRuleNotPending = errors.New("suppression rule is not pending") ErrRuleExpired = errors.New("suppression rule has expired") ErrInvalidCriteria = errors.New("invalid suppression criteria") ErrSuppressionExists = errors.New("finding already suppressed by this rule") )
Domain errors for suppression rules.
Functions ¶
This section is empty.
Types ¶
type ApproveRuleInput ¶
ApproveRuleInput contains input for approving a rule.
type CreateRuleInput ¶
type CreateRuleInput struct {
TenantID shared.ID
Name string
Description string
SuppressionType SuppressionType
RuleID string // Tool rule ID pattern
ToolName string // Tool name filter
PathPattern string // File path pattern
AssetID *shared.ID // Optional asset filter
RequestedBy shared.ID
ExpiresAt *string // ISO8601 format
}
CreateRuleInput contains input for creating a suppression rule.
type FindingMatch ¶
MatchesFinding checks if the rule matches a finding.
type FindingSuppression ¶
type FindingSuppression struct {
ID shared.ID
FindingID shared.ID
SuppressionRuleID shared.ID
AppliedAt string
AppliedBy string
}
FindingSuppression represents a suppression applied to a finding.
type RejectRuleInput ¶
type RejectRuleInput struct {
TenantID shared.ID
RuleID shared.ID
RejectedBy shared.ID
Reason string
}
RejectRuleInput contains input for rejecting a rule.
type Repository ¶
type Repository interface {
// Rule operations
Save(ctx context.Context, rule *Rule) error
FindByID(ctx context.Context, tenantID, id shared.ID) (*Rule, error)
Delete(ctx context.Context, tenantID, id shared.ID) error
// Query operations
FindByTenant(ctx context.Context, tenantID shared.ID, filter RuleFilter) ([]*Rule, error)
FindActiveByTenant(ctx context.Context, tenantID shared.ID) ([]*Rule, error)
FindPendingByTenant(ctx context.Context, tenantID shared.ID) ([]*Rule, error)
// Matching
FindMatchingRules(ctx context.Context, tenantID shared.ID, match FindingMatch) ([]*Rule, error)
// Bulk operations
ExpireRules(ctx context.Context) (int64, error)
// Finding suppressions
RecordSuppression(ctx context.Context, findingID, ruleID shared.ID, appliedBy string) error
FindSuppressionsByFinding(ctx context.Context, findingID shared.ID) ([]*FindingSuppression, error)
RemoveSuppression(ctx context.Context, findingID, ruleID shared.ID) error
// Audit
RecordAudit(ctx context.Context, ruleID shared.ID, action string, actorID *shared.ID, details map[string]any) error
}
Repository defines the interface for suppression rule persistence.
type Rule ¶
type Rule struct {
// contains filtered or unexported fields
}
Rule represents a suppression rule for findings.
func NewRule ¶
func NewRule( tenantID shared.ID, name string, suppressionType SuppressionType, requestedBy shared.ID, ) (*Rule, error)
NewRule creates a new suppression rule.
func ReconstituteRule ¶
ReconstituteRule recreates a Rule from persistence.
func (*Rule) ApprovedAt ¶
func (*Rule) ApprovedBy ¶
func (*Rule) Description ¶
func (*Rule) HasCriteria ¶
HasCriteria checks if the rule has at least one matching criterion.
func (*Rule) Matches ¶
func (r *Rule) Matches(f FindingMatch) bool
Matches checks if this suppression rule matches the given finding.
func (*Rule) PathPattern ¶
func (*Rule) RejectedAt ¶
func (*Rule) RejectedBy ¶
func (*Rule) RejectionReason ¶
func (*Rule) RequestedAt ¶
func (*Rule) RequestedBy ¶
func (*Rule) SetAssetID ¶
SetAssetID sets the asset ID filter.
func (*Rule) SetDescription ¶
SetDescription sets the description.
func (*Rule) SetExpiresAt ¶
SetExpiresAt sets the expiration date.
func (*Rule) SetPathPattern ¶
SetPathPattern sets the file path pattern.
func (*Rule) SetRuleIDPattern ¶
SetRuleIDPattern sets the rule ID pattern.
func (*Rule) SetToolName ¶
SetToolName sets the tool name filter.
func (*Rule) Status ¶
func (r *Rule) Status() RuleStatus
func (*Rule) SuppressionType ¶
func (r *Rule) SuppressionType() SuppressionType
type RuleData ¶
type RuleData struct {
ID shared.ID
TenantID shared.ID
RuleID string
ToolName string
PathPattern string
AssetID *shared.ID
Name string
Description string
SuppressionType SuppressionType
Status RuleStatus
RequestedBy shared.ID
RequestedAt time.Time
ApprovedBy *shared.ID
ApprovedAt *time.Time
RejectedBy *shared.ID
RejectedAt *time.Time
RejectionReason string
ExpiresAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
RuleData contains all data needed to reconstitute a Rule from persistence.
type RuleFilter ¶
type RuleFilter struct {
Status *RuleStatus
SuppressionType *SuppressionType
ToolName *string
AssetID *shared.ID
RequestedBy *shared.ID
IncludeExpired bool
Limit int
Offset int
}
RuleFilter provides filtering options for rule queries.
type RuleStatus ¶
type RuleStatus string
RuleStatus represents the approval status of a suppression rule.
const ( RuleStatusPending RuleStatus = "pending" RuleStatusApproved RuleStatus = "approved" RuleStatusRejected RuleStatus = "rejected" RuleStatusExpired RuleStatus = "expired" )
func (RuleStatus) IsValid ¶
func (s RuleStatus) IsValid() bool
IsValid checks if the rule status is valid.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides business logic for suppression rules.
func NewService ¶
func NewService(repo Repository, log *logger.Logger) *Service
NewService creates a new suppression service.
func (*Service) ApplySuppression ¶
ApplySuppression applies a suppression rule to a finding.
func (*Service) ApproveRule ¶
ApproveRule approves a pending suppression rule.
func (*Service) CheckSuppression ¶
func (s *Service) CheckSuppression(ctx context.Context, tenantID shared.ID, match FindingMatch) ([]*Rule, error)
CheckSuppression checks if a finding matches any active suppression rules.
func (*Service) CreateRule ¶
CreateRule creates a new suppression rule.
func (*Service) DeleteRule ¶
DeleteRule deletes a suppression rule.
func (*Service) ExpireRules ¶
ExpireRules expires all rules past their expiration date.
func (*Service) ListActiveRules ¶
ListActiveRules lists all active (approved, not expired) rules.
func (*Service) ListPendingRules ¶
ListPendingRules lists all pending rules awaiting approval.
func (*Service) ListRules ¶
func (s *Service) ListRules(ctx context.Context, tenantID shared.ID, filter RuleFilter) ([]*Rule, error)
ListRules lists suppression rules for a tenant.
func (*Service) RejectRule ¶
RejectRule rejects a pending suppression rule.
func (*Service) UpdateRule ¶
UpdateRule updates an existing suppression rule. Only pending rules can be updated.
type SuppressionType ¶
type SuppressionType string
SuppressionType represents the type of suppression.
const ( SuppressionTypeFalsePositive SuppressionType = "false_positive" SuppressionTypeAcceptedRisk SuppressionType = "accepted_risk" SuppressionTypeWontFix SuppressionType = "wont_fix" )
func (SuppressionType) IsValid ¶
func (t SuppressionType) IsValid() bool
IsValid checks if the suppression type is valid.
type UpdateRuleInput ¶
type UpdateRuleInput struct {
TenantID shared.ID
RuleID shared.ID
Name *string
Description *string
RuleIDPat *string // Rule ID pattern
ToolName *string
PathPattern *string
ExpiresAt *string // ISO8601 format, empty string to clear
UpdatedBy shared.ID
}
UpdateRuleInput contains input for updating a suppression rule.