2023-01-30 14:49:44 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
// PolicyResponse policy application response
|
|
|
|
type PolicyResponse struct {
|
2023-04-12 16:20:42 +00:00
|
|
|
// stats contains policy statistics
|
|
|
|
stats PolicyStats
|
2023-01-30 14:49:44 +00:00
|
|
|
// Rules contains policy rules responses
|
|
|
|
Rules []RuleResponse
|
2024-09-05 10:02:00 +00:00
|
|
|
// emitWarning controls if rule responses are returned in warning header
|
|
|
|
emitWarning bool
|
2023-01-30 14:49:44 +00:00
|
|
|
}
|
2023-03-30 11:59:32 +00:00
|
|
|
|
2023-04-05 22:55:42 +00:00
|
|
|
func (pr *PolicyResponse) Add(stats ExecutionStats, responses ...RuleResponse) {
|
|
|
|
for _, response := range responses {
|
|
|
|
pr.Rules = append(pr.Rules, response.WithStats(stats))
|
|
|
|
status := response.Status()
|
|
|
|
if status == RuleStatusPass || status == RuleStatusFail {
|
2023-04-12 16:20:42 +00:00
|
|
|
pr.stats.rulesAppliedCount++
|
2023-04-05 22:55:42 +00:00
|
|
|
} else if status == RuleStatusError {
|
2023-04-12 16:20:42 +00:00
|
|
|
pr.stats.rulesErrorCount++
|
2023-04-05 22:55:42 +00:00
|
|
|
}
|
2023-03-30 11:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPolicyResponse() PolicyResponse {
|
|
|
|
return PolicyResponse{}
|
|
|
|
}
|
2023-04-12 16:20:42 +00:00
|
|
|
|
|
|
|
func (pr *PolicyResponse) Stats() PolicyStats {
|
|
|
|
return pr.stats
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pr *PolicyResponse) RulesAppliedCount() int {
|
|
|
|
return pr.stats.RulesAppliedCount()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pr *PolicyResponse) RulesErrorCount() int {
|
|
|
|
return pr.stats.RulesErrorCount()
|
|
|
|
}
|