Skip to main content

clientapi_pbs/apis/
admin_sync_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_sync_create_run`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AdminSyncCreateRunError {
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_sync_get_admin_sync_by_id`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AdminSyncGetAdminSyncByIdError {
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_sync_get_sync`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum AdminSyncGetSyncError {
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/// Runs the sync jobs manually.  Permissions: User needs Datastore.Backup on target datastore, and Remote.Read on source remote. Additionally, remove_vanished requires Datastore.Prune, and any owner other than the user themselves requires Datastore.Modify
62pub async fn admin_sync_create_run(configuration: &configuration::Configuration, id: &str) -> Result<models::AdminSyncCreateRunResponse, Error<AdminSyncCreateRunError>> {
63    // add a prefix to parameters to efficiently prevent name collisions
64    let p_path_id = id;
65
66    let uri_str = format!("{}/admin/sync/{id}/run", configuration.base_path, id=crate::apis::urlencode(p_path_id));
67    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
68
69    if let Some(ref user_agent) = configuration.user_agent {
70        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71    }
72    if let Some(ref apikey) = configuration.api_key {
73        let key = apikey.key.clone();
74        let value = match apikey.prefix {
75            Some(ref prefix) => format!("{} {}", prefix, key),
76            None => key,
77        };
78        req_builder = req_builder.header("Authorization", value);
79    };
80    if let Some(ref apikey) = configuration.api_key {
81        let key = apikey.key.clone();
82        let value = match apikey.prefix {
83            Some(ref prefix) => format!("{} {}", prefix, key),
84            None => key,
85        };
86        req_builder = req_builder.header("CSRFPreventionToken", value);
87    };
88
89    let req = req_builder.build()?;
90    let resp = configuration.client.execute(req).await?;
91
92    let status = resp.status();
93    let content_type = resp
94        .headers()
95        .get("content-type")
96        .and_then(|v| v.to_str().ok())
97        .unwrap_or("application/octet-stream");
98    let content_type = super::ContentType::from(content_type);
99
100    if !status.is_client_error() && !status.is_server_error() {
101        let content = resp.text().await?;
102        match content_type {
103            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
104            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminSyncCreateRunResponse`"))),
105            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::AdminSyncCreateRunResponse`")))),
106        }
107    } else {
108        let content = resp.text().await?;
109        let entity: Option<AdminSyncCreateRunError> = serde_json::from_str(&content).ok();
110        Err(Error::ResponseError(ResponseContent { status, content, entity }))
111    }
112}
113
114/// Directory index.
115pub async fn admin_sync_get_admin_sync_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::AdminSyncGetAdminSyncByIdResponse, Error<AdminSyncGetAdminSyncByIdError>> {
116    // add a prefix to parameters to efficiently prevent name collisions
117    let p_path_id = id;
118
119    let uri_str = format!("{}/admin/sync/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
120    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
121
122    if let Some(ref user_agent) = configuration.user_agent {
123        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124    }
125    if let Some(ref apikey) = configuration.api_key {
126        let key = apikey.key.clone();
127        let value = match apikey.prefix {
128            Some(ref prefix) => format!("{} {}", prefix, key),
129            None => key,
130        };
131        req_builder = req_builder.header("Authorization", value);
132    };
133    if let Some(ref apikey) = configuration.api_key {
134        let key = apikey.key.clone();
135        let value = match apikey.prefix {
136            Some(ref prefix) => format!("{} {}", prefix, key),
137            None => key,
138        };
139        req_builder = req_builder.header("CSRFPreventionToken", value);
140    };
141
142    let req = req_builder.build()?;
143    let resp = configuration.client.execute(req).await?;
144
145    let status = resp.status();
146    let content_type = resp
147        .headers()
148        .get("content-type")
149        .and_then(|v| v.to_str().ok())
150        .unwrap_or("application/octet-stream");
151    let content_type = super::ContentType::from(content_type);
152
153    if !status.is_client_error() && !status.is_server_error() {
154        let content = resp.text().await?;
155        match content_type {
156            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
157            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminSyncGetAdminSyncByIdResponse`"))),
158            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::AdminSyncGetAdminSyncByIdResponse`")))),
159        }
160    } else {
161        let content = resp.text().await?;
162        let entity: Option<AdminSyncGetAdminSyncByIdError> = serde_json::from_str(&content).ok();
163        Err(Error::ResponseError(ResponseContent { status, content, entity }))
164    }
165}
166
167/// List all configured sync jobs  Permissions: Limited to sync jobs where user has Datastore.Audit on target datastore, and Remote.Audit on source remote.
168pub async fn admin_sync_get_sync(configuration: &configuration::Configuration, store: Option<&str>, sync_direction: Option<models::PbsSyncDirectionEnum>) -> Result<models::AdminSyncGetSyncResponse, Error<AdminSyncGetSyncError>> {
169    // add a prefix to parameters to efficiently prevent name collisions
170    let p_query_store = store;
171    let p_query_sync_direction = sync_direction;
172
173    let uri_str = format!("{}/admin/sync", configuration.base_path);
174    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
175
176    if let Some(ref param_value) = p_query_store {
177        req_builder = req_builder.query(&[("store", &param_value.to_string())]);
178    }
179    if let Some(ref param_value) = p_query_sync_direction {
180        req_builder = req_builder.query(&[("sync-direction", &param_value.to_string())]);
181    }
182    if let Some(ref user_agent) = configuration.user_agent {
183        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
184    }
185    if let Some(ref apikey) = configuration.api_key {
186        let key = apikey.key.clone();
187        let value = match apikey.prefix {
188            Some(ref prefix) => format!("{} {}", prefix, key),
189            None => key,
190        };
191        req_builder = req_builder.header("Authorization", value);
192    };
193    if let Some(ref apikey) = configuration.api_key {
194        let key = apikey.key.clone();
195        let value = match apikey.prefix {
196            Some(ref prefix) => format!("{} {}", prefix, key),
197            None => key,
198        };
199        req_builder = req_builder.header("CSRFPreventionToken", value);
200    };
201
202    let req = req_builder.build()?;
203    let resp = configuration.client.execute(req).await?;
204
205    let status = resp.status();
206    let content_type = resp
207        .headers()
208        .get("content-type")
209        .and_then(|v| v.to_str().ok())
210        .unwrap_or("application/octet-stream");
211    let content_type = super::ContentType::from(content_type);
212
213    if !status.is_client_error() && !status.is_server_error() {
214        let content = resp.text().await?;
215        match content_type {
216            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
217            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdminSyncGetSyncResponse`"))),
218            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::AdminSyncGetSyncResponse`")))),
219        }
220    } else {
221        let content = resp.text().await?;
222        let entity: Option<AdminSyncGetSyncError> = serde_json::from_str(&content).ok();
223        Err(Error::ResponseError(ResponseContent { status, content, entity }))
224    }
225}
226