sla

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: GPL-3.0 Imports: 5 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

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 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 for a finding.

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

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