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