Skip to main content

clientapi_pbs/apis/
admin_api.rs

1/*
2 * Proxmox Backup Server API
3 *
4 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pbs.proxmox.com/docs/api-viewer/ for the upstream documentation.
5 *
6 * The version of the OpenAPI document: 9.x
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`admin_get_admin`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AdminGetAdminError {
22    Status400(models::PbsError),
23    Status401(models::PbsError),
24    Status403(models::PbsError),
25    Status404(models::PbsError),
26    Status500(models::PbsError),
27    Status501(models::PbsError),
28    Status503(models::PbsError),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`admin_get_metrics`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AdminGetMetricsError {
36    Status400(models::PbsError),
37    Status401(models::PbsError),
38    Status403(models::PbsError),
39    Status404(models::PbsError),
40    Status500(models::PbsError),
41    Status501(models::PbsError),
42    Status503(models::PbsError),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`admin_get_traffic_control`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum AdminGetTrafficControlError {
50    Status400(models::PbsError),
51    Status401(models::PbsError),
52    Status403(models::PbsError),
53    Status404(models::PbsError),
54    Status500(models::PbsError),
55    Status501(models::PbsError),
56    Status503(models::PbsError),
57    UnknownValue(serde_json::Value),
58}
59
60
61/// Directory index.
62pub async fn admin_get_admin(configuration: &configuration::Configuration, ) -> Result<models::AdminGetAdminResponse, Error<AdminGetAdminError>> {
63
64    let uri_str = format!("{}/admin", configuration.base_path);
65    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
66
67    if let Some(ref user_agent) = configuration.user_agent {
68        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
69    }
70    if let Some(ref apikey) = configuration.api_key {
71        let key = apikey.key.clone();
72        let value = match apikey.prefix {
73            Some(ref prefix) => format!("{} {}", prefix, key),
74            None => key,
75        };
76        req_builder = req_builder.header("Authorization", value);
77    };
78    if let Some(ref apikey) = configuration.api_key {
79        let key = apikey.key.clone();
80        let value = match apikey.prefix {
81            Some(ref prefix) => format!("{} {}", prefix, key),
82            None => key,
83        };
84        req_builder = req_builder.header("CSRFPreventionToken", value);
85    };
86
87    let req = req_builder.build()?;
88    let resp = configuration.client.execute(req).await?;
89
90    let status = resp.status();
91    let content_type = resp
92        .headers()
93        .get("content-type")
94        .and_then(|v| v.to_str().ok())
95        .unwrap_or("application/octet-stream");
96    let content_type = super::ContentType::from(content_type);
97
98    if !status.is_client_error() && !status.is_server_error() {
99        let content = resp.text().await?;
100        match content_type {
101            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
102            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminGetAdminResponse`"))),
103            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::AdminGetAdminResponse`")))),
104        }
105    } else {
106        let content = resp.text().await?;
107        let entity: Option<AdminGetAdminError> = serde_json::from_str(&content).ok();
108        Err(Error::ResponseError(ResponseContent { status, content, entity }))
109    }
110}
111
112/// List configured metric servers.
113pub async fn admin_get_metrics(configuration: &configuration::Configuration, ) -> Result<models::AdminGetMetricsResponse, Error<AdminGetMetricsError>> {
114
115    let uri_str = format!("{}/admin/metrics", configuration.base_path);
116    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
117
118    if let Some(ref user_agent) = configuration.user_agent {
119        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
120    }
121    if let Some(ref apikey) = configuration.api_key {
122        let key = apikey.key.clone();
123        let value = match apikey.prefix {
124            Some(ref prefix) => format!("{} {}", prefix, key),
125            None => key,
126        };
127        req_builder = req_builder.header("Authorization", value);
128    };
129    if let Some(ref apikey) = configuration.api_key {
130        let key = apikey.key.clone();
131        let value = match apikey.prefix {
132            Some(ref prefix) => format!("{} {}", prefix, key),
133            None => key,
134        };
135        req_builder = req_builder.header("CSRFPreventionToken", value);
136    };
137
138    let req = req_builder.build()?;
139    let resp = configuration.client.execute(req).await?;
140
141    let status = resp.status();
142    let content_type = resp
143        .headers()
144        .get("content-type")
145        .and_then(|v| v.to_str().ok())
146        .unwrap_or("application/octet-stream");
147    let content_type = super::ContentType::from(content_type);
148
149    if !status.is_client_error() && !status.is_server_error() {
150        let content = resp.text().await?;
151        match content_type {
152            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
153            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminGetMetricsResponse`"))),
154            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::AdminGetMetricsResponse`")))),
155        }
156    } else {
157        let content = resp.text().await?;
158        let entity: Option<AdminGetMetricsError> = serde_json::from_str(&content).ok();
159        Err(Error::ResponseError(ResponseContent { status, content, entity }))
160    }
161}
162
163/// Show current traffic for all traffic control rules.
164pub async fn admin_get_traffic_control(configuration: &configuration::Configuration, ) -> Result<models::AdminGetTrafficControlResponse, Error<AdminGetTrafficControlError>> {
165
166    let uri_str = format!("{}/admin/traffic-control", configuration.base_path);
167    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
168
169    if let Some(ref user_agent) = configuration.user_agent {
170        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171    }
172    if let Some(ref apikey) = configuration.api_key {
173        let key = apikey.key.clone();
174        let value = match apikey.prefix {
175            Some(ref prefix) => format!("{} {}", prefix, key),
176            None => key,
177        };
178        req_builder = req_builder.header("Authorization", value);
179    };
180    if let Some(ref apikey) = configuration.api_key {
181        let key = apikey.key.clone();
182        let value = match apikey.prefix {
183            Some(ref prefix) => format!("{} {}", prefix, key),
184            None => key,
185        };
186        req_builder = req_builder.header("CSRFPreventionToken", value);
187    };
188
189    let req = req_builder.build()?;
190    let resp = configuration.client.execute(req).await?;
191
192    let status = resp.status();
193    let content_type = resp
194        .headers()
195        .get("content-type")
196        .and_then(|v| v.to_str().ok())
197        .unwrap_or("application/octet-stream");
198    let content_type = super::ContentType::from(content_type);
199
200    if !status.is_client_error() && !status.is_server_error() {
201        let content = resp.text().await?;
202        match content_type {
203            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
204            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminGetTrafficControlResponse`"))),
205            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::AdminGetTrafficControlResponse`")))),
206        }
207    } else {
208        let content = resp.text().await?;
209        let entity: Option<AdminGetTrafficControlError> = serde_json::from_str(&content).ok();
210        Err(Error::ResponseError(ResponseContent { status, content, entity }))
211    }
212}
213