1// Generated from definition io.k8s.api.admissionregistration.v1alpha1.MatchCondition
23#[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.
14pub expression: String,
1516/// 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.
19pub name: String,
20}
2122impl crate::DeepMerge for MatchCondition {
23fn merge_from(&mut self, other: Self) {
24crate::DeepMerge::merge_from(&mut self.expression, other.expression);
25crate::DeepMerge::merge_from(&mut self.name, other.name);
26 }
27}
2829impl<'de> crate::serde::Deserialize<'de> for MatchCondition {
30fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
31#[allow(non_camel_case_types)]
32enum Field {
33 Key_expression,
34 Key_name,
35 Other,
36 }
3738impl<'de> crate::serde::Deserialize<'de> for Field {
39fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40struct Visitor;
4142impl<'de> crate::serde::de::Visitor<'de> for Visitor {
43type Value = Field;
4445fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 f.write_str("field identifier")
47 }
4849fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
50Ok(match v {
51"expression" => Field::Key_expression,
52"name" => Field::Key_name,
53_ => Field::Other,
54 })
55 }
56 }
5758 deserializer.deserialize_identifier(Visitor)
59 }
60 }
6162struct Visitor;
6364impl<'de> crate::serde::de::Visitor<'de> for Visitor {
65type Value = MatchCondition;
6667fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68 f.write_str("MatchCondition")
69 }
7071fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
72let mut value_expression: Option<String> = None;
73let mut value_name: Option<String> = None;
7475while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
76match 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 }
8283Ok(MatchCondition {
84 expression: value_expression.unwrap_or_default(),
85 name: value_name.unwrap_or_default(),
86 })
87 }
88 }
8990 deserializer.deserialize_struct(
91"MatchCondition",
92&[
93"expression",
94"name",
95 ],
96 Visitor,
97 )
98 }
99}
100101impl crate::serde::Serialize for MatchCondition {
102fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
103let mut state = serializer.serialize_struct(
104"MatchCondition",
1052,
106 )?;
107crate::serde::ser::SerializeStruct::serialize_field(&mut state, "expression", &self.expression)?;
108crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
109crate::serde::ser::SerializeStruct::end(state)
110 }
111}
112113#[cfg(feature = "schemars")]
114impl crate::schemars::JsonSchema for MatchCondition {
115fn schema_name() -> String {
116"io.k8s.api.admissionregistration.v1alpha1.MatchCondition".to_owned()
117 }
118119fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
120crate::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(),
126crate::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(),
137crate::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}