Skip to main content

clientapi_pbs/apis/
admin_gc_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_gc_get_admin_gc_by_store`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AdminGcGetAdminGcByStoreError {
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_gc_get_gc`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AdminGcGetGcError {
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
47/// List all GC jobs (max one per datastore)  Permissions: Requires Datastore.Audit or Datastore.Modify on datastore.
48pub async fn admin_gc_get_admin_gc_by_store(configuration: &configuration::Configuration, store: &str) -> Result<models::AdminGcGetAdminGcByStoreResponse, Error<AdminGcGetAdminGcByStoreError>> {
49    // add a prefix to parameters to efficiently prevent name collisions
50    let p_path_store = store;
51
52    let uri_str = format!("{}/admin/gc/{store}", configuration.base_path, store=crate::apis::urlencode(p_path_store));
53    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
54
55    if let Some(ref user_agent) = configuration.user_agent {
56        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
57    }
58    if let Some(ref apikey) = configuration.api_key {
59        let key = apikey.key.clone();
60        let value = match apikey.prefix {
61            Some(ref prefix) => format!("{} {}", prefix, key),
62            None => key,
63        };
64        req_builder = req_builder.header("Authorization", value);
65    };
66    if let Some(ref apikey) = configuration.api_key {
67        let key = apikey.key.clone();
68        let value = match apikey.prefix {
69            Some(ref prefix) => format!("{} {}", prefix, key),
70            None => key,
71        };
72        req_builder = req_builder.header("CSRFPreventionToken", value);
73    };
74
75    let req = req_builder.build()?;
76    let resp = configuration.client.execute(req).await?;
77
78    let status = resp.status();
79    let content_type = resp
80        .headers()
81        .get("content-type")
82        .and_then(|v| v.to_str().ok())
83        .unwrap_or("application/octet-stream");
84    let content_type = super::ContentType::from(content_type);
85
86    if !status.is_client_error() && !status.is_server_error() {
87        let content = resp.text().await?;
88        match content_type {
89            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
90            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminGcGetAdminGcByStoreResponse`"))),
91            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::AdminGcGetAdminGcByStoreResponse`")))),
92        }
93    } else {
94        let content = resp.text().await?;
95        let entity: Option<AdminGcGetAdminGcByStoreError> = serde_json::from_str(&content).ok();
96        Err(Error::ResponseError(ResponseContent { status, content, entity }))
97    }
98}
99
100/// List all GC jobs (max one per datastore)  Permissions: Requires Datastore.Audit or Datastore.Modify on datastore.
101pub async fn admin_gc_get_gc(configuration: &configuration::Configuration, store: Option<&str>) -> Result<models::AdminGcGetGcResponse, Error<AdminGcGetGcError>> {
102    // add a prefix to parameters to efficiently prevent name collisions
103    let p_query_store = store;
104
105    let uri_str = format!("{}/admin/gc", configuration.base_path);
106    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
107
108    if let Some(ref param_value) = p_query_store {
109        req_builder = req_builder.query(&[("store", &param_value.to_string())]);
110    }
111    if let Some(ref user_agent) = configuration.user_agent {
112        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
113    }
114    if let Some(ref apikey) = configuration.api_key {
115        let key = apikey.key.clone();
116        let value = match apikey.prefix {
117            Some(ref prefix) => format!("{} {}", prefix, key),
118            None => key,
119        };
120        req_builder = req_builder.header("Authorization", value);
121    };
122    if let Some(ref apikey) = configuration.api_key {
123        let key = apikey.key.clone();
124        let value = match apikey.prefix {
125            Some(ref prefix) => format!("{} {}", prefix, key),
126            None => key,
127        };
128        req_builder = req_builder.header("CSRFPreventionToken", value);
129    };
130
131    let req = req_builder.build()?;
132    let resp = configuration.client.execute(req).await?;
133
134    let status = resp.status();
135    let content_type = resp
136        .headers()
137        .get("content-type")
138        .and_then(|v| v.to_str().ok())
139        .unwrap_or("application/octet-stream");
140    let content_type = super::ContentType::from(content_type);
141
142    if !status.is_client_error() && !status.is_server_error() {
143        let content = resp.text().await?;
144        match content_type {
145            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
146            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminGcGetGcResponse`"))),
147            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::AdminGcGetGcResponse`")))),
148        }
149    } else {
150        let content = resp.text().await?;
151        let entity: Option<AdminGcGetGcError> = serde_json::from_str(&content).ok();
152        Err(Error::ResponseError(ResponseContent { status, content, entity }))
153    }
154}
155