Skip to main content

tapis_workflows/apis/
groups_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 [`create_group`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateGroupError {
20    Status400(models::RespError),
21    Status401(models::RespError),
22    Status409(models::RespError),
23    Status415(models::RespError),
24    Status500(models::RespError),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`delete_group`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteGroupError {
32    Status401(models::RespError),
33    Status403(models::RespError),
34    Status404(models::RespError),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`get_group`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetGroupError {
42    Status401(models::RespError),
43    Status500(models::RespError),
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`list_groups`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum ListGroupsError {
51    Status401(models::RespError),
52    Status500(models::RespError),
53    UnknownValue(serde_json::Value),
54}
55
56/// Create a group that perform CRUD operations on workflow resources.  The owner of the group will be made an admin by default. If you want to set other users as admins, you must use the '' endpoint.
57pub async fn create_group(
58    configuration: &configuration::Configuration,
59    req_group: models::ReqGroup,
60) -> Result<models::RespResourceUrl, Error<CreateGroupError>> {
61    // add a prefix to parameters to efficiently prevent name collisions
62    let p_body_req_group = req_group;
63
64    let uri_str = format!("{}/v3/workflows/groups", configuration.base_path);
65    let mut req_builder = configuration
66        .client
67        .request(reqwest::Method::POST, &uri_str);
68
69    if let Some(ref user_agent) = configuration.user_agent {
70        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71    }
72    if let Some(ref apikey) = configuration.api_key {
73        let key = apikey.key.clone();
74        let value = match apikey.prefix {
75            Some(ref prefix) => format!("{} {}", prefix, key),
76            None => key,
77        };
78        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
79    };
80    req_builder = req_builder.json(&p_body_req_group);
81
82    let req = req_builder.build()?;
83    let resp = configuration.client.execute(req).await?;
84
85    let status = resp.status();
86    let content_type = resp
87        .headers()
88        .get("content-type")
89        .and_then(|v| v.to_str().ok())
90        .unwrap_or("application/octet-stream");
91    let content_type = super::ContentType::from(content_type);
92
93    if !status.is_client_error() && !status.is_server_error() {
94        let content = resp.text().await?;
95        match content_type {
96            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
97            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespResourceUrl`"))),
98            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`")))),
99        }
100    } else {
101        let content = resp.text().await?;
102        let entity: Option<CreateGroupError> = serde_json::from_str(&content).ok();
103        Err(Error::ResponseError(ResponseContent {
104            status,
105            content,
106            entity,
107        }))
108    }
109}
110
111/// Delete a group and all of the objects that belong to them
112pub async fn delete_group(
113    configuration: &configuration::Configuration,
114    group_id: &str,
115) -> Result<models::RespString, Error<DeleteGroupError>> {
116    // add a prefix to parameters to efficiently prevent name collisions
117    let p_path_group_id = group_id;
118
119    let uri_str = format!(
120        "{}/v3/workflows/groups/{group_id}",
121        configuration.base_path,
122        group_id = crate::apis::urlencode(p_path_group_id)
123    );
124    let mut req_builder = configuration
125        .client
126        .request(reqwest::Method::DELETE, &uri_str);
127
128    if let Some(ref user_agent) = configuration.user_agent {
129        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130    }
131    if let Some(ref apikey) = configuration.api_key {
132        let key = apikey.key.clone();
133        let value = match apikey.prefix {
134            Some(ref prefix) => format!("{} {}", prefix, key),
135            None => key,
136        };
137        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
138    };
139
140    let req = req_builder.build()?;
141    let resp = configuration.client.execute(req).await?;
142
143    let status = resp.status();
144    let content_type = resp
145        .headers()
146        .get("content-type")
147        .and_then(|v| v.to_str().ok())
148        .unwrap_or("application/octet-stream");
149    let content_type = super::ContentType::from(content_type);
150
151    if !status.is_client_error() && !status.is_server_error() {
152        let content = resp.text().await?;
153        match content_type {
154            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
155            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespString`"))),
156            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespString`")))),
157        }
158    } else {
159        let content = resp.text().await?;
160        let entity: Option<DeleteGroupError> = serde_json::from_str(&content).ok();
161        Err(Error::ResponseError(ResponseContent {
162            status,
163            content,
164            entity,
165        }))
166    }
167}
168
169/// Retrieve details for a given group id
170pub async fn get_group(
171    configuration: &configuration::Configuration,
172    group_id: &str,
173) -> Result<models::RespGroupDetail, Error<GetGroupError>> {
174    // add a prefix to parameters to efficiently prevent name collisions
175    let p_path_group_id = group_id;
176
177    let uri_str = format!(
178        "{}/v3/workflows/groups/{group_id}",
179        configuration.base_path,
180        group_id = crate::apis::urlencode(p_path_group_id)
181    );
182    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
183
184    if let Some(ref user_agent) = configuration.user_agent {
185        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
186    }
187    if let Some(ref apikey) = configuration.api_key {
188        let key = apikey.key.clone();
189        let value = match apikey.prefix {
190            Some(ref prefix) => format!("{} {}", prefix, key),
191            None => key,
192        };
193        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
194    };
195
196    let req = req_builder.build()?;
197    let resp = configuration.client.execute(req).await?;
198
199    let status = resp.status();
200    let content_type = resp
201        .headers()
202        .get("content-type")
203        .and_then(|v| v.to_str().ok())
204        .unwrap_or("application/octet-stream");
205    let content_type = super::ContentType::from(content_type);
206
207    if !status.is_client_error() && !status.is_server_error() {
208        let content = resp.text().await?;
209        match content_type {
210            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
211            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespGroupDetail`"))),
212            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespGroupDetail`")))),
213        }
214    } else {
215        let content = resp.text().await?;
216        let entity: Option<GetGroupError> = serde_json::from_str(&content).ok();
217        Err(Error::ResponseError(ResponseContent {
218            status,
219            content,
220            entity,
221        }))
222    }
223}
224
225/// Retrieve all groups to which the user belongs
226pub async fn list_groups(
227    configuration: &configuration::Configuration,
228) -> Result<models::RespGroupList, Error<ListGroupsError>> {
229    let uri_str = format!("{}/v3/workflows/groups", configuration.base_path);
230    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
231
232    if let Some(ref user_agent) = configuration.user_agent {
233        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
234    }
235    if let Some(ref apikey) = configuration.api_key {
236        let key = apikey.key.clone();
237        let value = match apikey.prefix {
238            Some(ref prefix) => format!("{} {}", prefix, key),
239            None => key,
240        };
241        req_builder = req_builder.header("X-TAPIS-TOKEN", value);
242    };
243
244    let req = req_builder.build()?;
245    let resp = configuration.client.execute(req).await?;
246
247    let status = resp.status();
248    let content_type = resp
249        .headers()
250        .get("content-type")
251        .and_then(|v| v.to_str().ok())
252        .unwrap_or("application/octet-stream");
253    let content_type = super::ContentType::from(content_type);
254
255    if !status.is_client_error() && !status.is_server_error() {
256        let content = resp.text().await?;
257        match content_type {
258            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
259            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespGroupList`"))),
260            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespGroupList`")))),
261        }
262    } else {
263        let content = resp.text().await?;
264        let entity: Option<ListGroupsError> = serde_json::from_str(&content).ok();
265        Err(Error::ResponseError(ResponseContent {
266            status,
267            content,
268            entity,
269        }))
270    }
271}