1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourcePolicyRule {
6 pub api_groups: std::vec::Vec<std::string::String>,
8
9 pub cluster_scope: Option<bool>,
11
12 pub namespaces: Option<std::vec::Vec<std::string::String>>,
14
15 pub resources: std::vec::Vec<std::string::String>,
17
18 pub verbs: std::vec::Vec<std::string::String>,
20}
21
22impl crate::DeepMerge for ResourcePolicyRule {
23 fn merge_from(&mut self, other: Self) {
24 crate::merge_strategies::list::set(&mut self.api_groups, other.api_groups);
25 crate::DeepMerge::merge_from(&mut self.cluster_scope, other.cluster_scope);
26 crate::merge_strategies::list::set(&mut self.namespaces, other.namespaces);
27 crate::merge_strategies::list::set(&mut self.resources, other.resources);
28 crate::merge_strategies::list::set(&mut self.verbs, other.verbs);
29 }
30}
31
32impl<'de> crate::serde::Deserialize<'de> for ResourcePolicyRule {
33 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
34 #[allow(non_camel_case_types)]
35 enum Field {
36 Key_api_groups,
37 Key_cluster_scope,
38 Key_namespaces,
39 Key_resources,
40 Key_verbs,
41 Other,
42 }
43
44 impl<'de> crate::serde::Deserialize<'de> for Field {
45 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46 struct Visitor;
47
48 impl crate::serde::de::Visitor<'_> for Visitor {
49 type Value = Field;
50
51 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52 f.write_str("field identifier")
53 }
54
55 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
56 Ok(match v {
57 "apiGroups" => Field::Key_api_groups,
58 "clusterScope" => Field::Key_cluster_scope,
59 "namespaces" => Field::Key_namespaces,
60 "resources" => Field::Key_resources,
61 "verbs" => Field::Key_verbs,
62 _ => Field::Other,
63 })
64 }
65 }
66
67 deserializer.deserialize_identifier(Visitor)
68 }
69 }
70
71 struct Visitor;
72
73 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
74 type Value = ResourcePolicyRule;
75
76 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77 f.write_str("ResourcePolicyRule")
78 }
79
80 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
81 let mut value_api_groups: Option<std::vec::Vec<std::string::String>> = None;
82 let mut value_cluster_scope: Option<bool> = None;
83 let mut value_namespaces: Option<std::vec::Vec<std::string::String>> = None;
84 let mut value_resources: Option<std::vec::Vec<std::string::String>> = None;
85 let mut value_verbs: Option<std::vec::Vec<std::string::String>> = None;
86
87 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
88 match key {
89 Field::Key_api_groups => value_api_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
90 Field::Key_cluster_scope => value_cluster_scope = crate::serde::de::MapAccess::next_value(&mut map)?,
91 Field::Key_namespaces => value_namespaces = crate::serde::de::MapAccess::next_value(&mut map)?,
92 Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
93 Field::Key_verbs => value_verbs = crate::serde::de::MapAccess::next_value(&mut map)?,
94 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
95 }
96 }
97
98 Ok(ResourcePolicyRule {
99 api_groups: value_api_groups.unwrap_or_default(),
100 cluster_scope: value_cluster_scope,
101 namespaces: value_namespaces,
102 resources: value_resources.unwrap_or_default(),
103 verbs: value_verbs.unwrap_or_default(),
104 })
105 }
106 }
107
108 deserializer.deserialize_struct(
109 "ResourcePolicyRule",
110 &[
111 "apiGroups",
112 "clusterScope",
113 "namespaces",
114 "resources",
115 "verbs",
116 ],
117 Visitor,
118 )
119 }
120}
121
122impl crate::serde::Serialize for ResourcePolicyRule {
123 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
124 let mut state = serializer.serialize_struct(
125 "ResourcePolicyRule",
126 3 +
127 self.cluster_scope.as_ref().map_or(0, |_| 1) +
128 self.namespaces.as_ref().map_or(0, |_| 1),
129 )?;
130 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroups", &self.api_groups)?;
131 if let Some(value) = &self.cluster_scope {
132 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "clusterScope", value)?;
133 }
134 if let Some(value) = &self.namespaces {
135 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespaces", value)?;
136 }
137 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", &self.resources)?;
138 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "verbs", &self.verbs)?;
139 crate::serde::ser::SerializeStruct::end(state)
140 }
141}
142
143#[cfg(feature = "schemars")]
144impl crate::schemars::JsonSchema for ResourcePolicyRule {
145 fn schema_name() -> std::borrow::Cow<'static, str> {
146 "io.k8s.api.flowcontrol.v1.ResourcePolicyRule".into()
147 }
148
149 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
150 crate::schemars::json_schema!({
151 "description": "ResourcePolicyRule is a predicate that matches some resource requests, testing the request's verb and the target resource. A ResourcePolicyRule matches a resource request if and only if: (a) at least one member of verbs matches the request, (b) at least one member of apiGroups matches the request, (c) at least one member of resources matches the request, and (d) either (d1) the request does not specify a namespace (i.e., `Namespace==\"\"`) and clusterScope is true or (d2) the request specifies a namespace and least one member of namespaces matches the request's namespace.",
152 "type": "object",
153 "properties": {
154 "apiGroups": {
155 "description": "`apiGroups` is a list of matching API groups and may not be empty. \"*\" matches all API groups and, if present, must be the only entry. Required.",
156 "type": "array",
157 "items": {
158 "type": "string",
159 },
160 },
161 "clusterScope": {
162 "description": "`clusterScope` indicates whether to match requests that do not specify a namespace (which happens either because the resource is not namespaced or the request targets all namespaces). If this field is omitted or false then the `namespaces` field must contain a non-empty list.",
163 "type": "boolean",
164 },
165 "namespaces": {
166 "description": "`namespaces` is a list of target namespaces that restricts matches. A request that specifies a target namespace matches only if either (a) this list contains that target namespace or (b) this list contains \"*\". Note that \"*\" matches any specified namespace but does not match a request that _does not specify_ a namespace (see the `clusterScope` field for that). This list may be empty, but only if `clusterScope` is true.",
167 "type": "array",
168 "items": {
169 "type": "string",
170 },
171 },
172 "resources": {
173 "description": "`resources` is a list of matching resources (i.e., lowercase and plural) with, if desired, subresource. For example, [ \"services\", \"nodes/status\" ]. This list may not be empty. \"*\" matches all resources and, if present, must be the only entry. Required.",
174 "type": "array",
175 "items": {
176 "type": "string",
177 },
178 },
179 "verbs": {
180 "description": "`verbs` is a list of matching verbs and may not be empty. \"*\" matches all verbs and, if present, must be the only entry. Required.",
181 "type": "array",
182 "items": {
183 "type": "string",
184 },
185 },
186 },
187 "required": [
188 "apiGroups",
189 "resources",
190 "verbs",
191 ],
192 })
193 }
194}
195
196#[cfg(feature = "schemars08")]
197impl crate::schemars08::JsonSchema for ResourcePolicyRule {
198 fn schema_name() -> std::string::String {
199 "io.k8s.api.flowcontrol.v1.ResourcePolicyRule".into()
200 }
201
202 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
203 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
204 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
205 description: Some("ResourcePolicyRule is a predicate that matches some resource requests, testing the request's verb and the target resource. A ResourcePolicyRule matches a resource request if and only if: (a) at least one member of verbs matches the request, (b) at least one member of apiGroups matches the request, (c) at least one member of resources matches the request, and (d) either (d1) the request does not specify a namespace (i.e., `Namespace==\"\"`) and clusterScope is true or (d2) the request specifies a namespace and least one member of namespaces matches the request's namespace.".into()),
206 ..Default::default()
207 })),
208 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
209 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
210 properties: [
211 (
212 "apiGroups".into(),
213 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
214 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
215 description: Some("`apiGroups` is a list of matching API groups and may not be empty. \"*\" matches all API groups and, if present, must be the only entry. Required.".into()),
216 ..Default::default()
217 })),
218 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
219 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
220 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
221 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
222 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
223 ..Default::default()
224 })
225 ))),
226 ..Default::default()
227 })),
228 ..Default::default()
229 }),
230 ),
231 (
232 "clusterScope".into(),
233 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
234 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
235 description: Some("`clusterScope` indicates whether to match requests that do not specify a namespace (which happens either because the resource is not namespaced or the request targets all namespaces). If this field is omitted or false then the `namespaces` field must contain a non-empty list.".into()),
236 ..Default::default()
237 })),
238 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Boolean))),
239 ..Default::default()
240 }),
241 ),
242 (
243 "namespaces".into(),
244 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
245 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
246 description: Some("`namespaces` is a list of target namespaces that restricts matches. A request that specifies a target namespace matches only if either (a) this list contains that target namespace or (b) this list contains \"*\". Note that \"*\" matches any specified namespace but does not match a request that _does not specify_ a namespace (see the `clusterScope` field for that). This list may be empty, but only if `clusterScope` is true.".into()),
247 ..Default::default()
248 })),
249 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
250 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
251 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
252 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
253 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
254 ..Default::default()
255 })
256 ))),
257 ..Default::default()
258 })),
259 ..Default::default()
260 }),
261 ),
262 (
263 "resources".into(),
264 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
265 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
266 description: Some("`resources` is a list of matching resources (i.e., lowercase and plural) with, if desired, subresource. For example, [ \"services\", \"nodes/status\" ]. This list may not be empty. \"*\" matches all resources and, if present, must be the only entry. Required.".into()),
267 ..Default::default()
268 })),
269 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
270 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
271 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
272 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
273 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
274 ..Default::default()
275 })
276 ))),
277 ..Default::default()
278 })),
279 ..Default::default()
280 }),
281 ),
282 (
283 "verbs".into(),
284 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
285 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
286 description: Some("`verbs` is a list of matching verbs and may not be empty. \"*\" matches all verbs and, if present, must be the only entry. Required.".into()),
287 ..Default::default()
288 })),
289 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
290 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
291 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
292 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
293 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
294 ..Default::default()
295 })
296 ))),
297 ..Default::default()
298 })),
299 ..Default::default()
300 }),
301 ),
302 ].into(),
303 required: [
304 "apiGroups".into(),
305 "resources".into(),
306 "verbs".into(),
307 ].into(),
308 ..Default::default()
309 })),
310 ..Default::default()
311 })
312 }
313}