Documentation
¶
Overview ¶
Package costpolicy provides cost policy enforcement
Index ¶
- type ActionType
- type EnforcementEngine
- func (e *EnforcementEngine) AddPolicy(policy *Policy) error
- func (e *EnforcementEngine) CheckPolicy(user, team, model string, cost float64) (*PolicyDecision, error)
- func (e *EnforcementEngine) GetViolations(filter ViolationFilter) []PolicyViolation
- func (e *EnforcementEngine) RemovePolicy(id string)
- type Notification
- type Policy
- type PolicyDecision
- type PolicyRule
- type PolicyViolation
- type RuleAction
- type RuleCondition
- type RuleType
- type ViolationFilter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionType ¶
type ActionType string
ActionType represents the type of action
const ( ActionTypeAllow ActionType = "allow" ActionTypeDeny ActionType = "deny" ActionTypeWarn ActionType = "warn" ActionTypeNotify ActionType = "notify" ActionTypeShutdown ActionType = "shutdown" ActionTypeLimit ActionType = "limit" )
type EnforcementEngine ¶
type EnforcementEngine struct {
// contains filtered or unexported fields
}
EnforcementEngine enforces cost policies
func NewEnforcementEngine ¶
func NewEnforcementEngine() *EnforcementEngine
NewEnforcementEngine creates a new enforcement engine
func (*EnforcementEngine) AddPolicy ¶
func (e *EnforcementEngine) AddPolicy(policy *Policy) error
AddPolicy adds a policy
func (*EnforcementEngine) CheckPolicy ¶
func (e *EnforcementEngine) CheckPolicy(user, team, model string, cost float64) (*PolicyDecision, error)
CheckPolicy checks if an action violates any policy
func (*EnforcementEngine) GetViolations ¶
func (e *EnforcementEngine) GetViolations(filter ViolationFilter) []PolicyViolation
GetViolations returns policy violations
func (*EnforcementEngine) RemovePolicy ¶
func (e *EnforcementEngine) RemovePolicy(id string)
RemovePolicy removes a policy
type Notification ¶
Notification represents a notification
type Policy ¶
type Policy struct {
ID string
Name string
Description string
Enabled bool
Rules []PolicyRule
CreatedAt time.Time
UpdatedAt time.Time
}
Policy represents a cost policy
func StandardPolicies ¶
func StandardPolicies() []*Policy
StandardPolicies returns standard cost policies
type PolicyDecision ¶
type PolicyDecision struct {
Allowed bool
Reason string
PolicyID string
RuleID string
ShouldShutdown bool
Warnings []string
Notifications []Notification
}
PolicyDecision represents a policy decision
type PolicyRule ¶
type PolicyRule struct {
ID string
Type RuleType
Condition RuleCondition
Action RuleAction
Priority int
Description string
}
PolicyRule represents a policy rule
type PolicyViolation ¶
type PolicyViolation struct {
ID string
PolicyID string
RuleID string
User string
Team string
Action string
Cost float64
Timestamp time.Time
Status string
}
PolicyViolation represents a policy violation
type RuleAction ¶
type RuleAction struct {
Type ActionType
Message string
Recipients []string
Limit float64
Shutdown bool
}
RuleAction represents a rule action
type RuleCondition ¶
type RuleCondition struct {
Metric string
Operator string
Value float64
TimeRange string
Team string
Model string
}
RuleCondition represents a rule condition
type ViolationFilter ¶
type ViolationFilter struct {
PolicyID string
User string
Team string
Status string
FromDate time.Time
ToDate time.Time
}
ViolationFilter filters violations
func (ViolationFilter) Matches ¶
func (f ViolationFilter) Matches(v PolicyViolation) bool
Matches checks if a violation matches the filter