sla

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("SLA policy not found")
	ErrAlreadyExists = errors.New("SLA policy already exists")
)
View Source
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".

View Source
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

func AlreadyExistsError(name string) error

AlreadyExistsError returns a formatted already exists error.

func NotFoundError

func NotFoundError(id string) error

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

func NewDefaultPolicy(tenantID shared.ID) (*Policy, error)

NewDefaultPolicy creates a new default SLA Policy for a tenant.

func NewPolicy

func NewPolicy(
	tenantID shared.ID,
	name string,
) (*Policy, error)

NewPolicy creates a new SLA Policy with default values.

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) Activate

func (p *Policy) Activate()

func (*Policy) AssetID

func (p *Policy) AssetID() *shared.ID

func (*Policy) CalculateDeadline

func (p *Policy) CalculateDeadline(severity string, detectedAt time.Time) time.Time

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) CreatedAt

func (p *Policy) CreatedAt() time.Time

func (*Policy) CriticalDays

func (p *Policy) CriticalDays() int

func (*Policy) Deactivate

func (p *Policy) Deactivate()

func (*Policy) Description

func (p *Policy) Description() string

func (*Policy) DisableEscalation

func (p *Policy) DisableEscalation()

func (*Policy) EnableEscalation

func (p *Policy) EnableEscalation(config map[string]any)

func (*Policy) EscalationConfig

func (p *Policy) EscalationConfig() map[string]any

func (*Policy) EscalationEnabled

func (p *Policy) EscalationEnabled() bool

func (*Policy) GetDaysForPriorityClass added in v0.2.0

func (p *Policy) GetDaysForPriorityClass(priorityClass string) int

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

func (p *Policy) GetDaysForSeverity(severity string) int

GetDaysForSeverity returns the remediation days for a given severity.

func (*Policy) HighDays

func (p *Policy) HighDays() int

func (*Policy) ID

func (p *Policy) ID() shared.ID

func (*Policy) InfoDays

func (p *Policy) InfoDays() int

func (*Policy) IsActive

func (p *Policy) IsActive() bool

func (*Policy) IsAssetSpecific

func (p *Policy) IsAssetSpecific() bool

IsAssetSpecific checks if this policy is for a specific asset.

func (*Policy) IsDefault

func (p *Policy) IsDefault() bool

func (*Policy) LowDays

func (p *Policy) LowDays() int

func (*Policy) MediumDays

func (p *Policy) MediumDays() int

func (*Policy) Name

func (p *Policy) Name() string

func (*Policy) P0Days added in v0.2.0

func (p *Policy) P0Days() int

P0Days returns the priority-class P0 SLA days.

func (*Policy) P1Days added in v0.2.0

func (p *Policy) P1Days() int

P1Days returns the priority-class P1 SLA days.

func (*Policy) P2Days added in v0.2.0

func (p *Policy) P2Days() int

P2Days returns the priority-class P2 SLA days.

func (*Policy) P3Days added in v0.2.0

func (p *Policy) P3Days() int

P3Days returns the priority-class P3 SLA days.

func (*Policy) SetAssetID

func (p *Policy) SetAssetID(assetID shared.ID)

func (*Policy) SetDefault

func (p *Policy) SetDefault(isDefault bool)

func (*Policy) SetWarningThreshold

func (p *Policy) SetWarningThreshold(percent int) error

func (*Policy) TenantID

func (p *Policy) TenantID() shared.ID

func (*Policy) UpdateDescription

func (p *Policy) UpdateDescription(description string)

func (*Policy) UpdateName

func (p *Policy) UpdateName(name string) error

func (*Policy) UpdateSLADays

func (p *Policy) UpdateSLADays(critical, high, medium, low, info int) error

func (*Policy) UpdatedAt

func (p *Policy) UpdatedAt() time.Time

func (*Policy) WarningThresholdPct

func (p *Policy) WarningThresholdPct() int

func (*Policy) WithPriorityDays added in v0.2.0

func (p *Policy) WithPriorityDays(p0, p1, p2, p3 int) *Policy

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.

Jump to

Keyboard shortcuts

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