1// Generated from definition io.k8s.api.admissionregistration.v1beta1.MatchCondition
23/// MatchCondition represents a condition which must be fulfilled for a request to be sent to a webhook.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct MatchCondition {
6/// Expression represents the expression which will be evaluated by CEL. Must evaluate to bool. CEL expressions have access to the contents of the AdmissionRequest and Authorizer, organized into CEL variables:
7 ///
8 /// 'object' - The object from the incoming request. The value is null for DELETE requests. 'oldObject' - The existing object. The value is null for CREATE requests. 'request' - Attributes of the admission request(/pkg/apis/admission/types.go#AdmissionRequest). 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request.
9 /// See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz
10 /// 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the
11 /// request resource.
12 /// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/
13 ///
14 /// Required.
15pub expression: String,
1617/// Name is an identifier for this match condition, used for strategic merging of MatchConditions, as well as providing an identifier for logging purposes. A good name should be descriptive of the associated expression. Name must be a qualified name consisting of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '(\[A-Za-z0-9\]\[-A-Za-z0-9_.\]*)?\[A-Za-z0-9\]') with an optional DNS subdomain prefix and '/' (e.g. 'example.com/MyName')
18 ///
19 /// Required.
20pub name: String,
21}
2223impl crate::DeepMerge for MatchCondition {
24fn merge_from(&mut self, other: Self) {
25crate::DeepMerge::merge_from(&mut self.expression, other.expression);
26crate::DeepMerge::merge_from(&mut self.name, other.name);
27 }
28}
2930impl<'de> crate::serde::Deserialize<'de> for MatchCondition {
31fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
32#[allow(non_camel_case_types)]
33enum Field {
34 Key_expression,
35 Key_name,
36 Other,
37 }
3839impl<'de> crate::serde::Deserialize<'de> for Field {
40fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41struct Visitor;
4243impl<'de> crate::serde::de::Visitor<'de> for Visitor {
44type Value = Field;
4546fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 f.write_str("field identifier")
48 }
4950fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51Ok(match v {
52"expression" => Field::Key_expression,
53"name" => Field::Key_name,
54_ => Field::Other,
55 })
56 }
57 }
5859 deserializer.deserialize_identifier(Visitor)
60 }
61 }
6263struct Visitor;
6465impl<'de> crate::serde::de::Visitor<'de> for Visitor {
66type Value = MatchCondition;
6768fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69 f.write_str("MatchCondition")
70 }
7172fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
73let mut value_expression: Option<String> = None;
74let mut value_name: Option<String> = None;
7576while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
77match key {
78 Field::Key_expression => value_expression = crate::serde::de::MapAccess::next_value(&mut map)?,
79 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
80 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
81 }
82 }
8384Ok(MatchCondition {
85 expression: value_expression.unwrap_or_default(),
86 name: value_name.unwrap_or_default(),
87 })
88 }
89 }
9091 deserializer.deserialize_struct(
92"MatchCondition",
93&[
94"expression",
95"name",
96 ],
97 Visitor,
98 )
99 }
100}
101102impl crate::serde::Serialize for MatchCondition {
103fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104let mut state = serializer.serialize_struct(
105"MatchCondition",
1062,
107 )?;
108crate::serde::ser::SerializeStruct::serialize_field(&mut state, "expression", &self.expression)?;
109crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
110crate::serde::ser::SerializeStruct::end(state)
111 }
112}
113114#[cfg(feature = "schemars")]
115impl crate::schemars::JsonSchema for MatchCondition {
116fn schema_name() -> String {
117"io.k8s.api.admissionregistration.v1beta1.MatchCondition".to_owned()
118 }
119120fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
121crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
122 metadata: Some(Box::new(crate::schemars::schema::Metadata {
123 description: Some("MatchCondition represents a condition which must be fulfilled for a request to be sent to a webhook.".to_owned()),
124 ..Default::default()
125 })),
126 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
127 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
128 properties: [
129 (
130"expression".to_owned(),
131crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
132 metadata: Some(Box::new(crate::schemars::schema::Metadata {
133 description: Some("Expression represents the expression which will be evaluated by CEL. Must evaluate to bool. CEL expressions have access to the contents of the AdmissionRequest and Authorizer, organized into CEL variables:\n\n'object' - The object from the incoming request. The value is null for DELETE requests. 'oldObject' - The existing object. The value is null for CREATE requests. 'request' - Attributes of the admission request(/pkg/apis/admission/types.go#AdmissionRequest). 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request.\n See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz\n'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the\n request resource.\nDocumentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/\n\nRequired.".to_owned()),
134 ..Default::default()
135 })),
136 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
137 ..Default::default()
138 }),
139 ),
140 (
141"name".to_owned(),
142crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
143 metadata: Some(Box::new(crate::schemars::schema::Metadata {
144 description: Some("Name is an identifier for this match condition, used for strategic merging of MatchConditions, as well as providing an identifier for logging purposes. A good name should be descriptive of the associated expression. Name must be a qualified name consisting of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]') with an optional DNS subdomain prefix and '/' (e.g. 'example.com/MyName')\n\nRequired.".to_owned()),
145 ..Default::default()
146 })),
147 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
148 ..Default::default()
149 }),
150 ),
151 ].into(),
152 required: [
153"expression".to_owned(),
154"name".to_owned(),
155 ].into(),
156 ..Default::default()
157 })),
158 ..Default::default()
159 })
160 }
161}