k8s_openapi/v1_36/api/authorization/v1/
resource_rule.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceRule {
6 pub api_groups: Option<std::vec::Vec<std::string::String>>,
8
9 pub resource_names: Option<std::vec::Vec<std::string::String>>,
11
12 pub resources: Option<std::vec::Vec<std::string::String>>,
15
16 pub verbs: std::vec::Vec<std::string::String>,
18}
19
20impl crate::DeepMerge for ResourceRule {
21 fn merge_from(&mut self, other: Self) {
22 crate::merge_strategies::list::atomic(&mut self.api_groups, other.api_groups);
23 crate::merge_strategies::list::atomic(&mut self.resource_names, other.resource_names);
24 crate::merge_strategies::list::atomic(&mut self.resources, other.resources);
25 crate::merge_strategies::list::atomic(&mut self.verbs, other.verbs);
26 }
27}
28
29impl<'de> crate::serde::Deserialize<'de> for ResourceRule {
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_api_groups,
34 Key_resource_names,
35 Key_resources,
36 Key_verbs,
37 Other,
38 }
39
40 impl<'de> crate::serde::Deserialize<'de> for Field {
41 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
42 struct Visitor;
43
44 impl crate::serde::de::Visitor<'_> for Visitor {
45 type Value = Field;
46
47 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
48 f.write_str("field identifier")
49 }
50
51 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
52 Ok(match v {
53 "apiGroups" => Field::Key_api_groups,
54 "resourceNames" => Field::Key_resource_names,
55 "resources" => Field::Key_resources,
56 "verbs" => Field::Key_verbs,
57 _ => Field::Other,
58 })
59 }
60 }
61
62 deserializer.deserialize_identifier(Visitor)
63 }
64 }
65
66 struct Visitor;
67
68 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
69 type Value = ResourceRule;
70
71 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
72 f.write_str("ResourceRule")
73 }
74
75 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
76 let mut value_api_groups: Option<std::vec::Vec<std::string::String>> = None;
77 let mut value_resource_names: Option<std::vec::Vec<std::string::String>> = None;
78 let mut value_resources: Option<std::vec::Vec<std::string::String>> = None;
79 let mut value_verbs: Option<std::vec::Vec<std::string::String>> = None;
80
81 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
82 match key {
83 Field::Key_api_groups => value_api_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
84 Field::Key_resource_names => value_resource_names = crate::serde::de::MapAccess::next_value(&mut map)?,
85 Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
86 Field::Key_verbs => value_verbs = crate::serde::de::MapAccess::next_value(&mut map)?,
87 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
88 }
89 }
90
91 Ok(ResourceRule {
92 api_groups: value_api_groups,
93 resource_names: value_resource_names,
94 resources: value_resources,
95 verbs: value_verbs.unwrap_or_default(),
96 })
97 }
98 }
99
100 deserializer.deserialize_struct(
101 "ResourceRule",
102 &[
103 "apiGroups",
104 "resourceNames",
105 "resources",
106 "verbs",
107 ],
108 Visitor,
109 )
110 }
111}
112
113impl crate::serde::Serialize for ResourceRule {
114 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
115 let mut state = serializer.serialize_struct(
116 "ResourceRule",
117 1 +
118 self.api_groups.as_ref().map_or(0, |_| 1) +
119 self.resource_names.as_ref().map_or(0, |_| 1) +
120 self.resources.as_ref().map_or(0, |_| 1),
121 )?;
122 if let Some(value) = &self.api_groups {
123 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroups", value)?;
124 }
125 if let Some(value) = &self.resource_names {
126 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceNames", value)?;
127 }
128 if let Some(value) = &self.resources {
129 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", value)?;
130 }
131 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "verbs", &self.verbs)?;
132 crate::serde::ser::SerializeStruct::end(state)
133 }
134}
135
136#[cfg(feature = "schemars")]
137impl crate::schemars::JsonSchema for ResourceRule {
138 fn schema_name() -> std::borrow::Cow<'static, str> {
139 "io.k8s.api.authorization.v1.ResourceRule".into()
140 }
141
142 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
143 crate::schemars::json_schema!({
144 "description": "ResourceRule is the list of actions the subject is allowed to perform on resources. The list ordering isn't significant, may contain duplicates, and possibly be incomplete.",
145 "type": "object",
146 "properties": {
147 "apiGroups": {
148 "description": "apiGroups is the name of the APIGroup that contains the resources. If multiple API groups are specified, any action requested against one of the enumerated resources in any API group will be allowed. \"*\" means all.",
149 "type": "array",
150 "items": {
151 "type": "string",
152 },
153 },
154 "resourceNames": {
155 "description": "resourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed. \"*\" means all.",
156 "type": "array",
157 "items": {
158 "type": "string",
159 },
160 },
161 "resources": {
162 "description": "resources is a list of resources this rule applies to. \"*\" means all in the specified apiGroups.\n \"*/foo\" represents the subresource 'foo' for all resources in the specified apiGroups.",
163 "type": "array",
164 "items": {
165 "type": "string",
166 },
167 },
168 "verbs": {
169 "description": "verbs is a list of kubernetes resource API verbs, like: get, list, watch, create, update, delete, proxy. \"*\" means all.",
170 "type": "array",
171 "items": {
172 "type": "string",
173 },
174 },
175 },
176 "required": [
177 "verbs",
178 ],
179 })
180 }
181}
182
183#[cfg(feature = "schemars08")]
184impl crate::schemars08::JsonSchema for ResourceRule {
185 fn schema_name() -> std::string::String {
186 "io.k8s.api.authorization.v1.ResourceRule".into()
187 }
188
189 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
190 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
191 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
192 description: Some("ResourceRule is the list of actions the subject is allowed to perform on resources. The list ordering isn't significant, may contain duplicates, and possibly be incomplete.".into()),
193 ..Default::default()
194 })),
195 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
196 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
197 properties: [
198 (
199 "apiGroups".into(),
200 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
201 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
202 description: Some("apiGroups is the name of the APIGroup that contains the resources. If multiple API groups are specified, any action requested against one of the enumerated resources in any API group will be allowed. \"*\" means all.".into()),
203 ..Default::default()
204 })),
205 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
206 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
207 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
208 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
209 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
210 ..Default::default()
211 })
212 ))),
213 ..Default::default()
214 })),
215 ..Default::default()
216 }),
217 ),
218 (
219 "resourceNames".into(),
220 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
221 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
222 description: Some("resourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed. \"*\" means all.".into()),
223 ..Default::default()
224 })),
225 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
226 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
227 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
228 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
229 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
230 ..Default::default()
231 })
232 ))),
233 ..Default::default()
234 })),
235 ..Default::default()
236 }),
237 ),
238 (
239 "resources".into(),
240 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
241 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
242 description: Some("resources is a list of resources this rule applies to. \"*\" means all in the specified apiGroups.\n \"*/foo\" represents the subresource 'foo' for all resources in the specified apiGroups.".into()),
243 ..Default::default()
244 })),
245 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
246 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
247 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
248 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
249 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
250 ..Default::default()
251 })
252 ))),
253 ..Default::default()
254 })),
255 ..Default::default()
256 }),
257 ),
258 (
259 "verbs".into(),
260 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
261 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
262 description: Some("verbs is a list of kubernetes resource API verbs, like: get, list, watch, create, update, delete, proxy. \"*\" means all.".into()),
263 ..Default::default()
264 })),
265 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
266 array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
267 items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
268 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
269 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
270 ..Default::default()
271 })
272 ))),
273 ..Default::default()
274 })),
275 ..Default::default()
276 }),
277 ),
278 ].into(),
279 required: [
280 "verbs".into(),
281 ].into(),
282 ..Default::default()
283 })),
284 ..Default::default()
285 })
286 }
287}