2023-01-30 15:49:44 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
// PolicyResponse policy application response
|
|
|
|
type PolicyResponse struct {
|
2023-02-10 20:35:55 +01:00
|
|
|
// Stats contains policy statistics
|
|
|
|
Stats PolicyStats
|
2023-01-30 15:49:44 +01:00
|
|
|
// Rules contains policy rules responses
|
|
|
|
Rules []RuleResponse
|
|
|
|
}
|
2023-03-30 13:59:32 +02:00
|
|
|
|
2023-04-06 00:55:42 +02: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 {
|
|
|
|
pr.Stats.RulesAppliedCount++
|
|
|
|
} else if status == RuleStatusError {
|
|
|
|
pr.Stats.RulesErrorCount++
|
|
|
|
}
|
2023-03-30 13:59:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPolicyResponse() PolicyResponse {
|
|
|
|
return PolicyResponse{}
|
|
|
|
}
|