2022-04-05 14:30:00 +02:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2022-05-17 13:12:43 +02:00
|
|
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
2022-04-05 14:30:00 +02:00
|
|
|
"github.com/kyverno/kyverno/pkg/engine/response"
|
|
|
|
)
|
|
|
|
|
|
|
|
// IsResponseSuccessful return true if all responses are successful
|
|
|
|
func IsResponseSuccessful(engineReponses []*response.EngineResponse) bool {
|
|
|
|
for _, er := range engineReponses {
|
|
|
|
if !er.IsSuccessful() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-08-02 07:54:02 -07:00
|
|
|
// BlockRequest returns true when:
|
|
|
|
// 1. a policy fails (i.e. creates a violation) and validationFailureAction is set to 'enforce'
|
|
|
|
// 2. a policy has a processing error and failurePolicy is set to 'Fail`
|
|
|
|
func BlockRequest(er *response.EngineResponse, failurePolicy kyvernov1.FailurePolicyType) bool {
|
2022-11-01 09:56:52 +00:00
|
|
|
if er.IsFailed() && er.GetValidationFailureAction().Enforce() {
|
2022-08-02 07:54:02 -07:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if er.IsError() && failurePolicy == kyvernov1.Fail {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2022-04-05 14:30:00 +02:00
|
|
|
}
|