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

1// Generated from definition io.k8s.api.admissionregistration.v1alpha1.MatchCondition
2
3#[derive(Clone, Debug, Default, PartialEq)]
4pub struct MatchCondition {
5    /// 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:
6    ///
7    /// '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.
8    ///   See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz
9    /// 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the
10    ///   request resource.
11    /// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/
12    ///
13    /// Required.
14    pub expression: String,
15
16    /// 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')
17    ///
18    /// Required.
19    pub name: String,
20}
21
22impl crate::DeepMerge for MatchCondition {
23    fn merge_from(&mut self, other: Self) {
24        crate::DeepMerge::merge_from(&mut self.expression, other.expression);
25        crate::DeepMerge::merge_from(&mut self.name, other.name);
26    }
27}
28
29impl<'de> crate::serde::Deserialize<'de> for MatchCondition {
30    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
31        #[allow(non_camel_case_types)]
32        enum Field {
33            Key_expression,
34            Key_name,
35            Other,
36        }
37
38        impl<'de> crate::serde::Deserialize<'de> for Field {
39            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40                struct Visitor;
41
42                impl crate::serde::de::Visitor<'_> for Visitor {
43                    type Value = Field;
44
45                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46                        f.write_str("field identifier")
47                    }
48
49                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
50                        Ok(match v {
51                            "expression" => Field::Key_expression,
52                            "name" => Field::Key_name,
53                            _ => Field::Other,
54                        })
55                    }
56                }
57
58                deserializer.deserialize_identifier(Visitor)
59            }
60        }
61
62        struct Visitor;
63
64        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
65            type Value = MatchCondition;
66
67            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68                f.write_str("MatchCondition")
69            }
70
71            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
72                let mut value_expression: Option<String> = None;
73                let mut value_name: Option<String> = None;
74
75                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
76                    match key {
77                        Field::Key_expression => value_expression = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
79                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
80                    }
81                }
82
83                Ok(MatchCondition {
84                    expression: value_expression.unwrap_or_default(),
85                    name: value_name.unwrap_or_default(),
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "MatchCondition",
92            &[
93                "expression",
94                "name",
95            ],
96            Visitor,
97        )
98    }
99}
100
101impl crate::serde::Serialize for MatchCondition {
102    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
103        let mut state = serializer.serialize_struct(
104            "MatchCondition",
105            2,
106        )?;
107        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "expression", &self.expression)?;
108        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
109        crate::serde::ser::SerializeStruct::end(state)
110    }
111}
112
113#[cfg(feature = "schemars")]
114impl crate::schemars::JsonSchema for MatchCondition {
115    fn schema_name() -> String {
116        "io.k8s.api.admissionregistration.v1alpha1.MatchCondition".to_owned()
117    }
118
119    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
120        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
121            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
122            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
123                properties: [
124                    (
125                        "expression".to_owned(),
126                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
127                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
128                                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()),
129                                ..Default::default()
130                            })),
131                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
132                            ..Default::default()
133                        }),
134                    ),
135                    (
136                        "name".to_owned(),
137                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
138                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
139                                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()),
140                                ..Default::default()
141                            })),
142                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
143                            ..Default::default()
144                        }),
145                    ),
146                ].into(),
147                required: [
148                    "expression".to_owned(),
149                    "name".to_owned(),
150                ].into(),
151                ..Default::default()
152            })),
153            ..Default::default()
154        })
155    }
156}