openshift_openapi/v4_5/api/user/v1/
user_identity_mapping.rs

1// Generated from definition com.github.openshift.api.user.v1.UserIdentityMapping
2
3/// UserIdentityMapping maps a user to an identity
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct UserIdentityMapping {
6    /// Identity is a reference to an identity
7    pub identity: Option<k8s_openapi::api::core::v1::ObjectReference>,
8
9    /// Standard object's metadata.
10    pub metadata: k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta,
11
12    /// User is a reference to a user
13    pub user: Option<k8s_openapi::api::core::v1::ObjectReference>,
14}
15
16// Begin user.openshift.io/v1/UserIdentityMapping
17
18// Generated from operation createUserOpenshiftIoV1UserIdentityMapping
19
20impl UserIdentityMapping {
21    /// create an UserIdentityMapping
22    ///
23    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::CreateResponse`]`<Self>>` constructor, or [`k8s_openapi::CreateResponse`]`<Self>` directly, to parse the HTTP response.
24    ///
25    /// # Arguments
26    ///
27    /// * `body`
28    ///
29    /// * `optional`
30    ///
31    ///     Optional parameters. Use `Default::default()` to not pass any.
32    #[cfg(feature = "api")]
33    pub fn create_user_identity_mapping(
34        body: &crate::api::user::v1::UserIdentityMapping,
35        optional: k8s_openapi::CreateOptional<'_>,
36    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::CreateResponse<Self>>), k8s_openapi::RequestError> {
37        let __url = "/apis/user.openshift.io/v1/useridentitymappings?".to_owned();
38        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
39        optional.__serialize(&mut __query_pairs);
40        let __url = __query_pairs.finish();
41
42        let __request = http::Request::post(__url);
43        let __body = serde_json::to_vec(body).map_err(k8s_openapi::RequestError::Json)?;
44        let __request = __request.header(http::header::CONTENT_TYPE, http::header::HeaderValue::from_static("application/json"));
45        match __request.body(__body) {
46            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
47            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
48        }
49    }
50}
51
52// Generated from operation deleteUserOpenshiftIoV1UserIdentityMapping
53
54impl UserIdentityMapping {
55    /// delete an UserIdentityMapping
56    ///
57    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::DeleteResponse`]`<Self>>` constructor, or [`k8s_openapi::DeleteResponse`]`<Self>` directly, to parse the HTTP response.
58    ///
59    /// # Arguments
60    ///
61    /// * `name`
62    ///
63    ///     name of the UserIdentityMapping
64    ///
65    /// * `optional`
66    ///
67    ///     Optional parameters. Use `Default::default()` to not pass any.
68    #[cfg(feature = "api")]
69    pub fn delete_user_identity_mapping(
70        name: &str,
71        optional: k8s_openapi::DeleteOptional<'_>,
72    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::DeleteResponse<Self>>), k8s_openapi::RequestError> {
73        let __url = format!("/apis/user.openshift.io/v1/useridentitymappings/{name}",
74            name = k8s_openapi::percent_encoding::percent_encode(name.as_bytes(), k8s_openapi::percent_encoding2::PATH_SEGMENT_ENCODE_SET),
75        );
76
77        let __request = http::Request::delete(__url);
78        let __body = serde_json::to_vec(&optional).map_err(k8s_openapi::RequestError::Json)?;
79        let __request = __request.header(http::header::CONTENT_TYPE, http::header::HeaderValue::from_static("application/json"));
80        match __request.body(__body) {
81            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
82            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
83        }
84    }
85}
86
87// Generated from operation patchUserOpenshiftIoV1UserIdentityMapping
88
89impl UserIdentityMapping {
90    /// partially update the specified UserIdentityMapping
91    ///
92    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::PatchResponse`]`<Self>>` constructor, or [`k8s_openapi::PatchResponse`]`<Self>` directly, to parse the HTTP response.
93    ///
94    /// # Arguments
95    ///
96    /// * `name`
97    ///
98    ///     name of the UserIdentityMapping
99    ///
100    /// * `body`
101    ///
102    /// * `optional`
103    ///
104    ///     Optional parameters. Use `Default::default()` to not pass any.
105    #[cfg(feature = "api")]
106    pub fn patch_user_identity_mapping(
107        name: &str,
108        body: &k8s_openapi::apimachinery::pkg::apis::meta::v1::Patch,
109        optional: k8s_openapi::PatchOptional<'_>,
110    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::PatchResponse<Self>>), k8s_openapi::RequestError> {
111        let __url = format!("/apis/user.openshift.io/v1/useridentitymappings/{name}?",
112            name = k8s_openapi::percent_encoding::percent_encode(name.as_bytes(), k8s_openapi::percent_encoding2::PATH_SEGMENT_ENCODE_SET),
113        );
114        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
115        optional.__serialize(&mut __query_pairs);
116        let __url = __query_pairs.finish();
117
118        let __request = http::Request::patch(__url);
119        let __body = serde_json::to_vec(body).map_err(k8s_openapi::RequestError::Json)?;
120        let __request = __request.header(http::header::CONTENT_TYPE, http::header::HeaderValue::from_static(match body {
121            k8s_openapi::apimachinery::pkg::apis::meta::v1::Patch::Json(_) => "application/json-patch+json",
122            k8s_openapi::apimachinery::pkg::apis::meta::v1::Patch::Merge(_) => "application/merge-patch+json",
123            k8s_openapi::apimachinery::pkg::apis::meta::v1::Patch::StrategicMerge(_) => "application/strategic-merge-patch+json",
124        }));
125        match __request.body(__body) {
126            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
127            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
128        }
129    }
130}
131
132// Generated from operation readUserOpenshiftIoV1UserIdentityMapping
133
134impl UserIdentityMapping {
135    /// read the specified UserIdentityMapping
136    ///
137    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`ReadUserIdentityMappingResponse`]`>` constructor, or [`ReadUserIdentityMappingResponse`] directly, to parse the HTTP response.
138    ///
139    /// # Arguments
140    ///
141    /// * `name`
142    ///
143    ///     name of the UserIdentityMapping
144    ///
145    /// * `optional`
146    ///
147    ///     Optional parameters. Use `Default::default()` to not pass any.
148    #[cfg(feature = "api")]
149    pub fn read_user_identity_mapping(
150        name: &str,
151        optional: ReadUserIdentityMappingOptional<'_>,
152    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<ReadUserIdentityMappingResponse>), k8s_openapi::RequestError> {
153        let ReadUserIdentityMappingOptional {
154            pretty,
155        } = optional;
156        let __url = format!("/apis/user.openshift.io/v1/useridentitymappings/{name}?",
157            name = k8s_openapi::percent_encoding::percent_encode(name.as_bytes(), k8s_openapi::percent_encoding2::PATH_SEGMENT_ENCODE_SET),
158        );
159        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
160        if let Some(pretty) = pretty {
161            __query_pairs.append_pair("pretty", pretty);
162        }
163        let __url = __query_pairs.finish();
164
165        let __request = http::Request::get(__url);
166        let __body = vec![];
167        match __request.body(__body) {
168            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
169            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
170        }
171    }
172}
173
174/// Optional parameters of [`UserIdentityMapping::read_user_identity_mapping`]
175#[cfg(feature = "api")]
176#[derive(Clone, Copy, Debug, Default)]
177pub struct ReadUserIdentityMappingOptional<'a> {
178    /// If 'true', then the output is pretty printed.
179    pub pretty: Option<&'a str>,
180}
181
182/// Use `<ReadUserIdentityMappingResponse as Response>::try_from_parts` to parse the HTTP response body of [`UserIdentityMapping::read_user_identity_mapping`]
183#[cfg(feature = "api")]
184#[derive(Debug)]
185pub enum ReadUserIdentityMappingResponse {
186    Ok(crate::api::user::v1::UserIdentityMapping),
187    Other(Result<Option<serde_json::Value>, serde_json::Error>),
188}
189
190#[cfg(feature = "api")]
191impl k8s_openapi::Response for ReadUserIdentityMappingResponse {
192    fn try_from_parts(status_code: http::StatusCode, buf: &[u8]) -> Result<(Self, usize), k8s_openapi::ResponseError> {
193        match status_code {
194            http::StatusCode::OK => {
195                let result = match serde_json::from_slice(buf) {
196                    Ok(value) => value,
197                    Err(ref err) if err.is_eof() => return Err(k8s_openapi::ResponseError::NeedMoreData),
198                    Err(err) => return Err(k8s_openapi::ResponseError::Json(err)),
199                };
200                Ok((ReadUserIdentityMappingResponse::Ok(result), buf.len()))
201            },
202            _ => {
203                let (result, read) =
204                    if buf.is_empty() {
205                        (Ok(None), 0)
206                    }
207                    else {
208                        match serde_json::from_slice(buf) {
209                            Ok(value) => (Ok(Some(value)), buf.len()),
210                            Err(ref err) if err.is_eof() => return Err(k8s_openapi::ResponseError::NeedMoreData),
211                            Err(err) => (Err(err), 0),
212                        }
213                    };
214                Ok((ReadUserIdentityMappingResponse::Other(result), read))
215            },
216        }
217    }
218}
219
220// Generated from operation replaceUserOpenshiftIoV1UserIdentityMapping
221
222impl UserIdentityMapping {
223    /// replace the specified UserIdentityMapping
224    ///
225    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::ReplaceResponse`]`<Self>>` constructor, or [`k8s_openapi::ReplaceResponse`]`<Self>` directly, to parse the HTTP response.
226    ///
227    /// # Arguments
228    ///
229    /// * `name`
230    ///
231    ///     name of the UserIdentityMapping
232    ///
233    /// * `body`
234    ///
235    /// * `optional`
236    ///
237    ///     Optional parameters. Use `Default::default()` to not pass any.
238    #[cfg(feature = "api")]
239    pub fn replace_user_identity_mapping(
240        name: &str,
241        body: &crate::api::user::v1::UserIdentityMapping,
242        optional: k8s_openapi::ReplaceOptional<'_>,
243    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::ReplaceResponse<Self>>), k8s_openapi::RequestError> {
244        let __url = format!("/apis/user.openshift.io/v1/useridentitymappings/{name}?",
245            name = k8s_openapi::percent_encoding::percent_encode(name.as_bytes(), k8s_openapi::percent_encoding2::PATH_SEGMENT_ENCODE_SET),
246        );
247        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
248        optional.__serialize(&mut __query_pairs);
249        let __url = __query_pairs.finish();
250
251        let __request = http::Request::put(__url);
252        let __body = serde_json::to_vec(body).map_err(k8s_openapi::RequestError::Json)?;
253        let __request = __request.header(http::header::CONTENT_TYPE, http::header::HeaderValue::from_static("application/json"));
254        match __request.body(__body) {
255            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
256            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
257        }
258    }
259}
260
261// End user.openshift.io/v1/UserIdentityMapping
262
263impl k8s_openapi::Resource for UserIdentityMapping {
264    const API_VERSION: &'static str = "user.openshift.io/v1";
265    const GROUP: &'static str = "user.openshift.io";
266    const KIND: &'static str = "UserIdentityMapping";
267    const VERSION: &'static str = "v1";
268}
269
270impl k8s_openapi::Metadata for UserIdentityMapping {
271    type Ty = k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
272
273    fn metadata(&self) -> &<Self as k8s_openapi::Metadata>::Ty {
274        &self.metadata
275    }
276
277    fn metadata_mut(&mut self) -> &mut<Self as k8s_openapi::Metadata>::Ty {
278        &mut self.metadata
279    }
280}
281
282impl<'de> serde::Deserialize<'de> for UserIdentityMapping {
283    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
284        #[allow(non_camel_case_types)]
285        enum Field {
286            Key_api_version,
287            Key_kind,
288            Key_identity,
289            Key_metadata,
290            Key_user,
291            Other,
292        }
293
294        impl<'de> serde::Deserialize<'de> for Field {
295            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
296                struct Visitor;
297
298                impl<'de> serde::de::Visitor<'de> for Visitor {
299                    type Value = Field;
300
301                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
302                        f.write_str("field identifier")
303                    }
304
305                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
306                        Ok(match v {
307                            "apiVersion" => Field::Key_api_version,
308                            "kind" => Field::Key_kind,
309                            "identity" => Field::Key_identity,
310                            "metadata" => Field::Key_metadata,
311                            "user" => Field::Key_user,
312                            _ => Field::Other,
313                        })
314                    }
315                }
316
317                deserializer.deserialize_identifier(Visitor)
318            }
319        }
320
321        struct Visitor;
322
323        impl<'de> serde::de::Visitor<'de> for Visitor {
324            type Value = UserIdentityMapping;
325
326            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
327                f.write_str(<Self::Value as k8s_openapi::Resource>::KIND)
328            }
329
330            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
331                let mut value_identity: Option<k8s_openapi::api::core::v1::ObjectReference> = None;
332                let mut value_metadata: Option<k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
333                let mut value_user: Option<k8s_openapi::api::core::v1::ObjectReference> = None;
334
335                while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
336                    match key {
337                        Field::Key_api_version => {
338                            let value_api_version: String = serde::de::MapAccess::next_value(&mut map)?;
339                            if value_api_version != <Self::Value as k8s_openapi::Resource>::API_VERSION {
340                                return Err(serde::de::Error::invalid_value(serde::de::Unexpected::Str(&value_api_version), &<Self::Value as k8s_openapi::Resource>::API_VERSION));
341                            }
342                        },
343                        Field::Key_kind => {
344                            let value_kind: String = serde::de::MapAccess::next_value(&mut map)?;
345                            if value_kind != <Self::Value as k8s_openapi::Resource>::KIND {
346                                return Err(serde::de::Error::invalid_value(serde::de::Unexpected::Str(&value_kind), &<Self::Value as k8s_openapi::Resource>::KIND));
347                            }
348                        },
349                        Field::Key_identity => value_identity = serde::de::MapAccess::next_value(&mut map)?,
350                        Field::Key_metadata => value_metadata = Some(serde::de::MapAccess::next_value(&mut map)?),
351                        Field::Key_user => value_user = serde::de::MapAccess::next_value(&mut map)?,
352                        Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
353                    }
354                }
355
356                Ok(UserIdentityMapping {
357                    identity: value_identity,
358                    metadata: value_metadata.ok_or_else(|| serde::de::Error::missing_field("metadata"))?,
359                    user: value_user,
360                })
361            }
362        }
363
364        deserializer.deserialize_struct(
365            <Self as k8s_openapi::Resource>::KIND,
366            &[
367                "apiVersion",
368                "kind",
369                "identity",
370                "metadata",
371                "user",
372            ],
373            Visitor,
374        )
375    }
376}
377
378impl serde::Serialize for UserIdentityMapping {
379    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
380        let mut state = serializer.serialize_struct(
381            <Self as k8s_openapi::Resource>::KIND,
382            3 +
383            self.identity.as_ref().map_or(0, |_| 1) +
384            self.user.as_ref().map_or(0, |_| 1),
385        )?;
386        serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as k8s_openapi::Resource>::API_VERSION)?;
387        serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as k8s_openapi::Resource>::KIND)?;
388        if let Some(value) = &self.identity {
389            serde::ser::SerializeStruct::serialize_field(&mut state, "identity", value)?;
390        }
391        serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
392        if let Some(value) = &self.user {
393            serde::ser::SerializeStruct::serialize_field(&mut state, "user", value)?;
394        }
395        serde::ser::SerializeStruct::end(state)
396    }
397}