k8s_openapi/v1_30/api/admissionregistration/v1alpha1/
named_rule_with_operations.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct NamedRuleWithOperations {
6 pub api_groups: Option<Vec<String>>,
8
9 pub api_versions: Option<Vec<String>>,
11
12 pub operations: Option<Vec<String>>,
14
15 pub resource_names: Option<Vec<String>>,
17
18 pub resources: Option<Vec<String>>,
26
27 pub scope: Option<String>,
29}
30
31impl crate::DeepMerge for NamedRuleWithOperations {
32 fn merge_from(&mut self, other: Self) {
33 crate::merge_strategies::list::atomic(&mut self.api_groups, other.api_groups);
34 crate::merge_strategies::list::atomic(&mut self.api_versions, other.api_versions);
35 crate::merge_strategies::list::atomic(&mut self.operations, other.operations);
36 crate::merge_strategies::list::atomic(&mut self.resource_names, other.resource_names);
37 crate::merge_strategies::list::atomic(&mut self.resources, other.resources);
38 crate::DeepMerge::merge_from(&mut self.scope, other.scope);
39 }
40}
41
42impl<'de> crate::serde::Deserialize<'de> for NamedRuleWithOperations {
43 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
44 #[allow(non_camel_case_types)]
45 enum Field {
46 Key_api_groups,
47 Key_api_versions,
48 Key_operations,
49 Key_resource_names,
50 Key_resources,
51 Key_scope,
52 Other,
53 }
54
55 impl<'de> crate::serde::Deserialize<'de> for Field {
56 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
57 struct Visitor;
58
59 impl crate::serde::de::Visitor<'_> for Visitor {
60 type Value = Field;
61
62 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63 f.write_str("field identifier")
64 }
65
66 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
67 Ok(match v {
68 "apiGroups" => Field::Key_api_groups,
69 "apiVersions" => Field::Key_api_versions,
70 "operations" => Field::Key_operations,
71 "resourceNames" => Field::Key_resource_names,
72 "resources" => Field::Key_resources,
73 "scope" => Field::Key_scope,
74 _ => Field::Other,
75 })
76 }
77 }
78
79 deserializer.deserialize_identifier(Visitor)
80 }
81 }
82
83 struct Visitor;
84
85 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
86 type Value = NamedRuleWithOperations;
87
88 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89 f.write_str("NamedRuleWithOperations")
90 }
91
92 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
93 let mut value_api_groups: Option<Vec<String>> = None;
94 let mut value_api_versions: Option<Vec<String>> = None;
95 let mut value_operations: Option<Vec<String>> = None;
96 let mut value_resource_names: Option<Vec<String>> = None;
97 let mut value_resources: Option<Vec<String>> = None;
98 let mut value_scope: Option<String> = None;
99
100 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
101 match key {
102 Field::Key_api_groups => value_api_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
103 Field::Key_api_versions => value_api_versions = crate::serde::de::MapAccess::next_value(&mut map)?,
104 Field::Key_operations => value_operations = crate::serde::de::MapAccess::next_value(&mut map)?,
105 Field::Key_resource_names => value_resource_names = crate::serde::de::MapAccess::next_value(&mut map)?,
106 Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
107 Field::Key_scope => value_scope = crate::serde::de::MapAccess::next_value(&mut map)?,
108 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
109 }
110 }
111
112 Ok(NamedRuleWithOperations {
113 api_groups: value_api_groups,
114 api_versions: value_api_versions,
115 operations: value_operations,
116 resource_names: value_resource_names,
117 resources: value_resources,
118 scope: value_scope,
119 })
120 }
121 }
122
123 deserializer.deserialize_struct(
124 "NamedRuleWithOperations",
125 &[
126 "apiGroups",
127 "apiVersions",
128 "operations",
129 "resourceNames",
130 "resources",
131 "scope",
132 ],
133 Visitor,
134 )
135 }
136}
137
138impl crate::serde::Serialize for NamedRuleWithOperations {
139 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
140 let mut state = serializer.serialize_struct(
141 "NamedRuleWithOperations",
142 self.api_groups.as_ref().map_or(0, |_| 1) +
143 self.api_versions.as_ref().map_or(0, |_| 1) +
144 self.operations.as_ref().map_or(0, |_| 1) +
145 self.resource_names.as_ref().map_or(0, |_| 1) +
146 self.resources.as_ref().map_or(0, |_| 1) +
147 self.scope.as_ref().map_or(0, |_| 1),
148 )?;
149 if let Some(value) = &self.api_groups {
150 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroups", value)?;
151 }
152 if let Some(value) = &self.api_versions {
153 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersions", value)?;
154 }
155 if let Some(value) = &self.operations {
156 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "operations", value)?;
157 }
158 if let Some(value) = &self.resource_names {
159 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceNames", value)?;
160 }
161 if let Some(value) = &self.resources {
162 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", value)?;
163 }
164 if let Some(value) = &self.scope {
165 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scope", value)?;
166 }
167 crate::serde::ser::SerializeStruct::end(state)
168 }
169}
170
171#[cfg(feature = "schemars")]
172impl crate::schemars::JsonSchema for NamedRuleWithOperations {
173 fn schema_name() -> String {
174 "io.k8s.api.admissionregistration.v1alpha1.NamedRuleWithOperations".to_owned()
175 }
176
177 fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
178 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
179 metadata: Some(Box::new(crate::schemars::schema::Metadata {
180 description: Some("NamedRuleWithOperations is a tuple of Operations and Resources with ResourceNames.".to_owned()),
181 ..Default::default()
182 })),
183 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
184 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
185 properties: [
186 (
187 "apiGroups".to_owned(),
188 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
189 metadata: Some(Box::new(crate::schemars::schema::Metadata {
190 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()),
191 ..Default::default()
192 })),
193 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
194 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
195 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
196 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
197 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
198 ..Default::default()
199 })
200 ))),
201 ..Default::default()
202 })),
203 ..Default::default()
204 }),
205 ),
206 (
207 "apiVersions".to_owned(),
208 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
209 metadata: Some(Box::new(crate::schemars::schema::Metadata {
210 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()),
211 ..Default::default()
212 })),
213 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
214 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
215 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
216 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
217 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
218 ..Default::default()
219 })
220 ))),
221 ..Default::default()
222 })),
223 ..Default::default()
224 }),
225 ),
226 (
227 "operations".to_owned(),
228 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
229 metadata: Some(Box::new(crate::schemars::schema::Metadata {
230 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()),
231 ..Default::default()
232 })),
233 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
234 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
235 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
236 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
237 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
238 ..Default::default()
239 })
240 ))),
241 ..Default::default()
242 })),
243 ..Default::default()
244 }),
245 ),
246 (
247 "resourceNames".to_owned(),
248 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
249 metadata: Some(Box::new(crate::schemars::schema::Metadata {
250 description: Some("ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed.".to_owned()),
251 ..Default::default()
252 })),
253 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
254 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
255 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
256 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
257 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
258 ..Default::default()
259 })
260 ))),
261 ..Default::default()
262 })),
263 ..Default::default()
264 }),
265 ),
266 (
267 "resources".to_owned(),
268 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
269 metadata: Some(Box::new(crate::schemars::schema::Metadata {
270 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()),
271 ..Default::default()
272 })),
273 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
274 array: Some(Box::new(crate::schemars::schema::ArrayValidation {
275 items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
276 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
277 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
278 ..Default::default()
279 })
280 ))),
281 ..Default::default()
282 })),
283 ..Default::default()
284 }),
285 ),
286 (
287 "scope".to_owned(),
288 crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
289 metadata: Some(Box::new(crate::schemars::schema::Metadata {
290 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()),
291 ..Default::default()
292 })),
293 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
294 ..Default::default()
295 }),
296 ),
297 ].into(),
298 ..Default::default()
299 })),
300 ..Default::default()
301 })
302 }
303}