k8s_openapi/v1_34/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}