Documentation
¶
Index ¶
- type Action
- type Condition
- type EvaluationResult
- type Rule
- type RuleEngine
- func (e *RuleEngine) AddRule(rule Rule)
- func (e *RuleEngine) Evaluate(ctx context.Context, br *analysis.EnhancedBlastRadius) (*EvaluationResult, error)
- func (e *RuleEngine) LoadDefaultRules()
- func (e *RuleEngine) LoadRules(path string) error
- func (e *RuleEngine) Rules() []Rule
- func (e *RuleEngine) SaveRules(path string) error
- type RuleResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Condition ¶
type Condition struct {
// CallerCountGT matches if caller count is greater than this.
CallerCountGT *int `yaml:"caller_count_gt" json:"caller_count_gt,omitempty"`
// CallerCountGTE matches if caller count is >= this.
CallerCountGTE *int `yaml:"caller_count_gte" json:"caller_count_gte,omitempty"`
// SecurityPathIn matches if any security path is in this list.
SecurityPathIn []string `yaml:"security_path_in" json:"security_path_in,omitempty"`
// PackageMatch matches if package path matches this regex.
PackageMatch *string `yaml:"package_match" json:"package_match,omitempty"`
// SymbolMatch matches if symbol ID matches this regex.
SymbolMatch *string `yaml:"symbol_match" json:"symbol_match,omitempty"`
// ChurnLevelIn matches if churn level is in this list.
ChurnLevelIn []string `yaml:"churn_level_in" json:"churn_level_in,omitempty"`
// RiskLevelIn matches if risk level is in this list.
RiskLevelIn []string `yaml:"risk_level_in" json:"risk_level_in,omitempty"`
// HasDeadCallers matches if there are dead callers.
HasDeadCallers *bool `yaml:"has_dead_callers" json:"has_dead_callers,omitempty"`
// TransitiveCountGT matches if transitive count is greater than this.
TransitiveCountGT *int `yaml:"transitive_count_gt" json:"transitive_count_gt,omitempty"`
// CoverageRiskIn matches if coverage risk is in this list.
CoverageRiskIn []string `yaml:"coverage_risk_in" json:"coverage_risk_in,omitempty"`
// ConfidenceLT matches if confidence is less than this.
ConfidenceLT *int `yaml:"confidence_lt" json:"confidence_lt,omitempty"`
// And combines multiple conditions (all must match).
And []Condition `yaml:"and" json:"and,omitempty"`
// Or combines multiple conditions (any must match).
Or []Condition `yaml:"or" json:"or,omitempty"`
// Not negates the condition.
Not *Condition `yaml:"not" json:"not,omitempty"`
}
Condition specifies when a rule matches.
type EvaluationResult ¶
type EvaluationResult struct {
// Results are the individual rule results.
Results []RuleResult `json:"results"`
// Blocked indicates if any BLOCK rule matched.
Blocked bool `json:"blocked"`
// BlockReason explains why it's blocked.
BlockReason string `json:"block_reason,omitempty"`
// RequiresReview indicates if review is required.
RequiresReview bool `json:"requires_review"`
// Warnings are warning messages.
Warnings []string `json:"warnings,omitempty"`
// Notifications are notification messages.
Notifications []string `json:"notifications,omitempty"`
}
EvaluationResult contains all rule evaluation results.
type Rule ¶
type Rule struct {
// Name is the rule identifier.
Name string `yaml:"name" json:"name"`
// Description explains what the rule checks.
Description string `yaml:"description" json:"description,omitempty"`
// Enabled indicates if the rule is active.
Enabled bool `yaml:"enabled" json:"enabled"`
// Condition is the condition that triggers this rule.
Condition Condition `yaml:"condition" json:"condition"`
// Action is what happens when the rule matches.
Action Action `yaml:"action" json:"action"`
// Severity is the severity level when triggered.
Severity string `yaml:"severity" json:"severity,omitempty"`
// Message is the message shown when the rule triggers.
Message string `yaml:"message" json:"message,omitempty"`
// Exemptions are patterns that exempt matching symbols.
Exemptions []string `yaml:"exemptions" json:"exemptions,omitempty"`
}
Rule defines a custom risk rule.
type RuleEngine ¶
type RuleEngine struct {
// contains filtered or unexported fields
}
RuleEngine evaluates custom rules against blast radius results.
Description ¶
Allows organizations to define custom risk rules that trigger actions such as blocking, warnings, or review requirements. Rules are loaded from YAML configuration files.
Thread Safety ¶
Safe for concurrent use after construction.
func (*RuleEngine) AddRule ¶
func (e *RuleEngine) AddRule(rule Rule)
AddRule adds a rule programmatically.
func (*RuleEngine) Evaluate ¶
func (e *RuleEngine) Evaluate(ctx context.Context, br *analysis.EnhancedBlastRadius) (*EvaluationResult, error)
Evaluate evaluates all rules against a blast radius result.
Inputs ¶
- ctx: Context for cancellation.
- br: The blast radius result to evaluate.
Outputs ¶
- *EvaluationResult: The evaluation result.
- error: Non-nil on failure.
func (*RuleEngine) LoadDefaultRules ¶
func (e *RuleEngine) LoadDefaultRules()
LoadDefaultRules loads sensible default rules.
func (*RuleEngine) LoadRules ¶
func (e *RuleEngine) LoadRules(path string) error
LoadRules loads rules from a YAML file.
Inputs ¶
- path: Path to the rules file (e.g., .aleutian/rules.yml).
Outputs ¶
- error: Non-nil if loading failed.
func (*RuleEngine) SaveRules ¶
func (e *RuleEngine) SaveRules(path string) error
SaveRules saves rules to a YAML file.
type RuleResult ¶
type RuleResult struct {
// Rule is the rule that was evaluated.
Rule *Rule `json:"rule"`
// Matched indicates if the rule matched.
Matched bool `json:"matched"`
// Action is the action to take.
Action Action `json:"action"`
// Message is the result message.
Message string `json:"message"`
// MatchDetails explains why the rule matched.
MatchDetails []string `json:"match_details,omitempty"`
}
RuleResult represents the result of evaluating a rule.