k8s_openapi/v1_30/api/core/v1/
se_linux_options.rs

1// Generated from definition io.k8s.api.core.v1.SELinuxOptions
2
3/// SELinuxOptions are the labels to be applied to the container
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct SELinuxOptions {
6    /// Level is SELinux level label that applies to the container.
7    pub level: Option<String>,
8
9    /// Role is a SELinux role label that applies to the container.
10    pub role: Option<String>,
11
12    /// Type is a SELinux type label that applies to the container.
13    pub type_: Option<String>,
14
15    /// User is a SELinux user label that applies to the container.
16    pub user: Option<String>,
17}
18
19impl crate::DeepMerge for SELinuxOptions {
20    fn merge_from(&mut self, other: Self) {
21        crate::DeepMerge::merge_from(&mut self.level, other.level);
22        crate::DeepMerge::merge_from(&mut self.role, other.role);
23        crate::DeepMerge::merge_from(&mut self.type_, other.type_);
24        crate::DeepMerge::merge_from(&mut self.user, other.user);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for SELinuxOptions {
29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30        #[allow(non_camel_case_types)]
31        enum Field {
32            Key_level,
33            Key_role,
34            Key_type_,
35            Key_user,
36            Other,
37        }
38
39        impl<'de> crate::serde::Deserialize<'de> for Field {
40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41                struct Visitor;
42
43                impl crate::serde::de::Visitor<'_> for Visitor {
44                    type Value = Field;
45
46                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47                        f.write_str("field identifier")
48                    }
49
50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51                        Ok(match v {
52                            "level" => Field::Key_level,
53                            "role" => Field::Key_role,
54                            "type" => Field::Key_type_,
55                            "user" => Field::Key_user,
56                            _ => Field::Other,
57                        })
58                    }
59                }
60
61                deserializer.deserialize_identifier(Visitor)
62            }
63        }
64
65        struct Visitor;
66
67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68            type Value = SELinuxOptions;
69
70            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71                f.write_str("SELinuxOptions")
72            }
73
74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75                let mut value_level: Option<String> = None;
76                let mut value_role: Option<String> = None;
77                let mut value_type_: Option<String> = None;
78                let mut value_user: Option<String> = None;
79
80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81                    match key {
82                        Field::Key_level => value_level = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_role => value_role = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Key_type_ => value_type_ = crate::serde::de::MapAccess::next_value(&mut map)?,
85                        Field::Key_user => value_user = crate::serde::de::MapAccess::next_value(&mut map)?,
86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
87                    }
88                }
89
90                Ok(SELinuxOptions {
91                    level: value_level,
92                    role: value_role,
93                    type_: value_type_,
94                    user: value_user,
95                })
96            }
97        }
98
99        deserializer.deserialize_struct(
100            "SELinuxOptions",
101            &[
102                "level",
103                "role",
104                "type",
105                "user",
106            ],
107            Visitor,
108        )
109    }
110}
111
112impl crate::serde::Serialize for SELinuxOptions {
113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
114        let mut state = serializer.serialize_struct(
115            "SELinuxOptions",
116            self.level.as_ref().map_or(0, |_| 1) +
117            self.role.as_ref().map_or(0, |_| 1) +
118            self.type_.as_ref().map_or(0, |_| 1) +
119            self.user.as_ref().map_or(0, |_| 1),
120        )?;
121        if let Some(value) = &self.level {
122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "level", value)?;
123        }
124        if let Some(value) = &self.role {
125            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "role", value)?;
126        }
127        if let Some(value) = &self.type_ {
128            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", value)?;
129        }
130        if let Some(value) = &self.user {
131            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "user", value)?;
132        }
133        crate::serde::ser::SerializeStruct::end(state)
134    }
135}
136
137#[cfg(feature = "schemars")]
138impl crate::schemars::JsonSchema for SELinuxOptions {
139    fn schema_name() -> String {
140        "io.k8s.api.core.v1.SELinuxOptions".to_owned()
141    }
142
143    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
144        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
145            metadata: Some(Box::new(crate::schemars::schema::Metadata {
146                description: Some("SELinuxOptions are the labels to be applied to the container".to_owned()),
147                ..Default::default()
148            })),
149            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
150            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
151                properties: [
152                    (
153                        "level".to_owned(),
154                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
155                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
156                                description: Some("Level is SELinux level label that applies to the container.".to_owned()),
157                                ..Default::default()
158                            })),
159                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
160                            ..Default::default()
161                        }),
162                    ),
163                    (
164                        "role".to_owned(),
165                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
166                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
167                                description: Some("Role is a SELinux role label that applies to the container.".to_owned()),
168                                ..Default::default()
169                            })),
170                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
171                            ..Default::default()
172                        }),
173                    ),
174                    (
175                        "type".to_owned(),
176                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
177                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
178                                description: Some("Type is a SELinux type label that applies to the container.".to_owned()),
179                                ..Default::default()
180                            })),
181                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
182                            ..Default::default()
183                        }),
184                    ),
185                    (
186                        "user".to_owned(),
187                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
188                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
189                                description: Some("User is a SELinux user label that applies to the container.".to_owned()),
190                                ..Default::default()
191                            })),
192                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
193                            ..Default::default()
194                        }),
195                    ),
196                ].into(),
197                ..Default::default()
198            })),
199            ..Default::default()
200        })
201    }
202}