k8s_openapi/v1_35/api/core/v1/
linux_container_user.rs

1// Generated from definition io.k8s.api.core.v1.LinuxContainerUser
2
3/// LinuxContainerUser represents user identity information in Linux containers
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct LinuxContainerUser {
6    /// GID is the primary gid initially attached to the first process in the container
7    pub gid: i64,
8
9    /// SupplementalGroups are the supplemental groups initially attached to the first process in the container
10    pub supplemental_groups: Option<std::vec::Vec<i64>>,
11
12    /// UID is the primary uid initially attached to the first process in the container
13    pub uid: i64,
14}
15
16impl crate::DeepMerge for LinuxContainerUser {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.gid, other.gid);
19        crate::merge_strategies::list::atomic(&mut self.supplemental_groups, other.supplemental_groups);
20        crate::DeepMerge::merge_from(&mut self.uid, other.uid);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for LinuxContainerUser {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_gid,
29            Key_supplemental_groups,
30            Key_uid,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "gid" => Field::Key_gid,
48                            "supplementalGroups" => Field::Key_supplemental_groups,
49                            "uid" => Field::Key_uid,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = LinuxContainerUser;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("LinuxContainerUser")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_gid: Option<i64> = None;
70                let mut value_supplemental_groups: Option<std::vec::Vec<i64>> = None;
71                let mut value_uid: Option<i64> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_gid => value_gid = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_supplemental_groups => value_supplemental_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_uid => value_uid = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(LinuxContainerUser {
83                    gid: value_gid.unwrap_or_default(),
84                    supplemental_groups: value_supplemental_groups,
85                    uid: value_uid.unwrap_or_default(),
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "LinuxContainerUser",
92            &[
93                "gid",
94                "supplementalGroups",
95                "uid",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for LinuxContainerUser {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "LinuxContainerUser",
106            2 +
107            self.supplemental_groups.as_ref().map_or(0, |_| 1),
108        )?;
109        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "gid", &self.gid)?;
110        if let Some(value) = &self.supplemental_groups {
111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "supplementalGroups", value)?;
112        }
113        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "uid", &self.uid)?;
114        crate::serde::ser::SerializeStruct::end(state)
115    }
116}
117
118#[cfg(feature = "schemars")]
119impl crate::schemars::JsonSchema for LinuxContainerUser {
120    fn schema_name() -> std::borrow::Cow<'static, str> {
121        "io.k8s.api.core.v1.LinuxContainerUser".into()
122    }
123
124    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
125        crate::schemars::json_schema!({
126            "description": "LinuxContainerUser represents user identity information in Linux containers",
127            "type": "object",
128            "properties": {
129                "gid": {
130                    "description": "GID is the primary gid initially attached to the first process in the container",
131                    "type": "integer",
132                    "format": "int64",
133                },
134                "supplementalGroups": {
135                    "description": "SupplementalGroups are the supplemental groups initially attached to the first process in the container",
136                    "type": "array",
137                    "items": {
138                        "type": "integer",
139                        "format": "int64",
140                    },
141                },
142                "uid": {
143                    "description": "UID is the primary uid initially attached to the first process in the container",
144                    "type": "integer",
145                    "format": "int64",
146                },
147            },
148            "required": [
149                "gid",
150                "uid",
151            ],
152        })
153    }
154}