k8s_openapi/v1_34/api/authentication/v1/
user_info.rs

1// Generated from definition io.k8s.api.authentication.v1.UserInfo
2
3/// UserInfo holds the information about the user needed to implement the user.Info interface.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct UserInfo {
6    /// Any additional information provided by the authenticator.
7    pub extra: Option<std::collections::BTreeMap<std::string::String, std::vec::Vec<std::string::String>>>,
8
9    /// The names of groups this user is a part of.
10    pub groups: Option<std::vec::Vec<std::string::String>>,
11
12    /// A unique value that identifies this user across time. If this user is deleted and another user by the same name is added, they will have different UIDs.
13    pub uid: Option<std::string::String>,
14
15    /// The name that uniquely identifies this user among all active users.
16    pub username: Option<std::string::String>,
17}
18
19impl crate::DeepMerge for UserInfo {
20    fn merge_from(&mut self, other: Self) {
21        crate::merge_strategies::map::granular(&mut self.extra, other.extra, |current_item, other_item| {
22            crate::merge_strategies::list::atomic(current_item, other_item);
23        });
24        crate::merge_strategies::list::atomic(&mut self.groups, other.groups);
25        crate::DeepMerge::merge_from(&mut self.uid, other.uid);
26        crate::DeepMerge::merge_from(&mut self.username, other.username);
27    }
28}
29
30impl<'de> crate::serde::Deserialize<'de> for UserInfo {
31    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
32        #[allow(non_camel_case_types)]
33        enum Field {
34            Key_extra,
35            Key_groups,
36            Key_uid,
37            Key_username,
38            Other,
39        }
40
41        impl<'de> crate::serde::Deserialize<'de> for Field {
42            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
43                struct Visitor;
44
45                impl crate::serde::de::Visitor<'_> for Visitor {
46                    type Value = Field;
47
48                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
49                        f.write_str("field identifier")
50                    }
51
52                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
53                        Ok(match v {
54                            "extra" => Field::Key_extra,
55                            "groups" => Field::Key_groups,
56                            "uid" => Field::Key_uid,
57                            "username" => Field::Key_username,
58                            _ => Field::Other,
59                        })
60                    }
61                }
62
63                deserializer.deserialize_identifier(Visitor)
64            }
65        }
66
67        struct Visitor;
68
69        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
70            type Value = UserInfo;
71
72            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
73                f.write_str("UserInfo")
74            }
75
76            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
77                let mut value_extra: Option<std::collections::BTreeMap<std::string::String, std::vec::Vec<std::string::String>>> = None;
78                let mut value_groups: Option<std::vec::Vec<std::string::String>> = None;
79                let mut value_uid: Option<std::string::String> = None;
80                let mut value_username: Option<std::string::String> = None;
81
82                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
83                    match key {
84                        Field::Key_extra => value_extra = crate::serde::de::MapAccess::next_value(&mut map)?,
85                        Field::Key_groups => value_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
86                        Field::Key_uid => value_uid = crate::serde::de::MapAccess::next_value(&mut map)?,
87                        Field::Key_username => value_username = crate::serde::de::MapAccess::next_value(&mut map)?,
88                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
89                    }
90                }
91
92                Ok(UserInfo {
93                    extra: value_extra,
94                    groups: value_groups,
95                    uid: value_uid,
96                    username: value_username,
97                })
98            }
99        }
100
101        deserializer.deserialize_struct(
102            "UserInfo",
103            &[
104                "extra",
105                "groups",
106                "uid",
107                "username",
108            ],
109            Visitor,
110        )
111    }
112}
113
114impl crate::serde::Serialize for UserInfo {
115    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
116        let mut state = serializer.serialize_struct(
117            "UserInfo",
118            self.extra.as_ref().map_or(0, |_| 1) +
119            self.groups.as_ref().map_or(0, |_| 1) +
120            self.uid.as_ref().map_or(0, |_| 1) +
121            self.username.as_ref().map_or(0, |_| 1),
122        )?;
123        if let Some(value) = &self.extra {
124            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "extra", value)?;
125        }
126        if let Some(value) = &self.groups {
127            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "groups", value)?;
128        }
129        if let Some(value) = &self.uid {
130            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "uid", value)?;
131        }
132        if let Some(value) = &self.username {
133            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "username", value)?;
134        }
135        crate::serde::ser::SerializeStruct::end(state)
136    }
137}
138
139#[cfg(feature = "schemars")]
140impl crate::schemars::JsonSchema for UserInfo {
141    fn schema_name() -> std::borrow::Cow<'static, str> {
142        "io.k8s.api.authentication.v1.UserInfo".into()
143    }
144
145    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
146        crate::schemars::json_schema!({
147            "description": "UserInfo holds the information about the user needed to implement the user.Info interface.",
148            "type": "object",
149            "properties": {
150                "extra": {
151                    "description": "Any additional information provided by the authenticator.",
152                    "type": "object",
153                    "additionalProperties": {
154                        "type": "array",
155                        "items": {
156                            "type": "string",
157                        },
158                    },
159                },
160                "groups": {
161                    "description": "The names of groups this user is a part of.",
162                    "type": "array",
163                    "items": {
164                        "type": "string",
165                    },
166                },
167                "uid": {
168                    "description": "A unique value that identifies this user across time. If this user is deleted and another user by the same name is added, they will have different UIDs.",
169                    "type": "string",
170                },
171                "username": {
172                    "description": "The name that uniquely identifies this user among all active users.",
173                    "type": "string",
174                },
175            },
176        })
177    }
178}