artcoded_api/apis/
mongo_management_controller_api.rs

1/*
2 * Artcoded
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.0.0
7 *
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 [`download`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum DownloadError {
20    UnknownValue(serde_json::Value),
21}
22
23/// struct for typed errors of method [`dump_list`]
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum DumpListError {
27    UnknownValue(serde_json::Value),
28}
29
30pub async fn download(
31    configuration: &configuration::Configuration,
32    archive_name: &str,
33    snapshot: Option<bool>,
34) -> Result<reqwest::Response, Error<DownloadError>> {
35    // add a prefix to parameters to efficiently prevent name collisions
36    let p_query_archive_name = archive_name;
37    let p_query_snapshot = snapshot;
38
39    let uri_str = format!("{}/api/mongo-management/download", configuration.base_path);
40    let mut req_builder = configuration
41        .client
42        .request(reqwest::Method::POST, &uri_str);
43
44    req_builder = req_builder.query(&[("archiveName", &p_query_archive_name.to_string())]);
45    if let Some(ref param_value) = p_query_snapshot {
46        req_builder = req_builder.query(&[("snapshot", &param_value.to_string())]);
47    }
48    if let Some(ref user_agent) = configuration.user_agent {
49        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
50    }
51    if let Some(ref token) = configuration.bearer_access_token {
52        req_builder = req_builder.bearer_auth(token.to_owned());
53    };
54
55    let req = req_builder.build()?;
56    let resp = configuration.client.execute(req).await?;
57
58    let status = resp.status();
59
60    if !status.is_client_error() && !status.is_server_error() {
61        Ok(resp)
62    } else {
63        let content = resp.text().await?;
64        let entity: Option<DownloadError> = serde_json::from_str(&content).ok();
65        Err(Error::ResponseError(ResponseContent {
66            status,
67            content,
68            entity,
69        }))
70    }
71}
72
73pub async fn dump_list(
74    configuration: &configuration::Configuration,
75    snapshot: Option<bool>,
76) -> Result<Vec<String>, Error<DumpListError>> {
77    // add a prefix to parameters to efficiently prevent name collisions
78    let p_query_snapshot = snapshot;
79
80    let uri_str = format!("{}/api/mongo-management", configuration.base_path);
81    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
82
83    if let Some(ref param_value) = p_query_snapshot {
84        req_builder = req_builder.query(&[("snapshot", &param_value.to_string())]);
85    }
86    if let Some(ref user_agent) = configuration.user_agent {
87        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88    }
89    if let Some(ref token) = configuration.bearer_access_token {
90        req_builder = req_builder.bearer_auth(token.to_owned());
91    };
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 `Vec&lt;String&gt;`"))),
109            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;String&gt;`")))),
110        }
111    } else {
112        let content = resp.text().await?;
113        let entity: Option<DumpListError> = serde_json::from_str(&content).ok();
114        Err(Error::ResponseError(ResponseContent {
115            status,
116            content,
117            entity,
118        }))
119    }
120}