Documentation
¶
Index ¶
- Variables
- func AlreadyExistsError(name string) error
- func NotFoundError(id string) error
- type Policy
- func (p *Policy) Activate()
- func (p *Policy) AssetID() *shared.ID
- func (p *Policy) CalculateDeadline(severity string, detectedAt time.Time) time.Time
- func (p *Policy) CalculateDeadlineFor(priorityClass, severity string, detectedAt time.Time) time.Time
- func (p *Policy) CreatedAt() time.Time
- func (p *Policy) CriticalDays() int
- func (p *Policy) Deactivate()
- func (p *Policy) Description() string
- func (p *Policy) DisableEscalation()
- func (p *Policy) EnableEscalation(config map[string]any)
- func (p *Policy) EscalationConfig() map[string]any
- func (p *Policy) EscalationEnabled() bool
- func (p *Policy) GetDaysForPriorityClass(priorityClass string) int
- func (p *Policy) GetDaysForSeverity(severity string) int
- func (p *Policy) HighDays() int
- func (p *Policy) ID() shared.ID
- func (p *Policy) InfoDays() int
- func (p *Policy) IsActive() bool
- func (p *Policy) IsAssetSpecific() bool
- func (p *Policy) IsDefault() bool
- func (p *Policy) LowDays() int
- func (p *Policy) MediumDays() int
- func (p *Policy) Name() string
- func (p *Policy) P0Days() int
- func (p *Policy) P1Days() int
- func (p *Policy) P2Days() int
- func (p *Policy) P3Days() int
- func (p *Policy) SetAssetID(assetID shared.ID)
- func (p *Policy) SetDefault(isDefault bool)
- func (p *Policy) SetWarningThreshold(percent int) error
- func (p *Policy) TenantID() shared.ID
- func (p *Policy) UpdateDescription(description string)
- func (p *Policy) UpdateName(name string) error
- func (p *Policy) UpdateSLADays(critical, high, medium, low, info int) error
- func (p *Policy) UpdatedAt() time.Time
- func (p *Policy) WarningThresholdPct() int
- func (p *Policy) WithPriorityDays(p0, p1, p2, p3 int) *Policy
- type Repository
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("SLA policy not found") ErrAlreadyExists = errors.New("SLA policy already exists") )
var DefaultPriorityDays = map[string]int{
"P0": 2,
"P1": 5,
"P2": 15,
"P3": 30,
}
DefaultPriorityDays is the default remediation window per CTEM priority class. These are tighter than severity-based defaults because priority class is supposed to express "how much does this matter now given the business context + exploit landscape".
var DefaultSLADays = map[string]int{
"critical": 2,
"high": 15,
"medium": 30,
"low": 60,
"info": 90,
}
DefaultSLADays contains the default remediation days per severity.
Functions ¶
func AlreadyExistsError ¶
AlreadyExistsError returns a formatted already exists error.
func NotFoundError ¶
NotFoundError returns a formatted not found error.
Types ¶
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy represents an SLA policy for findings remediation.
func NewDefaultPolicy ¶
NewDefaultPolicy creates a new default SLA Policy for a tenant.
func Reconstitute ¶
func Reconstitute( id shared.ID, tenantID shared.ID, assetID *shared.ID, name string, description string, isDefault bool, criticalDays int, highDays int, mediumDays int, lowDays int, infoDays int, warningThresholdPct int, escalationEnabled bool, escalationConfig map[string]any, isActive bool, createdAt time.Time, updatedAt time.Time, ) *Policy
Reconstitute recreates a Policy from persistence.
func (*Policy) CalculateDeadline ¶
CalculateDeadline calculates the SLA deadline using severity only. Retained for backward compatibility; prefer CalculateDeadlineFor for priority-aware deadlines.
func (*Policy) CalculateDeadlineFor ¶ added in v0.2.0
func (p *Policy) CalculateDeadlineFor(priorityClass, severity string, detectedAt time.Time) time.Time
CalculateDeadlineFor computes the SLA deadline honouring CTEM priority class first, falling back to severity when the priority class is empty or unknown (legacy findings without a class yet).
F3: this is the single entry point that downstream services SHOULD use. It closes the fake-signal gap where p0..p3 days existed in the schema but were not read.
func (*Policy) CriticalDays ¶
func (*Policy) Deactivate ¶
func (p *Policy) Deactivate()
func (*Policy) Description ¶
func (*Policy) DisableEscalation ¶
func (p *Policy) DisableEscalation()
func (*Policy) EnableEscalation ¶
func (*Policy) EscalationConfig ¶
func (*Policy) EscalationEnabled ¶
func (*Policy) GetDaysForPriorityClass ¶ added in v0.2.0
GetDaysForPriorityClass returns the remediation days for a CTEM priority class (P0..P3). Returns 0 for unrecognised values so the caller can fall back to severity-based days.
func (*Policy) GetDaysForSeverity ¶
GetDaysForSeverity returns the remediation days for a given severity.
func (*Policy) IsAssetSpecific ¶
IsAssetSpecific checks if this policy is for a specific asset.
func (*Policy) MediumDays ¶
func (*Policy) SetAssetID ¶
func (*Policy) SetDefault ¶
func (*Policy) SetWarningThreshold ¶
func (*Policy) UpdateDescription ¶
func (*Policy) UpdateName ¶
func (*Policy) UpdateSLADays ¶
func (*Policy) WarningThresholdPct ¶
func (*Policy) WithPriorityDays ¶ added in v0.2.0
WithPriorityDays attaches priority-class SLA days to a reconstituted Policy. Zero values keep the default — a persisted value of 0 is treated as "inherit default" so the column can be safely added to existing rows without breaking anything.
type Repository ¶
type Repository interface {
// Create persists a new SLA policy.
Create(ctx context.Context, policy *Policy) error
// GetByID retrieves a policy by ID.
GetByID(ctx context.Context, id shared.ID) (*Policy, error)
// GetByTenantAndID retrieves a policy by tenant and ID.
GetByTenantAndID(ctx context.Context, tenantID, id shared.ID) (*Policy, error)
// GetByAsset retrieves the policy for a specific asset.
// Returns the asset-specific policy if exists, otherwise the tenant default.
GetByAsset(ctx context.Context, tenantID, assetID shared.ID) (*Policy, error)
// GetTenantDefault retrieves the default policy for a tenant.
GetTenantDefault(ctx context.Context, tenantID shared.ID) (*Policy, error)
// Update updates an existing policy.
Update(ctx context.Context, policy *Policy) error
// Delete removes a policy.
Delete(ctx context.Context, id shared.ID) error
// ListByTenant returns all policies for a tenant.
ListByTenant(ctx context.Context, tenantID shared.ID) ([]*Policy, error)
// ExistsByAsset checks if an asset-specific policy exists.
ExistsByAsset(ctx context.Context, assetID shared.ID) (bool, error)
}
Repository defines the SLA policy repository interface.