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

1// Generated from definition com.github.openshift.api.user.v1.User
2
3/// Upon log in, every user of the system receives a User and Identity resource. Administrators may directly manipulate the attributes of the users for their own tracking, or set groups via the API. The user name is unique and is chosen based on the value provided by the identity provider - if a user already exists with the incoming name, the user name may have a number appended to it depending on the configuration of the system.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct User {
6    /// FullName is the full name of user
7    pub full_name: Option<String>,
8
9    /// Groups specifies group names this user is a member of. This field is deprecated and will be removed in a future release. Instead, create a Group object containing the name of this User.
10    pub groups: Vec<String>,
11
12    /// Identities are the identities associated with this user
13    pub identities: Vec<String>,
14
15    /// Standard object's metadata.
16    pub metadata: k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta,
17}
18
19// Begin user.openshift.io/v1/User
20
21// Generated from operation createUserOpenshiftIoV1User
22
23impl User {
24    /// create an User
25    ///
26    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::CreateResponse`]`<Self>>` constructor, or [`k8s_openapi::CreateResponse`]`<Self>` directly, to parse the HTTP response.
27    ///
28    /// # Arguments
29    ///
30    /// * `body`
31    ///
32    /// * `optional`
33    ///
34    ///     Optional parameters. Use `Default::default()` to not pass any.
35    #[cfg(feature = "api")]
36    pub fn create_user(
37        body: &crate::api::user::v1::User,
38        optional: k8s_openapi::CreateOptional<'_>,
39    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::CreateResponse<Self>>), k8s_openapi::RequestError> {
40        let __url = "/apis/user.openshift.io/v1/users?".to_owned();
41        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
42        optional.__serialize(&mut __query_pairs);
43        let __url = __query_pairs.finish();
44
45        let __request = http::Request::post(__url);
46        let __body = serde_json::to_vec(body).map_err(k8s_openapi::RequestError::Json)?;
47        let __request = __request.header(http::header::CONTENT_TYPE, http::header::HeaderValue::from_static("application/json"));
48        match __request.body(__body) {
49            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
50            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
51        }
52    }
53}
54
55// Generated from operation deleteUserOpenshiftIoV1CollectionUser
56
57impl User {
58    /// delete collection of User
59    ///
60    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::DeleteResponse`]`<`[`k8s_openapi::List`]`<Self>>>` constructor, or [`k8s_openapi::DeleteResponse`]`<`[`k8s_openapi::List`]`<Self>>` directly, to parse the HTTP response.
61    ///
62    /// # Arguments
63    ///
64    /// * `delete_optional`
65    ///
66    ///     Delete options. Use `Default::default()` to not pass any.
67    ///
68    /// * `list_optional`
69    ///
70    ///     List options. Use `Default::default()` to not pass any.
71    #[cfg(feature = "api")]
72    pub fn delete_collection_user(
73        delete_optional: k8s_openapi::DeleteOptional<'_>,
74        list_optional: k8s_openapi::ListOptional<'_>,
75    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::DeleteResponse<k8s_openapi::List<Self>>>), k8s_openapi::RequestError> {
76        let __url = "/apis/user.openshift.io/v1/users?".to_owned();
77        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
78        list_optional.__serialize(&mut __query_pairs);
79        let __url = __query_pairs.finish();
80
81        let __request = http::Request::delete(__url);
82        let __body = serde_json::to_vec(&delete_optional).map_err(k8s_openapi::RequestError::Json)?;
83        let __request = __request.header(http::header::CONTENT_TYPE, http::header::HeaderValue::from_static("application/json"));
84        match __request.body(__body) {
85            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
86            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
87        }
88    }
89}
90
91// Generated from operation deleteUserOpenshiftIoV1User
92
93impl User {
94    /// delete an User
95    ///
96    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::DeleteResponse`]`<Self>>` constructor, or [`k8s_openapi::DeleteResponse`]`<Self>` directly, to parse the HTTP response.
97    ///
98    /// # Arguments
99    ///
100    /// * `name`
101    ///
102    ///     name of the User
103    ///
104    /// * `optional`
105    ///
106    ///     Optional parameters. Use `Default::default()` to not pass any.
107    #[cfg(feature = "api")]
108    pub fn delete_user(
109        name: &str,
110        optional: k8s_openapi::DeleteOptional<'_>,
111    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::DeleteResponse<Self>>), k8s_openapi::RequestError> {
112        let __url = format!("/apis/user.openshift.io/v1/users/{name}",
113            name = k8s_openapi::percent_encoding::percent_encode(name.as_bytes(), k8s_openapi::percent_encoding2::PATH_SEGMENT_ENCODE_SET),
114        );
115
116        let __request = http::Request::delete(__url);
117        let __body = serde_json::to_vec(&optional).map_err(k8s_openapi::RequestError::Json)?;
118        let __request = __request.header(http::header::CONTENT_TYPE, http::header::HeaderValue::from_static("application/json"));
119        match __request.body(__body) {
120            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
121            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
122        }
123    }
124}
125
126// Generated from operation listUserOpenshiftIoV1User
127
128impl User {
129    /// list or watch objects of kind User
130    ///
131    /// This operation only supports listing all items of this type.
132    ///
133    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::ListResponse`]`<Self>>` constructor, or [`k8s_openapi::ListResponse`]`<Self>` directly, to parse the HTTP response.
134    ///
135    /// # Arguments
136    ///
137    /// * `optional`
138    ///
139    ///     Optional parameters. Use `Default::default()` to not pass any.
140    #[cfg(feature = "api")]
141    pub fn list_user(
142        optional: k8s_openapi::ListOptional<'_>,
143    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::ListResponse<Self>>), k8s_openapi::RequestError> {
144        let __url = "/apis/user.openshift.io/v1/users?".to_owned();
145        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
146        optional.__serialize(&mut __query_pairs);
147        let __url = __query_pairs.finish();
148
149        let __request = http::Request::get(__url);
150        let __body = vec![];
151        match __request.body(__body) {
152            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
153            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
154        }
155    }
156}
157
158// Generated from operation patchUserOpenshiftIoV1User
159
160impl User {
161    /// partially update the specified User
162    ///
163    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::PatchResponse`]`<Self>>` constructor, or [`k8s_openapi::PatchResponse`]`<Self>` directly, to parse the HTTP response.
164    ///
165    /// # Arguments
166    ///
167    /// * `name`
168    ///
169    ///     name of the User
170    ///
171    /// * `body`
172    ///
173    /// * `optional`
174    ///
175    ///     Optional parameters. Use `Default::default()` to not pass any.
176    #[cfg(feature = "api")]
177    pub fn patch_user(
178        name: &str,
179        body: &k8s_openapi::apimachinery::pkg::apis::meta::v1::Patch,
180        optional: k8s_openapi::PatchOptional<'_>,
181    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::PatchResponse<Self>>), k8s_openapi::RequestError> {
182        let __url = format!("/apis/user.openshift.io/v1/users/{name}?",
183            name = k8s_openapi::percent_encoding::percent_encode(name.as_bytes(), k8s_openapi::percent_encoding2::PATH_SEGMENT_ENCODE_SET),
184        );
185        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
186        optional.__serialize(&mut __query_pairs);
187        let __url = __query_pairs.finish();
188
189        let __request = http::Request::patch(__url);
190        let __body = serde_json::to_vec(body).map_err(k8s_openapi::RequestError::Json)?;
191        let __request = __request.header(http::header::CONTENT_TYPE, http::header::HeaderValue::from_static(match body {
192            k8s_openapi::apimachinery::pkg::apis::meta::v1::Patch::Json(_) => "application/json-patch+json",
193            k8s_openapi::apimachinery::pkg::apis::meta::v1::Patch::Merge(_) => "application/merge-patch+json",
194            k8s_openapi::apimachinery::pkg::apis::meta::v1::Patch::StrategicMerge(_) => "application/strategic-merge-patch+json",
195        }));
196        match __request.body(__body) {
197            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
198            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
199        }
200    }
201}
202
203// Generated from operation readUserOpenshiftIoV1User
204
205impl User {
206    /// read the specified User
207    ///
208    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`ReadUserResponse`]`>` constructor, or [`ReadUserResponse`] directly, to parse the HTTP response.
209    ///
210    /// # Arguments
211    ///
212    /// * `name`
213    ///
214    ///     name of the User
215    ///
216    /// * `optional`
217    ///
218    ///     Optional parameters. Use `Default::default()` to not pass any.
219    #[cfg(feature = "api")]
220    pub fn read_user(
221        name: &str,
222        optional: ReadUserOptional<'_>,
223    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<ReadUserResponse>), k8s_openapi::RequestError> {
224        let ReadUserOptional {
225            exact,
226            export,
227            pretty,
228        } = optional;
229        let __url = format!("/apis/user.openshift.io/v1/users/{name}?",
230            name = k8s_openapi::percent_encoding::percent_encode(name.as_bytes(), k8s_openapi::percent_encoding2::PATH_SEGMENT_ENCODE_SET),
231        );
232        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
233        if let Some(exact) = exact {
234            __query_pairs.append_pair("exact", &exact.to_string());
235        }
236        if let Some(export) = export {
237            __query_pairs.append_pair("export", &export.to_string());
238        }
239        if let Some(pretty) = pretty {
240            __query_pairs.append_pair("pretty", pretty);
241        }
242        let __url = __query_pairs.finish();
243
244        let __request = http::Request::get(__url);
245        let __body = vec![];
246        match __request.body(__body) {
247            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
248            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
249        }
250    }
251}
252
253/// Optional parameters of [`User::read_user`]
254#[cfg(feature = "api")]
255#[derive(Clone, Copy, Debug, Default)]
256pub struct ReadUserOptional<'a> {
257    /// Should the export be exact.  Exact export maintains cluster-specific fields like 'Namespace'.
258    pub exact: Option<bool>,
259    /// Should this value be exported.  Export strips fields that a user can not specify.
260    pub export: Option<bool>,
261    /// If 'true', then the output is pretty printed.
262    pub pretty: Option<&'a str>,
263}
264
265/// Use `<ReadUserResponse as Response>::try_from_parts` to parse the HTTP response body of [`User::read_user`]
266#[cfg(feature = "api")]
267#[derive(Debug)]
268pub enum ReadUserResponse {
269    Ok(crate::api::user::v1::User),
270    Other(Result<Option<serde_json::Value>, serde_json::Error>),
271}
272
273#[cfg(feature = "api")]
274impl k8s_openapi::Response for ReadUserResponse {
275    fn try_from_parts(status_code: http::StatusCode, buf: &[u8]) -> Result<(Self, usize), k8s_openapi::ResponseError> {
276        match status_code {
277            http::StatusCode::OK => {
278                let result = match serde_json::from_slice(buf) {
279                    Ok(value) => value,
280                    Err(ref err) if err.is_eof() => return Err(k8s_openapi::ResponseError::NeedMoreData),
281                    Err(err) => return Err(k8s_openapi::ResponseError::Json(err)),
282                };
283                Ok((ReadUserResponse::Ok(result), buf.len()))
284            },
285            _ => {
286                let (result, read) =
287                    if buf.is_empty() {
288                        (Ok(None), 0)
289                    }
290                    else {
291                        match serde_json::from_slice(buf) {
292                            Ok(value) => (Ok(Some(value)), buf.len()),
293                            Err(ref err) if err.is_eof() => return Err(k8s_openapi::ResponseError::NeedMoreData),
294                            Err(err) => (Err(err), 0),
295                        }
296                    };
297                Ok((ReadUserResponse::Other(result), read))
298            },
299        }
300    }
301}
302
303// Generated from operation replaceUserOpenshiftIoV1User
304
305impl User {
306    /// replace the specified User
307    ///
308    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::ReplaceResponse`]`<Self>>` constructor, or [`k8s_openapi::ReplaceResponse`]`<Self>` directly, to parse the HTTP response.
309    ///
310    /// # Arguments
311    ///
312    /// * `name`
313    ///
314    ///     name of the User
315    ///
316    /// * `body`
317    ///
318    /// * `optional`
319    ///
320    ///     Optional parameters. Use `Default::default()` to not pass any.
321    #[cfg(feature = "api")]
322    pub fn replace_user(
323        name: &str,
324        body: &crate::api::user::v1::User,
325        optional: k8s_openapi::ReplaceOptional<'_>,
326    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::ReplaceResponse<Self>>), k8s_openapi::RequestError> {
327        let __url = format!("/apis/user.openshift.io/v1/users/{name}?",
328            name = k8s_openapi::percent_encoding::percent_encode(name.as_bytes(), k8s_openapi::percent_encoding2::PATH_SEGMENT_ENCODE_SET),
329        );
330        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
331        optional.__serialize(&mut __query_pairs);
332        let __url = __query_pairs.finish();
333
334        let __request = http::Request::put(__url);
335        let __body = serde_json::to_vec(body).map_err(k8s_openapi::RequestError::Json)?;
336        let __request = __request.header(http::header::CONTENT_TYPE, http::header::HeaderValue::from_static("application/json"));
337        match __request.body(__body) {
338            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
339            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
340        }
341    }
342}
343
344// Generated from operation watchUserOpenshiftIoV1User
345
346impl User {
347    /// list or watch objects of kind User
348    ///
349    /// This operation only supports watching one item, or a list of items, of this type for changes.
350    ///
351    /// Use the returned [`k8s_openapi::ResponseBody`]`<`[`k8s_openapi::WatchResponse`]`<Self>>` constructor, or [`k8s_openapi::WatchResponse`]`<Self>` directly, to parse the HTTP response.
352    ///
353    /// # Arguments
354    ///
355    /// * `optional`
356    ///
357    ///     Optional parameters. Use `Default::default()` to not pass any.
358    #[cfg(feature = "api")]
359    pub fn watch_user(
360        optional: k8s_openapi::WatchOptional<'_>,
361    ) -> Result<(http::Request<Vec<u8>>, fn(http::StatusCode) -> k8s_openapi::ResponseBody<k8s_openapi::WatchResponse<Self>>), k8s_openapi::RequestError> {
362        let __url = "/apis/user.openshift.io/v1/users?".to_owned();
363        let mut __query_pairs = k8s_openapi::url::form_urlencoded::Serializer::new(__url);
364        optional.__serialize(&mut __query_pairs);
365        let __url = __query_pairs.finish();
366
367        let __request = http::Request::get(__url);
368        let __body = vec![];
369        match __request.body(__body) {
370            Ok(request) => Ok((request, k8s_openapi::ResponseBody::new)),
371            Err(err) => Err(k8s_openapi::RequestError::Http(err)),
372        }
373    }
374}
375
376// End user.openshift.io/v1/User
377
378impl k8s_openapi::Resource for User {
379    const API_VERSION: &'static str = "user.openshift.io/v1";
380    const GROUP: &'static str = "user.openshift.io";
381    const KIND: &'static str = "User";
382    const VERSION: &'static str = "v1";
383}
384
385impl k8s_openapi::ListableResource for User {
386    const LIST_KIND: &'static str = concat!("User", "List");
387}
388
389impl k8s_openapi::Metadata for User {
390    type Ty = k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
391
392    fn metadata(&self) -> &<Self as k8s_openapi::Metadata>::Ty {
393        &self.metadata
394    }
395
396    fn metadata_mut(&mut self) -> &mut<Self as k8s_openapi::Metadata>::Ty {
397        &mut self.metadata
398    }
399}
400
401impl<'de> serde::Deserialize<'de> for User {
402    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
403        #[allow(non_camel_case_types)]
404        enum Field {
405            Key_api_version,
406            Key_kind,
407            Key_full_name,
408            Key_groups,
409            Key_identities,
410            Key_metadata,
411            Other,
412        }
413
414        impl<'de> serde::Deserialize<'de> for Field {
415            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
416                struct Visitor;
417
418                impl<'de> serde::de::Visitor<'de> for Visitor {
419                    type Value = Field;
420
421                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
422                        f.write_str("field identifier")
423                    }
424
425                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
426                        Ok(match v {
427                            "apiVersion" => Field::Key_api_version,
428                            "kind" => Field::Key_kind,
429                            "fullName" => Field::Key_full_name,
430                            "groups" => Field::Key_groups,
431                            "identities" => Field::Key_identities,
432                            "metadata" => Field::Key_metadata,
433                            _ => Field::Other,
434                        })
435                    }
436                }
437
438                deserializer.deserialize_identifier(Visitor)
439            }
440        }
441
442        struct Visitor;
443
444        impl<'de> serde::de::Visitor<'de> for Visitor {
445            type Value = User;
446
447            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
448                f.write_str(<Self::Value as k8s_openapi::Resource>::KIND)
449            }
450
451            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
452                let mut value_full_name: Option<String> = None;
453                let mut value_groups: Option<Vec<String>> = None;
454                let mut value_identities: Option<Vec<String>> = None;
455                let mut value_metadata: Option<k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
456
457                while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
458                    match key {
459                        Field::Key_api_version => {
460                            let value_api_version: String = serde::de::MapAccess::next_value(&mut map)?;
461                            if value_api_version != <Self::Value as k8s_openapi::Resource>::API_VERSION {
462                                return Err(serde::de::Error::invalid_value(serde::de::Unexpected::Str(&value_api_version), &<Self::Value as k8s_openapi::Resource>::API_VERSION));
463                            }
464                        },
465                        Field::Key_kind => {
466                            let value_kind: String = serde::de::MapAccess::next_value(&mut map)?;
467                            if value_kind != <Self::Value as k8s_openapi::Resource>::KIND {
468                                return Err(serde::de::Error::invalid_value(serde::de::Unexpected::Str(&value_kind), &<Self::Value as k8s_openapi::Resource>::KIND));
469                            }
470                        },
471                        Field::Key_full_name => value_full_name = serde::de::MapAccess::next_value(&mut map)?,
472                        Field::Key_groups => value_groups = Some(serde::de::MapAccess::next_value(&mut map)?),
473                        Field::Key_identities => value_identities = Some(serde::de::MapAccess::next_value(&mut map)?),
474                        Field::Key_metadata => value_metadata = Some(serde::de::MapAccess::next_value(&mut map)?),
475                        Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
476                    }
477                }
478
479                Ok(User {
480                    full_name: value_full_name,
481                    groups: value_groups.ok_or_else(|| serde::de::Error::missing_field("groups"))?,
482                    identities: value_identities.ok_or_else(|| serde::de::Error::missing_field("identities"))?,
483                    metadata: value_metadata.ok_or_else(|| serde::de::Error::missing_field("metadata"))?,
484                })
485            }
486        }
487
488        deserializer.deserialize_struct(
489            <Self as k8s_openapi::Resource>::KIND,
490            &[
491                "apiVersion",
492                "kind",
493                "fullName",
494                "groups",
495                "identities",
496                "metadata",
497            ],
498            Visitor,
499        )
500    }
501}
502
503impl serde::Serialize for User {
504    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
505        let mut state = serializer.serialize_struct(
506            <Self as k8s_openapi::Resource>::KIND,
507            5 +
508            self.full_name.as_ref().map_or(0, |_| 1),
509        )?;
510        serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as k8s_openapi::Resource>::API_VERSION)?;
511        serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as k8s_openapi::Resource>::KIND)?;
512        if let Some(value) = &self.full_name {
513            serde::ser::SerializeStruct::serialize_field(&mut state, "fullName", value)?;
514        }
515        serde::ser::SerializeStruct::serialize_field(&mut state, "groups", &self.groups)?;
516        serde::ser::SerializeStruct::serialize_field(&mut state, "identities", &self.identities)?;
517        serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
518        serde::ser::SerializeStruct::end(state)
519    }
520}