k8s_openapi/v1_32/api/admissionregistration/v1beta1/
match_condition.rs

1// Generated from definition io.k8s.api.admissionregistration.v1beta1.MatchCondition
2
3/// 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.
15    pub expression: String,
16
17    /// 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.
20    pub name: String,
21}
22
23impl crate::DeepMerge for MatchCondition {
24    fn merge_from(&mut self, other: Self) {
25        crate::DeepMerge::merge_from(&mut self.expression, other.expression);
26        crate::DeepMerge::merge_from(&mut self.name, other.name);
27    }
28}
29
30impl<'de> crate::serde::Deserialize<'de> for MatchCondition {
31    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
32        #[allow(non_camel_case_types)]
33        enum Field {
34            Key_expression,
35            Key_name,
36            Other,
37        }
38
39        impl<'de> crate::serde::Deserialize<'de> for Field {
40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41                struct Visitor;
42
43                impl crate::serde::de::Visitor<'_> for Visitor {
44                    type Value = Field;
45
46                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47                        f.write_str("field identifier")
48                    }
49
50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51                        Ok(match v {
52                            "expression" => Field::Key_expression,
53                            "name" => Field::Key_name,
54                            _ => Field::Other,
55                        })
56                    }
57                }
58
59                deserializer.deserialize_identifier(Visitor)
60            }
61        }
62
63        struct Visitor;
64
65        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
66            type Value = MatchCondition;
67
68            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69                f.write_str("MatchCondition")
70            }
71
72            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
73                let mut value_expression: Option<String> = None;
74                let mut value_name: Option<String> = None;
75
76                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
77                    match 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                }
83
84                Ok(MatchCondition {
85                    expression: value_expression.unwrap_or_default(),
86                    name: value_name.unwrap_or_default(),
87                })
88            }
89        }
90
91        deserializer.deserialize_struct(
92            "MatchCondition",
93            &[
94                "expression",
95                "name",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for MatchCondition {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "MatchCondition",
106            2,
107        )?;
108        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "expression", &self.expression)?;
109        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
110        crate::serde::ser::SerializeStruct::end(state)
111    }
112}
113
114#[cfg(feature = "schemars")]
115impl crate::schemars::JsonSchema for MatchCondition {
116    fn schema_name() -> String {
117        "io.k8s.api.admissionregistration.v1beta1.MatchCondition".to_owned()
118    }
119
120    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
121        crate::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(),
131                        crate::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(),
142                        crate::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}