1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 15:37:19 +00:00
kyverno/pkg/engine/api/policyresponse.go
Charles-Edouard Brétéché b82c1bc386
refactor: policy response (#6877)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-04-12 16:20:42 +00:00

37 lines
906 B
Go

package api
// PolicyResponse policy application response
type PolicyResponse struct {
// stats contains policy statistics
stats PolicyStats
// Rules contains policy rules responses
Rules []RuleResponse
}
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 {
pr.stats.rulesAppliedCount++
} else if status == RuleStatusError {
pr.stats.rulesErrorCount++
}
}
}
func NewPolicyResponse() PolicyResponse {
return PolicyResponse{}
}
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()
}