1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateTaskError {
20 UnknownValue(serde_json::Value),
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum DeleteTaskError {
27 Status401(models::RespError),
28 Status403(models::RespError),
29 Status404(models::RespError),
30 UnknownValue(serde_json::Value),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum GetTaskError {
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ListTasksError {
44 UnknownValue(serde_json::Value),
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum PatchTaskError {
51 UnknownValue(serde_json::Value),
52}
53
54pub async fn create_task(
56 configuration: &configuration::Configuration,
57 group_id: &str,
58 pipeline_id: &str,
59 req_task: models::ReqTask,
60) -> Result<models::RespResourceUrl, Error<CreateTaskError>> {
61 let p_path_group_id = group_id;
63 let p_path_pipeline_id = pipeline_id;
64 let p_body_req_task = req_task;
65
66 let uri_str = format!(
67 "{}/v3/workflows/groups/{group_id}/pipelines/{pipeline_id}/tasks",
68 configuration.base_path,
69 group_id = crate::apis::urlencode(p_path_group_id),
70 pipeline_id = crate::apis::urlencode(p_path_pipeline_id)
71 );
72 let mut req_builder = configuration
73 .client
74 .request(reqwest::Method::POST, &uri_str);
75
76 if let Some(ref user_agent) = configuration.user_agent {
77 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
78 }
79 if let Some(ref apikey) = configuration.api_key {
80 let key = apikey.key.clone();
81 let value = match apikey.prefix {
82 Some(ref prefix) => format!("{} {}", prefix, key),
83 None => key,
84 };
85 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
86 };
87 req_builder = req_builder.json(&p_body_req_task);
88
89 let req = req_builder.build()?;
90 let resp = configuration.client.execute(req).await?;
91
92 let status = resp.status();
93 let content_type = resp
94 .headers()
95 .get("content-type")
96 .and_then(|v| v.to_str().ok())
97 .unwrap_or("application/octet-stream");
98 let content_type = super::ContentType::from(content_type);
99
100 if !status.is_client_error() && !status.is_server_error() {
101 let content = resp.text().await?;
102 match content_type {
103 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
104 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespResourceUrl`"))),
105 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`")))),
106 }
107 } else {
108 let content = resp.text().await?;
109 let entity: Option<CreateTaskError> = serde_json::from_str(&content).ok();
110 Err(Error::ResponseError(ResponseContent {
111 status,
112 content,
113 entity,
114 }))
115 }
116}
117
118pub async fn delete_task(
120 configuration: &configuration::Configuration,
121 group_id: &str,
122 pipeline_id: &str,
123 task_id: &str,
124) -> Result<models::RespString, Error<DeleteTaskError>> {
125 let p_path_group_id = group_id;
127 let p_path_pipeline_id = pipeline_id;
128 let p_path_task_id = task_id;
129
130 let uri_str = format!(
131 "{}/v3/workflows/groups/{group_id}/pipelines/{pipeline_id}/tasks/{task_id}",
132 configuration.base_path,
133 group_id = crate::apis::urlencode(p_path_group_id),
134 pipeline_id = crate::apis::urlencode(p_path_pipeline_id),
135 task_id = crate::apis::urlencode(p_path_task_id)
136 );
137 let mut req_builder = configuration
138 .client
139 .request(reqwest::Method::DELETE, &uri_str);
140
141 if let Some(ref user_agent) = configuration.user_agent {
142 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
143 }
144 if let Some(ref apikey) = configuration.api_key {
145 let key = apikey.key.clone();
146 let value = match apikey.prefix {
147 Some(ref prefix) => format!("{} {}", prefix, key),
148 None => key,
149 };
150 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
151 };
152
153 let req = req_builder.build()?;
154 let resp = configuration.client.execute(req).await?;
155
156 let status = resp.status();
157 let content_type = resp
158 .headers()
159 .get("content-type")
160 .and_then(|v| v.to_str().ok())
161 .unwrap_or("application/octet-stream");
162 let content_type = super::ContentType::from(content_type);
163
164 if !status.is_client_error() && !status.is_server_error() {
165 let content = resp.text().await?;
166 match content_type {
167 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
168 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespString`"))),
169 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`")))),
170 }
171 } else {
172 let content = resp.text().await?;
173 let entity: Option<DeleteTaskError> = serde_json::from_str(&content).ok();
174 Err(Error::ResponseError(ResponseContent {
175 status,
176 content,
177 entity,
178 }))
179 }
180}
181
182pub async fn get_task(
184 configuration: &configuration::Configuration,
185 group_id: &str,
186 pipeline_id: &str,
187 task_id: &str,
188) -> Result<models::RespTask, Error<GetTaskError>> {
189 let p_path_group_id = group_id;
191 let p_path_pipeline_id = pipeline_id;
192 let p_path_task_id = task_id;
193
194 let uri_str = format!(
195 "{}/v3/workflows/groups/{group_id}/pipelines/{pipeline_id}/tasks/{task_id}",
196 configuration.base_path,
197 group_id = crate::apis::urlencode(p_path_group_id),
198 pipeline_id = crate::apis::urlencode(p_path_pipeline_id),
199 task_id = crate::apis::urlencode(p_path_task_id)
200 );
201 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
202
203 if let Some(ref user_agent) = configuration.user_agent {
204 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
205 }
206 if let Some(ref apikey) = configuration.api_key {
207 let key = apikey.key.clone();
208 let value = match apikey.prefix {
209 Some(ref prefix) => format!("{} {}", prefix, key),
210 None => key,
211 };
212 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
213 };
214
215 let req = req_builder.build()?;
216 let resp = configuration.client.execute(req).await?;
217
218 let status = resp.status();
219 let content_type = resp
220 .headers()
221 .get("content-type")
222 .and_then(|v| v.to_str().ok())
223 .unwrap_or("application/octet-stream");
224 let content_type = super::ContentType::from(content_type);
225
226 if !status.is_client_error() && !status.is_server_error() {
227 let content = resp.text().await?;
228 match content_type {
229 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
230 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespTask`"))),
231 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespTask`")))),
232 }
233 } else {
234 let content = resp.text().await?;
235 let entity: Option<GetTaskError> = serde_json::from_str(&content).ok();
236 Err(Error::ResponseError(ResponseContent {
237 status,
238 content,
239 entity,
240 }))
241 }
242}
243
244pub async fn list_tasks(
246 configuration: &configuration::Configuration,
247 group_id: &str,
248 pipeline_id: &str,
249) -> Result<models::RespTaskList, Error<ListTasksError>> {
250 let p_path_group_id = group_id;
252 let p_path_pipeline_id = pipeline_id;
253
254 let uri_str = format!(
255 "{}/v3/workflows/groups/{group_id}/pipelines/{pipeline_id}/tasks",
256 configuration.base_path,
257 group_id = crate::apis::urlencode(p_path_group_id),
258 pipeline_id = crate::apis::urlencode(p_path_pipeline_id)
259 );
260 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
261
262 if let Some(ref user_agent) = configuration.user_agent {
263 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
264 }
265 if let Some(ref apikey) = configuration.api_key {
266 let key = apikey.key.clone();
267 let value = match apikey.prefix {
268 Some(ref prefix) => format!("{} {}", prefix, key),
269 None => key,
270 };
271 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
272 };
273
274 let req = req_builder.build()?;
275 let resp = configuration.client.execute(req).await?;
276
277 let status = resp.status();
278 let content_type = resp
279 .headers()
280 .get("content-type")
281 .and_then(|v| v.to_str().ok())
282 .unwrap_or("application/octet-stream");
283 let content_type = super::ContentType::from(content_type);
284
285 if !status.is_client_error() && !status.is_server_error() {
286 let content = resp.text().await?;
287 match content_type {
288 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
289 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespTaskList`"))),
290 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespTaskList`")))),
291 }
292 } else {
293 let content = resp.text().await?;
294 let entity: Option<ListTasksError> = serde_json::from_str(&content).ok();
295 Err(Error::ResponseError(ResponseContent {
296 status,
297 content,
298 entity,
299 }))
300 }
301}
302
303pub async fn patch_task(
305 configuration: &configuration::Configuration,
306 group_id: &str,
307 pipeline_id: &str,
308 task_id: &str,
309 task: models::Task,
310) -> Result<models::RespTask, Error<PatchTaskError>> {
311 let p_path_group_id = group_id;
313 let p_path_pipeline_id = pipeline_id;
314 let p_path_task_id = task_id;
315 let p_body_task = task;
316
317 let uri_str = format!(
318 "{}/v3/workflows/groups/{group_id}/pipelines/{pipeline_id}/tasks/{task_id}",
319 configuration.base_path,
320 group_id = crate::apis::urlencode(p_path_group_id),
321 pipeline_id = crate::apis::urlencode(p_path_pipeline_id),
322 task_id = crate::apis::urlencode(p_path_task_id)
323 );
324 let mut req_builder = configuration
325 .client
326 .request(reqwest::Method::PATCH, &uri_str);
327
328 if let Some(ref user_agent) = configuration.user_agent {
329 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
330 }
331 if let Some(ref apikey) = configuration.api_key {
332 let key = apikey.key.clone();
333 let value = match apikey.prefix {
334 Some(ref prefix) => format!("{} {}", prefix, key),
335 None => key,
336 };
337 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
338 };
339 req_builder = req_builder.json(&p_body_task);
340
341 let req = req_builder.build()?;
342 let resp = configuration.client.execute(req).await?;
343
344 let status = resp.status();
345 let content_type = resp
346 .headers()
347 .get("content-type")
348 .and_then(|v| v.to_str().ok())
349 .unwrap_or("application/octet-stream");
350 let content_type = super::ContentType::from(content_type);
351
352 if !status.is_client_error() && !status.is_server_error() {
353 let content = resp.text().await?;
354 match content_type {
355 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
356 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespTask`"))),
357 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespTask`")))),
358 }
359 } else {
360 let content = resp.text().await?;
361 let entity: Option<PatchTaskError> = serde_json::from_str(&content).ok();
362 Err(Error::ResponseError(ResponseContent {
363 status,
364 content,
365 entity,
366 }))
367 }
368}