Skip to main content

k8s_openapi/v1_36/api/authorization/v1/
resource_attributes.rs

1// Generated from definition io.k8s.api.authorization.v1.ResourceAttributes
2
3/// ResourceAttributes includes the authorization attributes available for resource requests to the Authorizer interface
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceAttributes {
6    /// fieldSelector describes the limitation on access based on field.  It can only limit access, not broaden it.
7    pub field_selector: Option<crate::api::authorization::v1::FieldSelectorAttributes>,
8
9    /// group is the API Group of the Resource.  "*" means all.
10    pub group: Option<std::string::String>,
11
12    /// labelSelector describes the limitation on access based on labels.  It can only limit access, not broaden it.
13    pub label_selector: Option<crate::api::authorization::v1::LabelSelectorAttributes>,
14
15    /// name is the name of the resource being requested for a "get" or deleted for a "delete". "" (empty) means all.
16    pub name: Option<std::string::String>,
17
18    /// namespace is the namespace of the action being requested.  Currently, there is no distinction between no namespace and all namespaces "" (empty) is defaulted for LocalSubjectAccessReviews "" (empty) is empty for cluster-scoped resources "" (empty) means "all" for namespace scoped resources from a SubjectAccessReview or SelfSubjectAccessReview
19    pub namespace: Option<std::string::String>,
20
21    /// resource is one of the existing resource types.  "*" means all.
22    pub resource: Option<std::string::String>,
23
24    /// subresource is one of the existing resource types.  "" means none.
25    pub subresource: Option<std::string::String>,
26
27    /// verb is a kubernetes resource API verb, like: get, list, watch, create, update, delete, proxy.  "*" means all.
28    pub verb: Option<std::string::String>,
29
30    /// version is the API Version of the Resource.  "*" means all.
31    pub version: Option<std::string::String>,
32}
33
34impl crate::DeepMerge for ResourceAttributes {
35    fn merge_from(&mut self, other: Self) {
36        crate::DeepMerge::merge_from(&mut self.field_selector, other.field_selector);
37        crate::DeepMerge::merge_from(&mut self.group, other.group);
38        crate::DeepMerge::merge_from(&mut self.label_selector, other.label_selector);
39        crate::DeepMerge::merge_from(&mut self.name, other.name);
40        crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
41        crate::DeepMerge::merge_from(&mut self.resource, other.resource);
42        crate::DeepMerge::merge_from(&mut self.subresource, other.subresource);
43        crate::DeepMerge::merge_from(&mut self.verb, other.verb);
44        crate::DeepMerge::merge_from(&mut self.version, other.version);
45    }
46}
47
48impl<'de> crate::serde::Deserialize<'de> for ResourceAttributes {
49    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
50        #[allow(non_camel_case_types)]
51        enum Field {
52            Key_field_selector,
53            Key_group,
54            Key_label_selector,
55            Key_name,
56            Key_namespace,
57            Key_resource,
58            Key_subresource,
59            Key_verb,
60            Key_version,
61            Other,
62        }
63
64        impl<'de> crate::serde::Deserialize<'de> for Field {
65            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
66                struct Visitor;
67
68                impl crate::serde::de::Visitor<'_> for Visitor {
69                    type Value = Field;
70
71                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
72                        f.write_str("field identifier")
73                    }
74
75                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
76                        Ok(match v {
77                            "fieldSelector" => Field::Key_field_selector,
78                            "group" => Field::Key_group,
79                            "labelSelector" => Field::Key_label_selector,
80                            "name" => Field::Key_name,
81                            "namespace" => Field::Key_namespace,
82                            "resource" => Field::Key_resource,
83                            "subresource" => Field::Key_subresource,
84                            "verb" => Field::Key_verb,
85                            "version" => Field::Key_version,
86                            _ => Field::Other,
87                        })
88                    }
89                }
90
91                deserializer.deserialize_identifier(Visitor)
92            }
93        }
94
95        struct Visitor;
96
97        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
98            type Value = ResourceAttributes;
99
100            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
101                f.write_str("ResourceAttributes")
102            }
103
104            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
105                let mut value_field_selector: Option<crate::api::authorization::v1::FieldSelectorAttributes> = None;
106                let mut value_group: Option<std::string::String> = None;
107                let mut value_label_selector: Option<crate::api::authorization::v1::LabelSelectorAttributes> = None;
108                let mut value_name: Option<std::string::String> = None;
109                let mut value_namespace: Option<std::string::String> = None;
110                let mut value_resource: Option<std::string::String> = None;
111                let mut value_subresource: Option<std::string::String> = None;
112                let mut value_verb: Option<std::string::String> = None;
113                let mut value_version: Option<std::string::String> = None;
114
115                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
116                    match key {
117                        Field::Key_field_selector => value_field_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
118                        Field::Key_group => value_group = crate::serde::de::MapAccess::next_value(&mut map)?,
119                        Field::Key_label_selector => value_label_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
120                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
121                        Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
122                        Field::Key_resource => value_resource = crate::serde::de::MapAccess::next_value(&mut map)?,
123                        Field::Key_subresource => value_subresource = crate::serde::de::MapAccess::next_value(&mut map)?,
124                        Field::Key_verb => value_verb = crate::serde::de::MapAccess::next_value(&mut map)?,
125                        Field::Key_version => value_version = crate::serde::de::MapAccess::next_value(&mut map)?,
126                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
127                    }
128                }
129
130                Ok(ResourceAttributes {
131                    field_selector: value_field_selector,
132                    group: value_group,
133                    label_selector: value_label_selector,
134                    name: value_name,
135                    namespace: value_namespace,
136                    resource: value_resource,
137                    subresource: value_subresource,
138                    verb: value_verb,
139                    version: value_version,
140                })
141            }
142        }
143
144        deserializer.deserialize_struct(
145            "ResourceAttributes",
146            &[
147                "fieldSelector",
148                "group",
149                "labelSelector",
150                "name",
151                "namespace",
152                "resource",
153                "subresource",
154                "verb",
155                "version",
156            ],
157            Visitor,
158        )
159    }
160}
161
162impl crate::serde::Serialize for ResourceAttributes {
163    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
164        let mut state = serializer.serialize_struct(
165            "ResourceAttributes",
166            self.field_selector.as_ref().map_or(0, |_| 1) +
167            self.group.as_ref().map_or(0, |_| 1) +
168            self.label_selector.as_ref().map_or(0, |_| 1) +
169            self.name.as_ref().map_or(0, |_| 1) +
170            self.namespace.as_ref().map_or(0, |_| 1) +
171            self.resource.as_ref().map_or(0, |_| 1) +
172            self.subresource.as_ref().map_or(0, |_| 1) +
173            self.verb.as_ref().map_or(0, |_| 1) +
174            self.version.as_ref().map_or(0, |_| 1),
175        )?;
176        if let Some(value) = &self.field_selector {
177            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "fieldSelector", value)?;
178        }
179        if let Some(value) = &self.group {
180            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "group", value)?;
181        }
182        if let Some(value) = &self.label_selector {
183            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "labelSelector", value)?;
184        }
185        if let Some(value) = &self.name {
186            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
187        }
188        if let Some(value) = &self.namespace {
189            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
190        }
191        if let Some(value) = &self.resource {
192            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resource", value)?;
193        }
194        if let Some(value) = &self.subresource {
195            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "subresource", value)?;
196        }
197        if let Some(value) = &self.verb {
198            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "verb", value)?;
199        }
200        if let Some(value) = &self.version {
201            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "version", value)?;
202        }
203        crate::serde::ser::SerializeStruct::end(state)
204    }
205}
206
207#[cfg(feature = "schemars")]
208impl crate::schemars::JsonSchema for ResourceAttributes {
209    fn schema_name() -> std::borrow::Cow<'static, str> {
210        "io.k8s.api.authorization.v1.ResourceAttributes".into()
211    }
212
213    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
214        crate::schemars::json_schema!({
215            "description": "ResourceAttributes includes the authorization attributes available for resource requests to the Authorizer interface",
216            "type": "object",
217            "properties": {
218                "fieldSelector": ({
219                    let mut schema_obj = __gen.subschema_for::<crate::api::authorization::v1::FieldSelectorAttributes>();
220                    schema_obj.ensure_object().insert("description".into(), "fieldSelector describes the limitation on access based on field.  It can only limit access, not broaden it.".into());
221                    schema_obj
222                }),
223                "group": {
224                    "description": "group is the API Group of the Resource.  \"*\" means all.",
225                    "type": "string",
226                },
227                "labelSelector": ({
228                    let mut schema_obj = __gen.subschema_for::<crate::api::authorization::v1::LabelSelectorAttributes>();
229                    schema_obj.ensure_object().insert("description".into(), "labelSelector describes the limitation on access based on labels.  It can only limit access, not broaden it.".into());
230                    schema_obj
231                }),
232                "name": {
233                    "description": "name is the name of the resource being requested for a \"get\" or deleted for a \"delete\". \"\" (empty) means all.",
234                    "type": "string",
235                },
236                "namespace": {
237                    "description": "namespace is the namespace of the action being requested.  Currently, there is no distinction between no namespace and all namespaces \"\" (empty) is defaulted for LocalSubjectAccessReviews \"\" (empty) is empty for cluster-scoped resources \"\" (empty) means \"all\" for namespace scoped resources from a SubjectAccessReview or SelfSubjectAccessReview",
238                    "type": "string",
239                },
240                "resource": {
241                    "description": "resource is one of the existing resource types.  \"*\" means all.",
242                    "type": "string",
243                },
244                "subresource": {
245                    "description": "subresource is one of the existing resource types.  \"\" means none.",
246                    "type": "string",
247                },
248                "verb": {
249                    "description": "verb is a kubernetes resource API verb, like: get, list, watch, create, update, delete, proxy.  \"*\" means all.",
250                    "type": "string",
251                },
252                "version": {
253                    "description": "version is the API Version of the Resource.  \"*\" means all.",
254                    "type": "string",
255                },
256            },
257        })
258    }
259}
260
261#[cfg(feature = "schemars08")]
262impl crate::schemars08::JsonSchema for ResourceAttributes {
263    fn schema_name() -> std::string::String {
264        "io.k8s.api.authorization.v1.ResourceAttributes".into()
265    }
266
267    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
268        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
269            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
270                description: Some("ResourceAttributes includes the authorization attributes available for resource requests to the Authorizer interface".into()),
271                ..Default::default()
272            })),
273            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
274            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
275                properties: [
276                    (
277                        "fieldSelector".into(),
278                        {
279                            let mut schema_obj = __gen.subschema_for::<crate::api::authorization::v1::FieldSelectorAttributes>().into_object();
280                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
281                                description: Some("fieldSelector describes the limitation on access based on field.  It can only limit access, not broaden it.".into()),
282                                ..Default::default()
283                            }));
284                            crate::schemars08::schema::Schema::Object(schema_obj)
285                        },
286                    ),
287                    (
288                        "group".into(),
289                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
290                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
291                                description: Some("group is the API Group of the Resource.  \"*\" means all.".into()),
292                                ..Default::default()
293                            })),
294                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
295                            ..Default::default()
296                        }),
297                    ),
298                    (
299                        "labelSelector".into(),
300                        {
301                            let mut schema_obj = __gen.subschema_for::<crate::api::authorization::v1::LabelSelectorAttributes>().into_object();
302                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
303                                description: Some("labelSelector describes the limitation on access based on labels.  It can only limit access, not broaden it.".into()),
304                                ..Default::default()
305                            }));
306                            crate::schemars08::schema::Schema::Object(schema_obj)
307                        },
308                    ),
309                    (
310                        "name".into(),
311                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
312                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
313                                description: Some("name is the name of the resource being requested for a \"get\" or deleted for a \"delete\". \"\" (empty) means all.".into()),
314                                ..Default::default()
315                            })),
316                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
317                            ..Default::default()
318                        }),
319                    ),
320                    (
321                        "namespace".into(),
322                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
323                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
324                                description: Some("namespace is the namespace of the action being requested.  Currently, there is no distinction between no namespace and all namespaces \"\" (empty) is defaulted for LocalSubjectAccessReviews \"\" (empty) is empty for cluster-scoped resources \"\" (empty) means \"all\" for namespace scoped resources from a SubjectAccessReview or SelfSubjectAccessReview".into()),
325                                ..Default::default()
326                            })),
327                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
328                            ..Default::default()
329                        }),
330                    ),
331                    (
332                        "resource".into(),
333                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
334                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
335                                description: Some("resource is one of the existing resource types.  \"*\" means all.".into()),
336                                ..Default::default()
337                            })),
338                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
339                            ..Default::default()
340                        }),
341                    ),
342                    (
343                        "subresource".into(),
344                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
345                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
346                                description: Some("subresource is one of the existing resource types.  \"\" means none.".into()),
347                                ..Default::default()
348                            })),
349                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
350                            ..Default::default()
351                        }),
352                    ),
353                    (
354                        "verb".into(),
355                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
356                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
357                                description: Some("verb is a kubernetes resource API verb, like: get, list, watch, create, update, delete, proxy.  \"*\" means all.".into()),
358                                ..Default::default()
359                            })),
360                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
361                            ..Default::default()
362                        }),
363                    ),
364                    (
365                        "version".into(),
366                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
367                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
368                                description: Some("version is the API Version of the Resource.  \"*\" means all.".into()),
369                                ..Default::default()
370                            })),
371                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
372                            ..Default::default()
373                        }),
374                    ),
375                ].into(),
376                ..Default::default()
377            })),
378            ..Default::default()
379        })
380    }
381}