1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateWorkspaceError {
22 Status400(models::ErrorGeneric),
23 Status401(models::ErrorGeneric),
24 Status403(models::ErrorGeneric),
25 Status500(models::ErrorGeneric),
26 DefaultResponse(models::ErrorGeneric),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum CreateWorkspaceApiKeyError {
34 DefaultResponse(models::ErrorGeneric),
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum DeleteWorkspaceApiKeyError {
42 DefaultResponse(models::ErrorGeneric),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetWorkspaceError {
50 Status400(models::ErrorGeneric),
51 Status401(models::ErrorGeneric),
52 Status403(models::ErrorGeneric),
53 Status500(models::ErrorGeneric),
54 DefaultResponse(models::ErrorGeneric),
55 UnknownValue(serde_json::Value),
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum ListWorkspaceApiKeysError {
62 DefaultResponse(models::ErrorGeneric),
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum ListWorkspaceProjectsError {
70 Status400(models::ErrorGeneric),
71 Status401(models::ErrorGeneric),
72 Status403(models::ErrorGeneric),
73 Status500(models::ErrorGeneric),
74 DefaultResponse(models::ErrorGeneric),
75 UnknownValue(serde_json::Value),
76}
77
78#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum ListWorkspacesError {
82 Status400(models::ErrorGeneric),
83 Status401(models::ErrorGeneric),
84 Status403(models::ErrorGeneric),
85 Status500(models::ErrorGeneric),
86 DefaultResponse(models::ErrorGeneric),
87 UnknownValue(serde_json::Value),
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum UpdateWorkspaceError {
94 Status400(models::ErrorGeneric),
95 Status401(models::ErrorGeneric),
96 Status403(models::ErrorGeneric),
97 Status500(models::ErrorGeneric),
98 DefaultResponse(models::ErrorGeneric),
99 UnknownValue(serde_json::Value),
100}
101
102
103pub async fn create_workspace(configuration: &configuration::Configuration, create_workspace_body: Option<models::CreateWorkspaceBody>) -> Result<models::Workspace, Error<CreateWorkspaceError>> {
104 let p_create_workspace_body = create_workspace_body;
106
107 let uri_str = format!("{}/workspaces", configuration.base_path);
108 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
109
110 if let Some(ref user_agent) = configuration.user_agent {
111 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112 }
113 if let Some(ref token) = configuration.bearer_access_token {
114 req_builder = req_builder.bearer_auth(token.to_owned());
115 };
116 req_builder = req_builder.json(&p_create_workspace_body);
117
118 let req = req_builder.build()?;
119 let resp = configuration.client.execute(req).await?;
120
121 let status = resp.status();
122 let content_type = resp
123 .headers()
124 .get("content-type")
125 .and_then(|v| v.to_str().ok())
126 .unwrap_or("application/octet-stream");
127 let content_type = super::ContentType::from(content_type);
128
129 if !status.is_client_error() && !status.is_server_error() {
130 let content = resp.text().await?;
131 match content_type {
132 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
133 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Workspace`"))),
134 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Workspace`")))),
135 }
136 } else {
137 let content = resp.text().await?;
138 let entity: Option<CreateWorkspaceError> = serde_json::from_str(&content).ok();
139 Err(Error::ResponseError(ResponseContent { status, content, entity }))
140 }
141}
142
143pub async fn create_workspace_api_key(configuration: &configuration::Configuration, workspace: &str, create_workspace_api_key_body: Option<models::CreateWorkspaceApiKeyBody>) -> Result<models::WorkspaceApiKey, Error<CreateWorkspaceApiKeyError>> {
145 let p_workspace = workspace;
147 let p_create_workspace_api_key_body = create_workspace_api_key_body;
148
149 let uri_str = format!("{}/workspaces/{workspace}/tokens", configuration.base_path, workspace=crate::apis::urlencode(p_workspace));
150 let mut req_builder = configuration.client.request(reqwest::Method::POST, &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 token) = configuration.bearer_access_token {
156 req_builder = req_builder.bearer_auth(token.to_owned());
157 };
158 req_builder = req_builder.json(&p_create_workspace_api_key_body);
159
160 let req = req_builder.build()?;
161 let resp = configuration.client.execute(req).await?;
162
163 let status = resp.status();
164 let content_type = resp
165 .headers()
166 .get("content-type")
167 .and_then(|v| v.to_str().ok())
168 .unwrap_or("application/octet-stream");
169 let content_type = super::ContentType::from(content_type);
170
171 if !status.is_client_error() && !status.is_server_error() {
172 let content = resp.text().await?;
173 match content_type {
174 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
175 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WorkspaceApiKey`"))),
176 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WorkspaceApiKey`")))),
177 }
178 } else {
179 let content = resp.text().await?;
180 let entity: Option<CreateWorkspaceApiKeyError> = serde_json::from_str(&content).ok();
181 Err(Error::ResponseError(ResponseContent { status, content, entity }))
182 }
183}
184
185pub async fn delete_workspace_api_key(configuration: &configuration::Configuration, workspace: &str, token_id: &str) -> Result<(), Error<DeleteWorkspaceApiKeyError>> {
187 let p_workspace = workspace;
189 let p_token_id = token_id;
190
191 let uri_str = format!("{}/workspaces/{workspace}/tokens/{token_id}", configuration.base_path, workspace=crate::apis::urlencode(p_workspace), token_id=crate::apis::urlencode(p_token_id));
192 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
193
194 if let Some(ref user_agent) = configuration.user_agent {
195 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
196 }
197 if let Some(ref token) = configuration.bearer_access_token {
198 req_builder = req_builder.bearer_auth(token.to_owned());
199 };
200
201 let req = req_builder.build()?;
202 let resp = configuration.client.execute(req).await?;
203
204 let status = resp.status();
205
206 if !status.is_client_error() && !status.is_server_error() {
207 Ok(())
208 } else {
209 let content = resp.text().await?;
210 let entity: Option<DeleteWorkspaceApiKeyError> = serde_json::from_str(&content).ok();
211 Err(Error::ResponseError(ResponseContent { status, content, entity }))
212 }
213}
214
215pub async fn get_workspace(configuration: &configuration::Configuration, workspace: &str) -> Result<models::Workspace, Error<GetWorkspaceError>> {
217 let p_workspace = workspace;
219
220 let uri_str = format!("{}/workspaces/{workspace}", configuration.base_path, workspace=crate::apis::urlencode(p_workspace));
221 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
222
223 if let Some(ref user_agent) = configuration.user_agent {
224 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
225 }
226 if let Some(ref token) = configuration.bearer_access_token {
227 req_builder = req_builder.bearer_auth(token.to_owned());
228 };
229
230 let req = req_builder.build()?;
231 let resp = configuration.client.execute(req).await?;
232
233 let status = resp.status();
234 let content_type = resp
235 .headers()
236 .get("content-type")
237 .and_then(|v| v.to_str().ok())
238 .unwrap_or("application/octet-stream");
239 let content_type = super::ContentType::from(content_type);
240
241 if !status.is_client_error() && !status.is_server_error() {
242 let content = resp.text().await?;
243 match content_type {
244 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
245 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Workspace`"))),
246 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Workspace`")))),
247 }
248 } else {
249 let content = resp.text().await?;
250 let entity: Option<GetWorkspaceError> = serde_json::from_str(&content).ok();
251 Err(Error::ResponseError(ResponseContent { status, content, entity }))
252 }
253}
254
255pub async fn list_workspace_api_keys(configuration: &configuration::Configuration, workspace: &str) -> Result<Vec<models::WorkspaceApiKey>, Error<ListWorkspaceApiKeysError>> {
257 let p_workspace = workspace;
259
260 let uri_str = format!("{}/workspaces/{workspace}/tokens", configuration.base_path, workspace=crate::apis::urlencode(p_workspace));
261 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
262
263 if let Some(ref user_agent) = configuration.user_agent {
264 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
265 }
266 if let Some(ref token) = configuration.bearer_access_token {
267 req_builder = req_builder.bearer_auth(token.to_owned());
268 };
269
270 let req = req_builder.build()?;
271 let resp = configuration.client.execute(req).await?;
272
273 let status = resp.status();
274 let content_type = resp
275 .headers()
276 .get("content-type")
277 .and_then(|v| v.to_str().ok())
278 .unwrap_or("application/octet-stream");
279 let content_type = super::ContentType::from(content_type);
280
281 if !status.is_client_error() && !status.is_server_error() {
282 let content = resp.text().await?;
283 match content_type {
284 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
285 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::WorkspaceApiKey>`"))),
286 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::WorkspaceApiKey>`")))),
287 }
288 } else {
289 let content = resp.text().await?;
290 let entity: Option<ListWorkspaceApiKeysError> = serde_json::from_str(&content).ok();
291 Err(Error::ResponseError(ResponseContent { status, content, entity }))
292 }
293}
294
295pub async fn list_workspace_projects(configuration: &configuration::Configuration, workspace: &str) -> Result<models::ListWorkspaceProjects, Error<ListWorkspaceProjectsError>> {
297 let p_workspace = workspace;
299
300 let uri_str = format!("{}/workspaces/{workspace}/projects", configuration.base_path, workspace=crate::apis::urlencode(p_workspace));
301 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
302
303 if let Some(ref user_agent) = configuration.user_agent {
304 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
305 }
306 if let Some(ref token) = configuration.bearer_access_token {
307 req_builder = req_builder.bearer_auth(token.to_owned());
308 };
309
310 let req = req_builder.build()?;
311 let resp = configuration.client.execute(req).await?;
312
313 let status = resp.status();
314 let content_type = resp
315 .headers()
316 .get("content-type")
317 .and_then(|v| v.to_str().ok())
318 .unwrap_or("application/octet-stream");
319 let content_type = super::ContentType::from(content_type);
320
321 if !status.is_client_error() && !status.is_server_error() {
322 let content = resp.text().await?;
323 match content_type {
324 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
325 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWorkspaceProjects`"))),
326 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListWorkspaceProjects`")))),
327 }
328 } else {
329 let content = resp.text().await?;
330 let entity: Option<ListWorkspaceProjectsError> = serde_json::from_str(&content).ok();
331 Err(Error::ResponseError(ResponseContent { status, content, entity }))
332 }
333}
334
335pub async fn list_workspaces(configuration: &configuration::Configuration, page_size: Option<i64>, page_token: Option<&str>) -> Result<models::ListWorkspaces, Error<ListWorkspacesError>> {
336 let p_page_size = page_size;
338 let p_page_token = page_token;
339
340 let uri_str = format!("{}/workspaces", configuration.base_path);
341 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
342
343 if let Some(ref param_value) = p_page_size {
344 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
345 }
346 if let Some(ref param_value) = p_page_token {
347 req_builder = req_builder.query(&[("page_token", ¶m_value.to_string())]);
348 }
349 if let Some(ref user_agent) = configuration.user_agent {
350 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
351 }
352 if let Some(ref token) = configuration.bearer_access_token {
353 req_builder = req_builder.bearer_auth(token.to_owned());
354 };
355
356 let req = req_builder.build()?;
357 let resp = configuration.client.execute(req).await?;
358
359 let status = resp.status();
360 let content_type = resp
361 .headers()
362 .get("content-type")
363 .and_then(|v| v.to_str().ok())
364 .unwrap_or("application/octet-stream");
365 let content_type = super::ContentType::from(content_type);
366
367 if !status.is_client_error() && !status.is_server_error() {
368 let content = resp.text().await?;
369 match content_type {
370 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
371 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWorkspaces`"))),
372 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListWorkspaces`")))),
373 }
374 } else {
375 let content = resp.text().await?;
376 let entity: Option<ListWorkspacesError> = serde_json::from_str(&content).ok();
377 Err(Error::ResponseError(ResponseContent { status, content, entity }))
378 }
379}
380
381pub async fn update_workspace(configuration: &configuration::Configuration, workspace: &str, update_workspace_body: Option<models::UpdateWorkspaceBody>) -> Result<models::Workspace, Error<UpdateWorkspaceError>> {
383 let p_workspace = workspace;
385 let p_update_workspace_body = update_workspace_body;
386
387 let uri_str = format!("{}/workspaces/{workspace}", configuration.base_path, workspace=crate::apis::urlencode(p_workspace));
388 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
389
390 if let Some(ref user_agent) = configuration.user_agent {
391 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
392 }
393 if let Some(ref token) = configuration.bearer_access_token {
394 req_builder = req_builder.bearer_auth(token.to_owned());
395 };
396 req_builder = req_builder.json(&p_update_workspace_body);
397
398 let req = req_builder.build()?;
399 let resp = configuration.client.execute(req).await?;
400
401 let status = resp.status();
402 let content_type = resp
403 .headers()
404 .get("content-type")
405 .and_then(|v| v.to_str().ok())
406 .unwrap_or("application/octet-stream");
407 let content_type = super::ContentType::from(content_type);
408
409 if !status.is_client_error() && !status.is_server_error() {
410 let content = resp.text().await?;
411 match content_type {
412 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
413 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Workspace`"))),
414 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Workspace`")))),
415 }
416 } else {
417 let content = resp.text().await?;
418 let entity: Option<UpdateWorkspaceError> = serde_json::from_str(&content).ok();
419 Err(Error::ResponseError(ResponseContent { status, content, entity }))
420 }
421}
422