k8s_openapi/v1_30/api/authorization/v1/
subject_access_review_spec.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct SubjectAccessReviewSpec {
6 pub extra: Option<std::collections::BTreeMap<std::string::String, std::vec::Vec<std::string::String>>>,
8
9 pub groups: Option<std::vec::Vec<std::string::String>>,
11
12 pub non_resource_attributes: Option<crate::api::authorization::v1::NonResourceAttributes>,
14
15 pub resource_attributes: Option<crate::api::authorization::v1::ResourceAttributes>,
17
18 pub uid: Option<std::string::String>,
20
21 pub user: Option<std::string::String>,
23}
24
25impl crate::DeepMerge for SubjectAccessReviewSpec {
26 fn merge_from(&mut self, other: Self) {
27 crate::merge_strategies::map::granular(&mut self.extra, other.extra, |current_item, other_item| {
28 crate::merge_strategies::list::atomic(current_item, other_item);
29 });
30 crate::merge_strategies::list::atomic(&mut self.groups, other.groups);
31 crate::DeepMerge::merge_from(&mut self.non_resource_attributes, other.non_resource_attributes);
32 crate::DeepMerge::merge_from(&mut self.resource_attributes, other.resource_attributes);
33 crate::DeepMerge::merge_from(&mut self.uid, other.uid);
34 crate::DeepMerge::merge_from(&mut self.user, other.user);
35 }
36}
37
38impl<'de> crate::serde::Deserialize<'de> for SubjectAccessReviewSpec {
39 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
40 #[allow(non_camel_case_types)]
41 enum Field {
42 Key_extra,
43 Key_groups,
44 Key_non_resource_attributes,
45 Key_resource_attributes,
46 Key_uid,
47 Key_user,
48 Other,
49 }
50
51 impl<'de> crate::serde::Deserialize<'de> for Field {
52 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
53 struct Visitor;
54
55 impl crate::serde::de::Visitor<'_> for Visitor {
56 type Value = Field;
57
58 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
59 f.write_str("field identifier")
60 }
61
62 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
63 Ok(match v {
64 "extra" => Field::Key_extra,
65 "groups" => Field::Key_groups,
66 "nonResourceAttributes" => Field::Key_non_resource_attributes,
67 "resourceAttributes" => Field::Key_resource_attributes,
68 "uid" => Field::Key_uid,
69 "user" => Field::Key_user,
70 _ => Field::Other,
71 })
72 }
73 }
74
75 deserializer.deserialize_identifier(Visitor)
76 }
77 }
78
79 struct Visitor;
80
81 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
82 type Value = SubjectAccessReviewSpec;
83
84 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
85 f.write_str("SubjectAccessReviewSpec")
86 }
87
88 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
89 let mut value_extra: Option<std::collections::BTreeMap<std::string::String, std::vec::Vec<std::string::String>>> = None;
90 let mut value_groups: Option<std::vec::Vec<std::string::String>> = None;
91 let mut value_non_resource_attributes: Option<crate::api::authorization::v1::NonResourceAttributes> = None;
92 let mut value_resource_attributes: Option<crate::api::authorization::v1::ResourceAttributes> = None;
93 let mut value_uid: Option<std::string::String> = None;
94 let mut value_user: Option<std::string::String> = None;
95
96 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
97 match key {
98 Field::Key_extra => value_extra = crate::serde::de::MapAccess::next_value(&mut map)?,
99 Field::Key_groups => value_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
100 Field::Key_non_resource_attributes => value_non_resource_attributes = crate::serde::de::MapAccess::next_value(&mut map)?,
101 Field::Key_resource_attributes => value_resource_attributes = crate::serde::de::MapAccess::next_value(&mut map)?,
102 Field::Key_uid => value_uid = crate::serde::de::MapAccess::next_value(&mut map)?,
103 Field::Key_user => value_user = crate::serde::de::MapAccess::next_value(&mut map)?,
104 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
105 }
106 }
107
108 Ok(SubjectAccessReviewSpec {
109 extra: value_extra,
110 groups: value_groups,
111 non_resource_attributes: value_non_resource_attributes,
112 resource_attributes: value_resource_attributes,
113 uid: value_uid,
114 user: value_user,
115 })
116 }
117 }
118
119 deserializer.deserialize_struct(
120 "SubjectAccessReviewSpec",
121 &[
122 "extra",
123 "groups",
124 "nonResourceAttributes",
125 "resourceAttributes",
126 "uid",
127 "user",
128 ],
129 Visitor,
130 )
131 }
132}
133
134impl crate::serde::Serialize for SubjectAccessReviewSpec {
135 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
136 let mut state = serializer.serialize_struct(
137 "SubjectAccessReviewSpec",
138 self.extra.as_ref().map_or(0, |_| 1) +
139 self.groups.as_ref().map_or(0, |_| 1) +
140 self.non_resource_attributes.as_ref().map_or(0, |_| 1) +
141 self.resource_attributes.as_ref().map_or(0, |_| 1) +
142 self.uid.as_ref().map_or(0, |_| 1) +
143 self.user.as_ref().map_or(0, |_| 1),
144 )?;
145 if let Some(value) = &self.extra {
146 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "extra", value)?;
147 }
148 if let Some(value) = &self.groups {
149 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "groups", value)?;
150 }
151 if let Some(value) = &self.non_resource_attributes {
152 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nonResourceAttributes", value)?;
153 }
154 if let Some(value) = &self.resource_attributes {
155 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceAttributes", value)?;
156 }
157 if let Some(value) = &self.uid {
158 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "uid", value)?;
159 }
160 if let Some(value) = &self.user {
161 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "user", value)?;
162 }
163 crate::serde::ser::SerializeStruct::end(state)
164 }
165}
166
167#[cfg(feature = "schemars")]
168impl crate::schemars::JsonSchema for SubjectAccessReviewSpec {
169 fn schema_name() -> std::borrow::Cow<'static, str> {
170 "io.k8s.api.authorization.v1.SubjectAccessReviewSpec".into()
171 }
172
173 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
174 crate::schemars::json_schema!({
175 "description": "SubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAuthorizationAttributes and NonResourceAuthorizationAttributes must be set",
176 "type": "object",
177 "properties": {
178 "extra": {
179 "description": "Extra corresponds to the user.Info.GetExtra() method from the authenticator. Since that is input to the authorizer it needs a reflection here.",
180 "type": "object",
181 "additionalProperties": {
182 "type": "array",
183 "items": {
184 "type": "string",
185 },
186 },
187 },
188 "groups": {
189 "description": "Groups is the groups you're testing for.",
190 "type": "array",
191 "items": {
192 "type": "string",
193 },
194 },
195 "nonResourceAttributes": ({
196 let mut schema_obj = __gen.subschema_for::<crate::api::authorization::v1::NonResourceAttributes>();
197 schema_obj.ensure_object().insert("description".into(), "NonResourceAttributes describes information for a non-resource access request".into());
198 schema_obj
199 }),
200 "resourceAttributes": ({
201 let mut schema_obj = __gen.subschema_for::<crate::api::authorization::v1::ResourceAttributes>();
202 schema_obj.ensure_object().insert("description".into(), "ResourceAuthorizationAttributes describes information for a resource access request".into());
203 schema_obj
204 }),
205 "uid": {
206 "description": "UID information about the requesting user.",
207 "type": "string",
208 },
209 "user": {
210 "description": "User is the user you're testing for. If you specify \"User\" but not \"Groups\", then is it interpreted as \"What if User were not a member of any groups",
211 "type": "string",
212 },
213 },
214 })
215 }
216}