k8s_openapi/v1_32/api/admissionregistration/v1/
rule_with_operations.rs

1// Generated from definition io.k8s.api.admissionregistration.v1.RuleWithOperations
2
3/// RuleWithOperations is a tuple of Operations and Resources. It is recommended to make sure that all the tuple expansions are valid.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct RuleWithOperations {
6    /// APIGroups is the API groups the resources belong to. '*' is all groups. If '*' is present, the length of the slice must be one. Required.
7    pub api_groups: Option<Vec<String>>,
8
9    /// APIVersions is the API versions the resources belong to. '*' is all versions. If '*' is present, the length of the slice must be one. Required.
10    pub api_versions: Option<Vec<String>>,
11
12    /// Operations is the operations the admission hook cares about - CREATE, UPDATE, DELETE, CONNECT or * for all of those operations and any future admission operations that are added. If '*' is present, the length of the slice must be one. Required.
13    pub operations: Option<Vec<String>>,
14
15    /// Resources is a list of resources this rule applies to.
16    ///
17    /// For example: 'pods' means pods. 'pods/log' means the log subresource of pods. '*' means all resources, but not subresources. 'pods/*' means all subresources of pods. '*/scale' means all scale subresources. '*/*' means all resources and their subresources.
18    ///
19    /// If wildcard is present, the validation rule will ensure resources do not overlap with each other.
20    ///
21    /// Depending on the enclosing object, subresources might not be allowed. Required.
22    pub resources: Option<Vec<String>>,
23
24    /// scope specifies the scope of this rule. Valid values are "Cluster", "Namespaced", and "*" "Cluster" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. "Namespaced" means that only namespaced resources will match this rule. "*" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is "*".
25    pub scope: Option<String>,
26}
27
28impl crate::DeepMerge for RuleWithOperations {
29    fn merge_from(&mut self, other: Self) {
30        crate::merge_strategies::list::atomic(&mut self.api_groups, other.api_groups);
31        crate::merge_strategies::list::atomic(&mut self.api_versions, other.api_versions);
32        crate::merge_strategies::list::atomic(&mut self.operations, other.operations);
33        crate::merge_strategies::list::atomic(&mut self.resources, other.resources);
34        crate::DeepMerge::merge_from(&mut self.scope, other.scope);
35    }
36}
37
38impl<'de> crate::serde::Deserialize<'de> for RuleWithOperations {
39    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40        #[allow(non_camel_case_types)]
41        enum Field {
42            Key_api_groups,
43            Key_api_versions,
44            Key_operations,
45            Key_resources,
46            Key_scope,
47            Other,
48        }
49
50        impl<'de> crate::serde::Deserialize<'de> for Field {
51            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
52                struct Visitor;
53
54                impl crate::serde::de::Visitor<'_> for Visitor {
55                    type Value = Field;
56
57                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58                        f.write_str("field identifier")
59                    }
60
61                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
62                        Ok(match v {
63                            "apiGroups" => Field::Key_api_groups,
64                            "apiVersions" => Field::Key_api_versions,
65                            "operations" => Field::Key_operations,
66                            "resources" => Field::Key_resources,
67                            "scope" => Field::Key_scope,
68                            _ => Field::Other,
69                        })
70                    }
71                }
72
73                deserializer.deserialize_identifier(Visitor)
74            }
75        }
76
77        struct Visitor;
78
79        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
80            type Value = RuleWithOperations;
81
82            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83                f.write_str("RuleWithOperations")
84            }
85
86            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
87                let mut value_api_groups: Option<Vec<String>> = None;
88                let mut value_api_versions: Option<Vec<String>> = None;
89                let mut value_operations: Option<Vec<String>> = None;
90                let mut value_resources: Option<Vec<String>> = None;
91                let mut value_scope: Option<String> = None;
92
93                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
94                    match key {
95                        Field::Key_api_groups => value_api_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
96                        Field::Key_api_versions => value_api_versions = crate::serde::de::MapAccess::next_value(&mut map)?,
97                        Field::Key_operations => value_operations = crate::serde::de::MapAccess::next_value(&mut map)?,
98                        Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
99                        Field::Key_scope => value_scope = crate::serde::de::MapAccess::next_value(&mut map)?,
100                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
101                    }
102                }
103
104                Ok(RuleWithOperations {
105                    api_groups: value_api_groups,
106                    api_versions: value_api_versions,
107                    operations: value_operations,
108                    resources: value_resources,
109                    scope: value_scope,
110                })
111            }
112        }
113
114        deserializer.deserialize_struct(
115            "RuleWithOperations",
116            &[
117                "apiGroups",
118                "apiVersions",
119                "operations",
120                "resources",
121                "scope",
122            ],
123            Visitor,
124        )
125    }
126}
127
128impl crate::serde::Serialize for RuleWithOperations {
129    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
130        let mut state = serializer.serialize_struct(
131            "RuleWithOperations",
132            self.api_groups.as_ref().map_or(0, |_| 1) +
133            self.api_versions.as_ref().map_or(0, |_| 1) +
134            self.operations.as_ref().map_or(0, |_| 1) +
135            self.resources.as_ref().map_or(0, |_| 1) +
136            self.scope.as_ref().map_or(0, |_| 1),
137        )?;
138        if let Some(value) = &self.api_groups {
139            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroups", value)?;
140        }
141        if let Some(value) = &self.api_versions {
142            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersions", value)?;
143        }
144        if let Some(value) = &self.operations {
145            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "operations", value)?;
146        }
147        if let Some(value) = &self.resources {
148            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", value)?;
149        }
150        if let Some(value) = &self.scope {
151            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scope", value)?;
152        }
153        crate::serde::ser::SerializeStruct::end(state)
154    }
155}
156
157#[cfg(feature = "schemars")]
158impl crate::schemars::JsonSchema for RuleWithOperations {
159    fn schema_name() -> String {
160        "io.k8s.api.admissionregistration.v1.RuleWithOperations".to_owned()
161    }
162
163    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
164        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
165            metadata: Some(Box::new(crate::schemars::schema::Metadata {
166                description: Some("RuleWithOperations is a tuple of Operations and Resources. It is recommended to make sure that all the tuple expansions are valid.".to_owned()),
167                ..Default::default()
168            })),
169            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
170            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
171                properties: [
172                    (
173                        "apiGroups".to_owned(),
174                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
175                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
176                                description: Some("APIGroups is the API groups the resources belong to. '*' is all groups. If '*' is present, the length of the slice must be one. Required.".to_owned()),
177                                ..Default::default()
178                            })),
179                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
180                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
181                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
182                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
183                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
184                                        ..Default::default()
185                                    })
186                                ))),
187                                ..Default::default()
188                            })),
189                            ..Default::default()
190                        }),
191                    ),
192                    (
193                        "apiVersions".to_owned(),
194                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
195                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
196                                description: Some("APIVersions is the API versions the resources belong to. '*' is all versions. If '*' is present, the length of the slice must be one. Required.".to_owned()),
197                                ..Default::default()
198                            })),
199                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
200                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
201                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
202                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
203                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
204                                        ..Default::default()
205                                    })
206                                ))),
207                                ..Default::default()
208                            })),
209                            ..Default::default()
210                        }),
211                    ),
212                    (
213                        "operations".to_owned(),
214                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
215                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
216                                description: Some("Operations is the operations the admission hook cares about - CREATE, UPDATE, DELETE, CONNECT or * for all of those operations and any future admission operations that are added. If '*' is present, the length of the slice must be one. Required.".to_owned()),
217                                ..Default::default()
218                            })),
219                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
220                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
221                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
222                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
223                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
224                                        ..Default::default()
225                                    })
226                                ))),
227                                ..Default::default()
228                            })),
229                            ..Default::default()
230                        }),
231                    ),
232                    (
233                        "resources".to_owned(),
234                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
235                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
236                                description: Some("Resources is a list of resources this rule applies to.\n\nFor example: 'pods' means pods. 'pods/log' means the log subresource of pods. '*' means all resources, but not subresources. 'pods/*' means all subresources of pods. '*/scale' means all scale subresources. '*/*' means all resources and their subresources.\n\nIf wildcard is present, the validation rule will ensure resources do not overlap with each other.\n\nDepending on the enclosing object, subresources might not be allowed. Required.".to_owned()),
237                                ..Default::default()
238                            })),
239                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
240                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
241                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
242                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
243                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
244                                        ..Default::default()
245                                    })
246                                ))),
247                                ..Default::default()
248                            })),
249                            ..Default::default()
250                        }),
251                    ),
252                    (
253                        "scope".to_owned(),
254                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
255                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
256                                description: Some("scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".".to_owned()),
257                                ..Default::default()
258                            })),
259                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
260                            ..Default::default()
261                        }),
262                    ),
263                ].into(),
264                ..Default::default()
265            })),
266            ..Default::default()
267        })
268    }
269}