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 CreateArchiveError {
20 Status400(models::RespError),
21 Status401(models::RespError),
22 Status403(models::RespError),
23 Status405(models::RespError),
24 Status409(models::RespError),
25 Status415(models::RespError),
26 Status422(models::RespError),
27 Status500(models::RespError),
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum GetArchiveError {
35 Status400(models::RespError),
36 Status401(models::RespError),
37 Status403(models::RespError),
38 Status404(models::RespError),
39 Status405(models::RespError),
40 Status415(models::RespError),
41 Status422(models::RespError),
42 Status500(models::RespError),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ListArchivesError {
50 Status400(models::RespError),
51 Status401(models::RespError),
52 Status403(models::RespError),
53 Status404(models::RespError),
54 Status405(models::RespError),
55 Status415(models::RespError),
56 Status422(models::RespError),
57 Status500(models::RespError),
58 UnknownValue(serde_json::Value),
59}
60
61pub async fn create_archive(
63 configuration: &configuration::Configuration,
64 group_id: &str,
65 req_archive: models::ReqArchive,
66) -> Result<models::RespResourceUrl, Error<CreateArchiveError>> {
67 let p_path_group_id = group_id;
69 let p_body_req_archive = req_archive;
70
71 let uri_str = format!(
72 "{}/v3/workflows/groups/{group_id}/archives",
73 configuration.base_path,
74 group_id = crate::apis::urlencode(p_path_group_id)
75 );
76 let mut req_builder = configuration
77 .client
78 .request(reqwest::Method::POST, &uri_str);
79
80 if let Some(ref user_agent) = configuration.user_agent {
81 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
82 }
83 if let Some(ref apikey) = configuration.api_key {
84 let key = apikey.key.clone();
85 let value = match apikey.prefix {
86 Some(ref prefix) => format!("{} {}", prefix, key),
87 None => key,
88 };
89 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
90 };
91 req_builder = req_builder.json(&p_body_req_archive);
92
93 let req = req_builder.build()?;
94 let resp = configuration.client.execute(req).await?;
95
96 let status = resp.status();
97 let content_type = resp
98 .headers()
99 .get("content-type")
100 .and_then(|v| v.to_str().ok())
101 .unwrap_or("application/octet-stream");
102 let content_type = super::ContentType::from(content_type);
103
104 if !status.is_client_error() && !status.is_server_error() {
105 let content = resp.text().await?;
106 match content_type {
107 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
108 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespResourceUrl`"))),
109 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`")))),
110 }
111 } else {
112 let content = resp.text().await?;
113 let entity: Option<CreateArchiveError> = serde_json::from_str(&content).ok();
114 Err(Error::ResponseError(ResponseContent {
115 status,
116 content,
117 entity,
118 }))
119 }
120}
121
122pub async fn get_archive(
124 configuration: &configuration::Configuration,
125 group_id: &str,
126 archive_id: &str,
127) -> Result<models::RespArchive, Error<GetArchiveError>> {
128 let p_path_group_id = group_id;
130 let p_path_archive_id = archive_id;
131
132 let uri_str = format!(
133 "{}/v3/workflows/groups/{group_id}/archives/{archive_id}",
134 configuration.base_path,
135 group_id = crate::apis::urlencode(p_path_group_id),
136 archive_id = crate::apis::urlencode(p_path_archive_id)
137 );
138 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
139
140 if let Some(ref user_agent) = configuration.user_agent {
141 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142 }
143 if let Some(ref apikey) = configuration.api_key {
144 let key = apikey.key.clone();
145 let value = match apikey.prefix {
146 Some(ref prefix) => format!("{} {}", prefix, key),
147 None => key,
148 };
149 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
150 };
151
152 let req = req_builder.build()?;
153 let resp = configuration.client.execute(req).await?;
154
155 let status = resp.status();
156 let content_type = resp
157 .headers()
158 .get("content-type")
159 .and_then(|v| v.to_str().ok())
160 .unwrap_or("application/octet-stream");
161 let content_type = super::ContentType::from(content_type);
162
163 if !status.is_client_error() && !status.is_server_error() {
164 let content = resp.text().await?;
165 match content_type {
166 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
167 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespArchive`"))),
168 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespArchive`")))),
169 }
170 } else {
171 let content = resp.text().await?;
172 let entity: Option<GetArchiveError> = serde_json::from_str(&content).ok();
173 Err(Error::ResponseError(ResponseContent {
174 status,
175 content,
176 entity,
177 }))
178 }
179}
180
181pub async fn list_archives(
183 configuration: &configuration::Configuration,
184 group_id: &str,
185) -> Result<models::RespArchiveList, Error<ListArchivesError>> {
186 let p_path_group_id = group_id;
188
189 let uri_str = format!(
190 "{}/v3/workflows/groups/{group_id}/archives",
191 configuration.base_path,
192 group_id = crate::apis::urlencode(p_path_group_id)
193 );
194 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
195
196 if let Some(ref user_agent) = configuration.user_agent {
197 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
198 }
199 if let Some(ref apikey) = configuration.api_key {
200 let key = apikey.key.clone();
201 let value = match apikey.prefix {
202 Some(ref prefix) => format!("{} {}", prefix, key),
203 None => key,
204 };
205 req_builder = req_builder.header("X-TAPIS-TOKEN", value);
206 };
207
208 let req = req_builder.build()?;
209 let resp = configuration.client.execute(req).await?;
210
211 let status = resp.status();
212 let content_type = resp
213 .headers()
214 .get("content-type")
215 .and_then(|v| v.to_str().ok())
216 .unwrap_or("application/octet-stream");
217 let content_type = super::ContentType::from(content_type);
218
219 if !status.is_client_error() && !status.is_server_error() {
220 let content = resp.text().await?;
221 match content_type {
222 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
223 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespArchiveList`"))),
224 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespArchiveList`")))),
225 }
226 } else {
227 let content = resp.text().await?;
228 let entity: Option<ListArchivesError> = serde_json::from_str(&content).ok();
229 Err(Error::ResponseError(ResponseContent {
230 status,
231 content,
232 entity,
233 }))
234 }
235}