costpolicy

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package costpolicy provides cost policy enforcement

Index

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

type Notification struct {
	Recipients []string
	Message    string
}

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 RuleType

type RuleType string

RuleType represents the type of rule

const (
	RuleTypeBudgetLimit   RuleType = "budget_limit"
	RuleTypeModelRestrict RuleType = "model_restrict"
	RuleTypeRateLimit     RuleType = "rate_limit"
	RuleTypeApproval      RuleType = "approval_required"
	RuleTypeNotification  RuleType = "notify"
	RuleTypeAutoShutdown  RuleType = "auto_shutdown"
)

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

Jump to

Keyboard shortcuts

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