mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
86b8a6d0f3
* feat: add audit warning to policy spec Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * feat: emit warning when audit warning is set Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * feat: add audit warn to policy cache Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * feat: add warnings for validation Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * feat: add warnings for mutation Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * feat: add chainsaw test Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * feat: add more chainsaw test Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * chore: fix ci Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * feat: rename field to emit warning Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: tests Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: unit tests Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: validate tests Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: cleanup Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> * fix: remove validation action failure fro mutation unit tests Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> --------- Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com> Co-authored-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
39 lines
998 B
Go
39 lines
998 B
Go
package api
|
|
|
|
// PolicyResponse policy application response
|
|
type PolicyResponse struct {
|
|
// stats contains policy statistics
|
|
stats PolicyStats
|
|
// Rules contains policy rules responses
|
|
Rules []RuleResponse
|
|
// emitWarning controls if rule responses are returned in warning header
|
|
emitWarning bool
|
|
}
|
|
|
|
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()
|
|
}
|