Skip to main content

tapis_workflows/apis/
users_api.rs

1/*
2 * Tapis Workflows API
3 *
4 * Create and manage pipelines
5 *
6 * The version of the OpenAPI document: 1.6.0
7 * Contact: cicsupport@tacc.utexas.edu
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`add_group_user`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum AddGroupUserError {
20    Status400(models::RespError),
21    Status401(models::RespError),
22    Status403(models::RespError),
23    Status404(models::RespError),
24    Status500(models::RespError),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`get_group_user`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetGroupUserError {
32    Status400(models::RespError),
33    Status401(models::RespError),
34    Status403(models::RespError),
35    Status404(models::RespError),
36    Status500(models::RespError),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`list_group_users`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ListGroupUsersError {
44    Status400(models::RespError),
45    Status401(models::RespError),
46    Status403(models::RespError),
47    Status404(models::RespError),
48    Status500(models::RespError),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`remove_group_user`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum RemoveGroupUserError {
56    Status401(models::RespError),
57    Status403(models::RespError),
58    Status404(models::RespError),
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`update_group_user`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum UpdateGroupUserError {
66    Status400(models::RespError),
67    Status401(models::RespError),
68    Status403(models::RespError),
69    Status404(models::RespError),
70    UnknownValue(serde_json::Value),
71}
72
73/// Add a user to a group.
74pub async fn add_group_user(
75    configuration: &configuration::Configuration,
76    group_id: &str,
77    req_group_user: models::ReqGroupUser,
78) -> Result<models::RespResourceUrl, Error<AddGroupUserError>> {
79    // add a prefix to parameters to efficiently prevent name collisions
80    let p_path_group_id = group_id;
81    let p_body_req_group_user = req_group_user;
82
83    let uri_str = format!(
84        "{}/v3/workflows/groups/{group_id}/users",
85        configuration.base_path,
86        group_id = crate::apis::urlencode(p_path_group_id)
87    );
88    let mut req_builder = configuration
89        .client
90        .request(reqwest::Method::POST, &uri_str);
91
92    if let Some(ref user_agent) = configuration.user_agent {
93        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
94    }
95    if let Some(ref apikey) = configuration.api_key {
96        let key = apikey.key.clone();
97        let value = match apikey.prefix {
98            Some(ref prefix) => format!("{} {}", prefix, key),
99            None => key,
100        };
101        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
102    };
103    req_builder = req_builder.json(&p_body_req_group_user);
104
105    let req = req_builder.build()?;
106    let resp = configuration.client.execute(req).await?;
107
108    let status = resp.status();
109    let content_type = resp
110        .headers()
111        .get("content-type")
112        .and_then(|v| v.to_str().ok())
113        .unwrap_or("application/octet-stream");
114    let content_type = super::ContentType::from(content_type);
115
116    if !status.is_client_error() && !status.is_server_error() {
117        let content = resp.text().await?;
118        match content_type {
119            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
120            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespResourceUrl`"))),
121            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespResourceUrl`")))),
122        }
123    } else {
124        let content = resp.text().await?;
125        let entity: Option<AddGroupUserError> = serde_json::from_str(&content).ok();
126        Err(Error::ResponseError(ResponseContent {
127            status,
128            content,
129            entity,
130        }))
131    }
132}
133
134/// Get a user from a group
135pub async fn get_group_user(
136    configuration: &configuration::Configuration,
137    group_id: &str,
138    username: &str,
139) -> Result<models::RespGroupUser, Error<GetGroupUserError>> {
140    // add a prefix to parameters to efficiently prevent name collisions
141    let p_path_group_id = group_id;
142    let p_path_username = username;
143
144    let uri_str = format!(
145        "{}/v3/workflows/groups/{group_id}/users/{username}",
146        configuration.base_path,
147        group_id = crate::apis::urlencode(p_path_group_id),
148        username = crate::apis::urlencode(p_path_username)
149    );
150    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
151
152    if let Some(ref user_agent) = configuration.user_agent {
153        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154    }
155    if let Some(ref apikey) = configuration.api_key {
156        let key = apikey.key.clone();
157        let value = match apikey.prefix {
158            Some(ref prefix) => format!("{} {}", prefix, key),
159            None => key,
160        };
161        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
162    };
163
164    let req = req_builder.build()?;
165    let resp = configuration.client.execute(req).await?;
166
167    let status = resp.status();
168    let content_type = resp
169        .headers()
170        .get("content-type")
171        .and_then(|v| v.to_str().ok())
172        .unwrap_or("application/octet-stream");
173    let content_type = super::ContentType::from(content_type);
174
175    if !status.is_client_error() && !status.is_server_error() {
176        let content = resp.text().await?;
177        match content_type {
178            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
179            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespGroupUser`"))),
180            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespGroupUser`")))),
181        }
182    } else {
183        let content = resp.text().await?;
184        let entity: Option<GetGroupUserError> = serde_json::from_str(&content).ok();
185        Err(Error::ResponseError(ResponseContent {
186            status,
187            content,
188            entity,
189        }))
190    }
191}
192
193/// List users.
194pub async fn list_group_users(
195    configuration: &configuration::Configuration,
196    group_id: &str,
197) -> Result<models::RespGroupUserList, Error<ListGroupUsersError>> {
198    // add a prefix to parameters to efficiently prevent name collisions
199    let p_path_group_id = group_id;
200
201    let uri_str = format!(
202        "{}/v3/workflows/groups/{group_id}/users",
203        configuration.base_path,
204        group_id = crate::apis::urlencode(p_path_group_id)
205    );
206    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
207
208    if let Some(ref user_agent) = configuration.user_agent {
209        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
210    }
211    if let Some(ref apikey) = configuration.api_key {
212        let key = apikey.key.clone();
213        let value = match apikey.prefix {
214            Some(ref prefix) => format!("{} {}", prefix, key),
215            None => key,
216        };
217        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
218    };
219
220    let req = req_builder.build()?;
221    let resp = configuration.client.execute(req).await?;
222
223    let status = resp.status();
224    let content_type = resp
225        .headers()
226        .get("content-type")
227        .and_then(|v| v.to_str().ok())
228        .unwrap_or("application/octet-stream");
229    let content_type = super::ContentType::from(content_type);
230
231    if !status.is_client_error() && !status.is_server_error() {
232        let content = resp.text().await?;
233        match content_type {
234            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
235            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespGroupUserList`"))),
236            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespGroupUserList`")))),
237        }
238    } else {
239        let content = resp.text().await?;
240        let entity: Option<ListGroupUsersError> = serde_json::from_str(&content).ok();
241        Err(Error::ResponseError(ResponseContent {
242            status,
243            content,
244            entity,
245        }))
246    }
247}
248
249/// Remove a user from a group.
250pub async fn remove_group_user(
251    configuration: &configuration::Configuration,
252    group_id: &str,
253    username: &str,
254) -> Result<models::RespGroupUser, Error<RemoveGroupUserError>> {
255    // add a prefix to parameters to efficiently prevent name collisions
256    let p_path_group_id = group_id;
257    let p_path_username = username;
258
259    let uri_str = format!(
260        "{}/v3/workflows/groups/{group_id}/users/{username}",
261        configuration.base_path,
262        group_id = crate::apis::urlencode(p_path_group_id),
263        username = crate::apis::urlencode(p_path_username)
264    );
265    let mut req_builder = configuration
266        .client
267        .request(reqwest::Method::DELETE, &uri_str);
268
269    if let Some(ref user_agent) = configuration.user_agent {
270        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
271    }
272    if let Some(ref apikey) = configuration.api_key {
273        let key = apikey.key.clone();
274        let value = match apikey.prefix {
275            Some(ref prefix) => format!("{} {}", prefix, key),
276            None => key,
277        };
278        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
279    };
280
281    let req = req_builder.build()?;
282    let resp = configuration.client.execute(req).await?;
283
284    let status = resp.status();
285    let content_type = resp
286        .headers()
287        .get("content-type")
288        .and_then(|v| v.to_str().ok())
289        .unwrap_or("application/octet-stream");
290    let content_type = super::ContentType::from(content_type);
291
292    if !status.is_client_error() && !status.is_server_error() {
293        let content = resp.text().await?;
294        match content_type {
295            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
296            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespGroupUser`"))),
297            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespGroupUser`")))),
298        }
299    } else {
300        let content = resp.text().await?;
301        let entity: Option<RemoveGroupUserError> = serde_json::from_str(&content).ok();
302        Err(Error::ResponseError(ResponseContent {
303            status,
304            content,
305            entity,
306        }))
307    }
308}
309
310/// Update a user for a specified group. Only group admins can perform this operation.
311pub async fn update_group_user(
312    configuration: &configuration::Configuration,
313    group_id: &str,
314    username: &str,
315    req_update_group_user: models::ReqUpdateGroupUser,
316) -> Result<models::RespGroupUser, Error<UpdateGroupUserError>> {
317    // add a prefix to parameters to efficiently prevent name collisions
318    let p_path_group_id = group_id;
319    let p_path_username = username;
320    let p_body_req_update_group_user = req_update_group_user;
321
322    let uri_str = format!(
323        "{}/v3/workflows/groups/{group_id}/users/{username}",
324        configuration.base_path,
325        group_id = crate::apis::urlencode(p_path_group_id),
326        username = crate::apis::urlencode(p_path_username)
327    );
328    let mut req_builder = configuration
329        .client
330        .request(reqwest::Method::PATCH, &uri_str);
331
332    if let Some(ref user_agent) = configuration.user_agent {
333        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
334    }
335    if let Some(ref apikey) = configuration.api_key {
336        let key = apikey.key.clone();
337        let value = match apikey.prefix {
338            Some(ref prefix) => format!("{} {}", prefix, key),
339            None => key,
340        };
341        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
342    };
343    req_builder = req_builder.json(&p_body_req_update_group_user);
344
345    let req = req_builder.build()?;
346    let resp = configuration.client.execute(req).await?;
347
348    let status = resp.status();
349    let content_type = resp
350        .headers()
351        .get("content-type")
352        .and_then(|v| v.to_str().ok())
353        .unwrap_or("application/octet-stream");
354    let content_type = super::ContentType::from(content_type);
355
356    if !status.is_client_error() && !status.is_server_error() {
357        let content = resp.text().await?;
358        match content_type {
359            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
360            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespGroupUser`"))),
361            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespGroupUser`")))),
362        }
363    } else {
364        let content = resp.text().await?;
365        let entity: Option<UpdateGroupUserError> = serde_json::from_str(&content).ok();
366        Err(Error::ResponseError(ResponseContent {
367            status,
368            content,
369            entity,
370        }))
371    }
372}