|
| 1 | +# Generated using https://github.com/RedHatQE/openshift-python-wrapper/blob/main/scripts/resource/README.md |
| 2 | + |
| 3 | + |
| 4 | +from typing import Any |
| 5 | + |
| 6 | +from ocp_resources.resource import Resource |
| 7 | + |
| 8 | + |
| 9 | +class ValidatingAdmissionPolicy(Resource): |
| 10 | + """ |
| 11 | + ValidatingAdmissionPolicy describes the definition of an admission validation policy that accepts or rejects an object without changing it. |
| 12 | + """ |
| 13 | + |
| 14 | + api_group: str = Resource.ApiGroup.ADMISSIONREGISTRATION_K8S_IO |
| 15 | + |
| 16 | + def __init__( |
| 17 | + self, |
| 18 | + audit_annotations: list[Any] | None = None, |
| 19 | + failure_policy: str | None = None, |
| 20 | + match_conditions: list[Any] | None = None, |
| 21 | + match_constraints: dict[str, Any] | None = None, |
| 22 | + param_kind: dict[str, Any] | None = None, |
| 23 | + validations: list[Any] | None = None, |
| 24 | + variables: list[Any] | None = None, |
| 25 | + **kwargs: Any, |
| 26 | + ) -> None: |
| 27 | + r""" |
| 28 | + Args: |
| 29 | + audit_annotations (list[Any]): auditAnnotations contains CEL expressions which are used to produce |
| 30 | + audit annotations for the audit event of the API request. |
| 31 | + validations and auditAnnotations may not both be empty; a least |
| 32 | + one of validations or auditAnnotations is required. |
| 33 | +
|
| 34 | + failure_policy (str): failurePolicy defines how to handle failures for the admission policy. |
| 35 | + Failures can occur from CEL expression parse errors, type check |
| 36 | + errors, runtime errors and invalid or mis-configured policy |
| 37 | + definitions or bindings. A policy is invalid if spec.paramKind |
| 38 | + refers to a non-existent Kind. A binding is invalid if |
| 39 | + spec.paramRef.name refers to a non-existent resource. |
| 40 | + failurePolicy does not define how validations that evaluate to |
| 41 | + false are handled. When failurePolicy is set to Fail, |
| 42 | + ValidatingAdmissionPolicyBinding validationActions define how |
| 43 | + failures are enforced. Allowed values are Ignore or Fail. |
| 44 | + Defaults to Fail. Possible enum values: - `"Fail"` means that an |
| 45 | + error calling the webhook causes the admission to fail. - |
| 46 | + `"Ignore"` means that an error calling the webhook is ignored. |
| 47 | +
|
| 48 | + match_conditions (list[Any]): MatchConditions is a list of conditions that must be met for a request |
| 49 | + to be validated. Match conditions filter requests that have |
| 50 | + already been matched by the rules, namespaceSelector, and |
| 51 | + objectSelector. An empty list of matchConditions matches all |
| 52 | + requests. There are a maximum of 64 match conditions allowed. If |
| 53 | + a parameter object is provided, it can be accessed via the |
| 54 | + `params` handle in the same manner as validation expressions. The |
| 55 | + exact matching logic is (in order): 1. If ANY matchCondition |
| 56 | + evaluates to FALSE, the policy is skipped. 2. If ALL |
| 57 | + matchConditions evaluate to TRUE, the policy is evaluated. 3. If |
| 58 | + any matchCondition evaluates to an error (but none are FALSE): |
| 59 | + - If failurePolicy=Fail, reject the request - If |
| 60 | + failurePolicy=Ignore, the policy is skipped |
| 61 | +
|
| 62 | + match_constraints (dict[str, Any]): MatchResources decides whether to run the admission control policy on |
| 63 | + an object based on whether it meets the match criteria. The |
| 64 | + exclude rules take precedence over include rules (if a resource |
| 65 | + matches both, it is excluded) |
| 66 | +
|
| 67 | + param_kind (dict[str, Any]): ParamKind is a tuple of Group Kind and Version. |
| 68 | +
|
| 69 | + validations (list[Any]): Validations contain CEL expressions which is used to apply the |
| 70 | + validation. Validations and AuditAnnotations may not both be |
| 71 | + empty; a minimum of one Validations or AuditAnnotations is |
| 72 | + required. |
| 73 | +
|
| 74 | + variables (list[Any]): Variables contain definitions of variables that can be used in |
| 75 | + composition of other expressions. Each variable is defined as a |
| 76 | + named CEL expression. The variables defined here will be available |
| 77 | + under `variables` in other expressions of the policy except |
| 78 | + MatchConditions because MatchConditions are evaluated before the |
| 79 | + rest of the policy. The expression of a variable can refer to |
| 80 | + other variables defined earlier in the list but not those after. |
| 81 | + Thus, Variables must be sorted by the order of first appearance |
| 82 | + and acyclic. |
| 83 | +
|
| 84 | + """ |
| 85 | + super().__init__(**kwargs) |
| 86 | + |
| 87 | + self.audit_annotations = audit_annotations |
| 88 | + self.failure_policy = failure_policy |
| 89 | + self.match_conditions = match_conditions |
| 90 | + self.match_constraints = match_constraints |
| 91 | + self.param_kind = param_kind |
| 92 | + self.validations = validations |
| 93 | + self.variables = variables |
| 94 | + |
| 95 | + def to_dict(self) -> None: |
| 96 | + |
| 97 | + super().to_dict() |
| 98 | + |
| 99 | + if not self.kind_dict and not self.yaml_file: |
| 100 | + self.res["spec"] = {} |
| 101 | + _spec = self.res["spec"] |
| 102 | + |
| 103 | + if self.audit_annotations is not None: |
| 104 | + _spec["auditAnnotations"] = self.audit_annotations |
| 105 | + |
| 106 | + if self.failure_policy is not None: |
| 107 | + _spec["failurePolicy"] = self.failure_policy |
| 108 | + |
| 109 | + if self.match_conditions is not None: |
| 110 | + _spec["matchConditions"] = self.match_conditions |
| 111 | + |
| 112 | + if self.match_constraints is not None: |
| 113 | + _spec["matchConstraints"] = self.match_constraints |
| 114 | + |
| 115 | + if self.param_kind is not None: |
| 116 | + _spec["paramKind"] = self.param_kind |
| 117 | + |
| 118 | + if self.validations is not None: |
| 119 | + _spec["validations"] = self.validations |
| 120 | + |
| 121 | + if self.variables is not None: |
| 122 | + _spec["variables"] = self.variables |
| 123 | + |
| 124 | + # End of generated code |
0 commit comments