k8s_openapi/v1_31/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    ///
8    /// This field  is alpha-level. To use this field, you must enable the `AuthorizeWithSelectors` feature gate (disabled by default).
9    pub field_selector: Option<crate::api::authorization::v1::FieldSelectorAttributes>,
10
11    /// Group is the API Group of the Resource.  "*" means all.
12    pub group: Option<std::string::String>,
13
14    /// labelSelector describes the limitation on access based on labels.  It can only limit access, not broaden it.
15    ///
16    /// This field  is alpha-level. To use this field, you must enable the `AuthorizeWithSelectors` feature gate (disabled by default).
17    pub label_selector: Option<crate::api::authorization::v1::LabelSelectorAttributes>,
18
19    /// Name is the name of the resource being requested for a "get" or deleted for a "delete". "" (empty) means all.
20    pub name: Option<std::string::String>,
21
22    /// 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
23    pub namespace: Option<std::string::String>,
24
25    /// Resource is one of the existing resource types.  "*" means all.
26    pub resource: Option<std::string::String>,
27
28    /// Subresource is one of the existing resource types.  "" means none.
29    pub subresource: Option<std::string::String>,
30
31    /// Verb is a kubernetes resource API verb, like: get, list, watch, create, update, delete, proxy.  "*" means all.
32    pub verb: Option<std::string::String>,
33
34    /// Version is the API Version of the Resource.  "*" means all.
35    pub version: Option<std::string::String>,
36}
37
38impl crate::DeepMerge for ResourceAttributes {
39    fn merge_from(&mut self, other: Self) {
40        crate::DeepMerge::merge_from(&mut self.field_selector, other.field_selector);
41        crate::DeepMerge::merge_from(&mut self.group, other.group);
42        crate::DeepMerge::merge_from(&mut self.label_selector, other.label_selector);
43        crate::DeepMerge::merge_from(&mut self.name, other.name);
44        crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
45        crate::DeepMerge::merge_from(&mut self.resource, other.resource);
46        crate::DeepMerge::merge_from(&mut self.subresource, other.subresource);
47        crate::DeepMerge::merge_from(&mut self.verb, other.verb);
48        crate::DeepMerge::merge_from(&mut self.version, other.version);
49    }
50}
51
52impl<'de> crate::serde::Deserialize<'de> for ResourceAttributes {
53    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
54        #[allow(non_camel_case_types)]
55        enum Field {
56            Key_field_selector,
57            Key_group,
58            Key_label_selector,
59            Key_name,
60            Key_namespace,
61            Key_resource,
62            Key_subresource,
63            Key_verb,
64            Key_version,
65            Other,
66        }
67
68        impl<'de> crate::serde::Deserialize<'de> for Field {
69            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
70                struct Visitor;
71
72                impl crate::serde::de::Visitor<'_> for Visitor {
73                    type Value = Field;
74
75                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
76                        f.write_str("field identifier")
77                    }
78
79                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
80                        Ok(match v {
81                            "fieldSelector" => Field::Key_field_selector,
82                            "group" => Field::Key_group,
83                            "labelSelector" => Field::Key_label_selector,
84                            "name" => Field::Key_name,
85                            "namespace" => Field::Key_namespace,
86                            "resource" => Field::Key_resource,
87                            "subresource" => Field::Key_subresource,
88                            "verb" => Field::Key_verb,
89                            "version" => Field::Key_version,
90                            _ => Field::Other,
91                        })
92                    }
93                }
94
95                deserializer.deserialize_identifier(Visitor)
96            }
97        }
98
99        struct Visitor;
100
101        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
102            type Value = ResourceAttributes;
103
104            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
105                f.write_str("ResourceAttributes")
106            }
107
108            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
109                let mut value_field_selector: Option<crate::api::authorization::v1::FieldSelectorAttributes> = None;
110                let mut value_group: Option<std::string::String> = None;
111                let mut value_label_selector: Option<crate::api::authorization::v1::LabelSelectorAttributes> = None;
112                let mut value_name: Option<std::string::String> = None;
113                let mut value_namespace: Option<std::string::String> = None;
114                let mut value_resource: Option<std::string::String> = None;
115                let mut value_subresource: Option<std::string::String> = None;
116                let mut value_verb: Option<std::string::String> = None;
117                let mut value_version: Option<std::string::String> = None;
118
119                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
120                    match key {
121                        Field::Key_field_selector => value_field_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
122                        Field::Key_group => value_group = crate::serde::de::MapAccess::next_value(&mut map)?,
123                        Field::Key_label_selector => value_label_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
124                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
125                        Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
126                        Field::Key_resource => value_resource = crate::serde::de::MapAccess::next_value(&mut map)?,
127                        Field::Key_subresource => value_subresource = crate::serde::de::MapAccess::next_value(&mut map)?,
128                        Field::Key_verb => value_verb = crate::serde::de::MapAccess::next_value(&mut map)?,
129                        Field::Key_version => value_version = crate::serde::de::MapAccess::next_value(&mut map)?,
130                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
131                    }
132                }
133
134                Ok(ResourceAttributes {
135                    field_selector: value_field_selector,
136                    group: value_group,
137                    label_selector: value_label_selector,
138                    name: value_name,
139                    namespace: value_namespace,
140                    resource: value_resource,
141                    subresource: value_subresource,
142                    verb: value_verb,
143                    version: value_version,
144                })
145            }
146        }
147
148        deserializer.deserialize_struct(
149            "ResourceAttributes",
150            &[
151                "fieldSelector",
152                "group",
153                "labelSelector",
154                "name",
155                "namespace",
156                "resource",
157                "subresource",
158                "verb",
159                "version",
160            ],
161            Visitor,
162        )
163    }
164}
165
166impl crate::serde::Serialize for ResourceAttributes {
167    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
168        let mut state = serializer.serialize_struct(
169            "ResourceAttributes",
170            self.field_selector.as_ref().map_or(0, |_| 1) +
171            self.group.as_ref().map_or(0, |_| 1) +
172            self.label_selector.as_ref().map_or(0, |_| 1) +
173            self.name.as_ref().map_or(0, |_| 1) +
174            self.namespace.as_ref().map_or(0, |_| 1) +
175            self.resource.as_ref().map_or(0, |_| 1) +
176            self.subresource.as_ref().map_or(0, |_| 1) +
177            self.verb.as_ref().map_or(0, |_| 1) +
178            self.version.as_ref().map_or(0, |_| 1),
179        )?;
180        if let Some(value) = &self.field_selector {
181            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "fieldSelector", value)?;
182        }
183        if let Some(value) = &self.group {
184            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "group", value)?;
185        }
186        if let Some(value) = &self.label_selector {
187            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "labelSelector", value)?;
188        }
189        if let Some(value) = &self.name {
190            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
191        }
192        if let Some(value) = &self.namespace {
193            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
194        }
195        if let Some(value) = &self.resource {
196            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resource", value)?;
197        }
198        if let Some(value) = &self.subresource {
199            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "subresource", value)?;
200        }
201        if let Some(value) = &self.verb {
202            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "verb", value)?;
203        }
204        if let Some(value) = &self.version {
205            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "version", value)?;
206        }
207        crate::serde::ser::SerializeStruct::end(state)
208    }
209}
210
211#[cfg(feature = "schemars")]
212impl crate::schemars::JsonSchema for ResourceAttributes {
213    fn schema_name() -> std::borrow::Cow<'static, str> {
214        "io.k8s.api.authorization.v1.ResourceAttributes".into()
215    }
216
217    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
218        crate::schemars::json_schema!({
219            "description": "ResourceAttributes includes the authorization attributes available for resource requests to the Authorizer interface",
220            "type": "object",
221            "properties": {
222                "fieldSelector": ({
223                    let mut schema_obj = __gen.subschema_for::<crate::api::authorization::v1::FieldSelectorAttributes>();
224                    schema_obj.ensure_object().insert("description".into(), "fieldSelector describes the limitation on access based on field.  It can only limit access, not broaden it.\n\nThis field  is alpha-level. To use this field, you must enable the `AuthorizeWithSelectors` feature gate (disabled by default).".into());
225                    schema_obj
226                }),
227                "group": {
228                    "description": "Group is the API Group of the Resource.  \"*\" means all.",
229                    "type": "string",
230                },
231                "labelSelector": ({
232                    let mut schema_obj = __gen.subschema_for::<crate::api::authorization::v1::LabelSelectorAttributes>();
233                    schema_obj.ensure_object().insert("description".into(), "labelSelector describes the limitation on access based on labels.  It can only limit access, not broaden it.\n\nThis field  is alpha-level. To use this field, you must enable the `AuthorizeWithSelectors` feature gate (disabled by default).".into());
234                    schema_obj
235                }),
236                "name": {
237                    "description": "Name is the name of the resource being requested for a \"get\" or deleted for a \"delete\". \"\" (empty) means all.",
238                    "type": "string",
239                },
240                "namespace": {
241                    "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",
242                    "type": "string",
243                },
244                "resource": {
245                    "description": "Resource is one of the existing resource types.  \"*\" means all.",
246                    "type": "string",
247                },
248                "subresource": {
249                    "description": "Subresource is one of the existing resource types.  \"\" means none.",
250                    "type": "string",
251                },
252                "verb": {
253                    "description": "Verb is a kubernetes resource API verb, like: get, list, watch, create, update, delete, proxy.  \"*\" means all.",
254                    "type": "string",
255                },
256                "version": {
257                    "description": "Version is the API Version of the Resource.  \"*\" means all.",
258                    "type": "string",
259                },
260            },
261        })
262    }
263}