Skip to main content

clientapi_pbs/apis/
config_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 [`config_sync_create_sync`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ConfigSyncCreateSyncError {
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 [`config_sync_delete_sync`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ConfigSyncDeleteSyncError {
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 [`config_sync_get_config_sync_by_id`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ConfigSyncGetConfigSyncByIdError {
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/// struct for typed errors of method [`config_sync_get_sync`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ConfigSyncGetSyncError {
64    Status400(models::PbsError),
65    Status401(models::PbsError),
66    Status403(models::PbsError),
67    Status404(models::PbsError),
68    Status500(models::PbsError),
69    Status501(models::PbsError),
70    Status503(models::PbsError),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`config_sync_update_sync`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ConfigSyncUpdateSyncError {
78    Status400(models::PbsError),
79    Status401(models::PbsError),
80    Status403(models::PbsError),
81    Status404(models::PbsError),
82    Status500(models::PbsError),
83    Status501(models::PbsError),
84    Status503(models::PbsError),
85    UnknownValue(serde_json::Value),
86}
87
88
89/// Create a new sync job.  Permissions: For sync jobs in pull direction 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. For sync jobs in push direction, user needs RemoteDatastore.Backup on remote datastore, and Datastore.Audit, Datastore.Read and Datastore.Modify on the source datastore, the latter not required sync job owned by user. Additionally, remove vanished requires RemoteDatastore.Modify.
90pub async fn config_sync_create_sync(configuration: &configuration::Configuration, config_sync_create_sync_request: models::ConfigSyncCreateSyncRequest) -> Result<models::ConfigSyncCreateSyncResponse, Error<ConfigSyncCreateSyncError>> {
91    // add a prefix to parameters to efficiently prevent name collisions
92    let p_body_config_sync_create_sync_request = config_sync_create_sync_request;
93
94    let uri_str = format!("{}/config/sync", configuration.base_path);
95    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
96
97    if let Some(ref user_agent) = configuration.user_agent {
98        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
99    }
100    if let Some(ref apikey) = configuration.api_key {
101        let key = apikey.key.clone();
102        let value = match apikey.prefix {
103            Some(ref prefix) => format!("{} {}", prefix, key),
104            None => key,
105        };
106        req_builder = req_builder.header("Authorization", value);
107    };
108    if let Some(ref apikey) = configuration.api_key {
109        let key = apikey.key.clone();
110        let value = match apikey.prefix {
111            Some(ref prefix) => format!("{} {}", prefix, key),
112            None => key,
113        };
114        req_builder = req_builder.header("CSRFPreventionToken", value);
115    };
116    req_builder = req_builder.json(&p_body_config_sync_create_sync_request);
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::ConfigSyncCreateSyncResponse`"))),
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::ConfigSyncCreateSyncResponse`")))),
135        }
136    } else {
137        let content = resp.text().await?;
138        let entity: Option<ConfigSyncCreateSyncError> = serde_json::from_str(&content).ok();
139        Err(Error::ResponseError(ResponseContent { status, content, entity }))
140    }
141}
142
143/// Remove a sync job configuration  Permissions: For sync jobs in pull direction 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. For sync jobs in push direction, user needs RemoteDatastore.Backup on remote datastore, and Datastore.Audit, Datastore.Read and Datastore.Modify on the source datastore, the latter not required sync job owned by user. Additionally, remove vanished requires RemoteDatastore.Modify.
144pub async fn config_sync_delete_sync(configuration: &configuration::Configuration, id: &str, digest: Option<&str>) -> Result<models::ConfigSyncDeleteSyncResponse, Error<ConfigSyncDeleteSyncError>> {
145    // add a prefix to parameters to efficiently prevent name collisions
146    let p_path_id = id;
147    let p_query_digest = digest;
148
149    let uri_str = format!("{}/config/sync/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
150    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
151
152    if let Some(ref param_value) = p_query_digest {
153        req_builder = req_builder.query(&[("digest", &param_value.to_string())]);
154    }
155    if let Some(ref user_agent) = configuration.user_agent {
156        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
157    }
158    if let Some(ref apikey) = configuration.api_key {
159        let key = apikey.key.clone();
160        let value = match apikey.prefix {
161            Some(ref prefix) => format!("{} {}", prefix, key),
162            None => key,
163        };
164        req_builder = req_builder.header("Authorization", value);
165    };
166    if let Some(ref apikey) = configuration.api_key {
167        let key = apikey.key.clone();
168        let value = match apikey.prefix {
169            Some(ref prefix) => format!("{} {}", prefix, key),
170            None => key,
171        };
172        req_builder = req_builder.header("CSRFPreventionToken", value);
173    };
174
175    let req = req_builder.build()?;
176    let resp = configuration.client.execute(req).await?;
177
178    let status = resp.status();
179    let content_type = resp
180        .headers()
181        .get("content-type")
182        .and_then(|v| v.to_str().ok())
183        .unwrap_or("application/octet-stream");
184    let content_type = super::ContentType::from(content_type);
185
186    if !status.is_client_error() && !status.is_server_error() {
187        let content = resp.text().await?;
188        match content_type {
189            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
190            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigSyncDeleteSyncResponse`"))),
191            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::ConfigSyncDeleteSyncResponse`")))),
192        }
193    } else {
194        let content = resp.text().await?;
195        let entity: Option<ConfigSyncDeleteSyncError> = serde_json::from_str(&content).ok();
196        Err(Error::ResponseError(ResponseContent { status, content, entity }))
197    }
198}
199
200/// Read a sync job configuration.  Permissions: Limited to sync job entries where user has Datastore.Audit on target datastore, and Remote.Audit on source remote for sync jobs in pull direction. For push direction the user requires RemoteDatastore.Audit on the remote datastore and Datastore.Audit on the local datastore.
201pub async fn config_sync_get_config_sync_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::ConfigSyncGetConfigSyncByIdResponse, Error<ConfigSyncGetConfigSyncByIdError>> {
202    // add a prefix to parameters to efficiently prevent name collisions
203    let p_path_id = id;
204
205    let uri_str = format!("{}/config/sync/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
206    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
207
208    if let Some(ref user_agent) = configuration.user_agent {
209        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
210    }
211    if let Some(ref apikey) = configuration.api_key {
212        let key = apikey.key.clone();
213        let value = match apikey.prefix {
214            Some(ref prefix) => format!("{} {}", prefix, key),
215            None => key,
216        };
217        req_builder = req_builder.header("Authorization", value);
218    };
219    if let Some(ref apikey) = configuration.api_key {
220        let key = apikey.key.clone();
221        let value = match apikey.prefix {
222            Some(ref prefix) => format!("{} {}", prefix, key),
223            None => key,
224        };
225        req_builder = req_builder.header("CSRFPreventionToken", value);
226    };
227
228    let req = req_builder.build()?;
229    let resp = configuration.client.execute(req).await?;
230
231    let status = resp.status();
232    let content_type = resp
233        .headers()
234        .get("content-type")
235        .and_then(|v| v.to_str().ok())
236        .unwrap_or("application/octet-stream");
237    let content_type = super::ContentType::from(content_type);
238
239    if !status.is_client_error() && !status.is_server_error() {
240        let content = resp.text().await?;
241        match content_type {
242            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
243            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigSyncGetConfigSyncByIdResponse`"))),
244            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::ConfigSyncGetConfigSyncByIdResponse`")))),
245        }
246    } else {
247        let content = resp.text().await?;
248        let entity: Option<ConfigSyncGetConfigSyncByIdError> = serde_json::from_str(&content).ok();
249        Err(Error::ResponseError(ResponseContent { status, content, entity }))
250    }
251}
252
253/// List all sync jobs  Permissions: Limited to sync job entries where user has Datastore.Audit on target datastore, and Remote.Audit on source remote for sync jobs in pull direction. For push direction the user requires RemoteDatastore.Audit on the remote datastore and Datastore.Audit on the local datastore.
254pub async fn config_sync_get_sync(configuration: &configuration::Configuration, sync_direction: Option<models::PbsSyncDirectionEnum>) -> Result<models::ConfigSyncGetSyncResponse, Error<ConfigSyncGetSyncError>> {
255    // add a prefix to parameters to efficiently prevent name collisions
256    let p_query_sync_direction = sync_direction;
257
258    let uri_str = format!("{}/config/sync", configuration.base_path);
259    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
260
261    if let Some(ref param_value) = p_query_sync_direction {
262        req_builder = req_builder.query(&[("sync-direction", &param_value.to_string())]);
263    }
264    if let Some(ref user_agent) = configuration.user_agent {
265        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
266    }
267    if let Some(ref apikey) = configuration.api_key {
268        let key = apikey.key.clone();
269        let value = match apikey.prefix {
270            Some(ref prefix) => format!("{} {}", prefix, key),
271            None => key,
272        };
273        req_builder = req_builder.header("Authorization", value);
274    };
275    if let Some(ref apikey) = configuration.api_key {
276        let key = apikey.key.clone();
277        let value = match apikey.prefix {
278            Some(ref prefix) => format!("{} {}", prefix, key),
279            None => key,
280        };
281        req_builder = req_builder.header("CSRFPreventionToken", value);
282    };
283
284    let req = req_builder.build()?;
285    let resp = configuration.client.execute(req).await?;
286
287    let status = resp.status();
288    let content_type = resp
289        .headers()
290        .get("content-type")
291        .and_then(|v| v.to_str().ok())
292        .unwrap_or("application/octet-stream");
293    let content_type = super::ContentType::from(content_type);
294
295    if !status.is_client_error() && !status.is_server_error() {
296        let content = resp.text().await?;
297        match content_type {
298            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
299            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigSyncGetSyncResponse`"))),
300            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::ConfigSyncGetSyncResponse`")))),
301        }
302    } else {
303        let content = resp.text().await?;
304        let entity: Option<ConfigSyncGetSyncError> = serde_json::from_str(&content).ok();
305        Err(Error::ResponseError(ResponseContent { status, content, entity }))
306    }
307}
308
309/// Update sync job config.  Permissions: For sync jobs in pull direction 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. For sync jobs in push direction, user needs RemoteDatastore.Backup on remote datastore, and Datastore.Audit, Datastore.Read and Datastore.Modify on the source datastore, the latter not required sync job owned by user. Additionally, remove vanished requires RemoteDatastore.Modify.
310pub async fn config_sync_update_sync(configuration: &configuration::Configuration, id: &str, config_sync_update_sync_request: Option<models::ConfigSyncUpdateSyncRequest>) -> Result<models::ConfigSyncUpdateSyncResponse, Error<ConfigSyncUpdateSyncError>> {
311    // add a prefix to parameters to efficiently prevent name collisions
312    let p_path_id = id;
313    let p_body_config_sync_update_sync_request = config_sync_update_sync_request;
314
315    let uri_str = format!("{}/config/sync/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
316    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
317
318    if let Some(ref user_agent) = configuration.user_agent {
319        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
320    }
321    if let Some(ref apikey) = configuration.api_key {
322        let key = apikey.key.clone();
323        let value = match apikey.prefix {
324            Some(ref prefix) => format!("{} {}", prefix, key),
325            None => key,
326        };
327        req_builder = req_builder.header("Authorization", value);
328    };
329    if let Some(ref apikey) = configuration.api_key {
330        let key = apikey.key.clone();
331        let value = match apikey.prefix {
332            Some(ref prefix) => format!("{} {}", prefix, key),
333            None => key,
334        };
335        req_builder = req_builder.header("CSRFPreventionToken", value);
336    };
337    req_builder = req_builder.json(&p_body_config_sync_update_sync_request);
338
339    let req = req_builder.build()?;
340    let resp = configuration.client.execute(req).await?;
341
342    let status = resp.status();
343    let content_type = resp
344        .headers()
345        .get("content-type")
346        .and_then(|v| v.to_str().ok())
347        .unwrap_or("application/octet-stream");
348    let content_type = super::ContentType::from(content_type);
349
350    if !status.is_client_error() && !status.is_server_error() {
351        let content = resp.text().await?;
352        match content_type {
353            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
354            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigSyncUpdateSyncResponse`"))),
355            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::ConfigSyncUpdateSyncResponse`")))),
356        }
357    } else {
358        let content = resp.text().await?;
359        let entity: Option<ConfigSyncUpdateSyncError> = serde_json::from_str(&content).ok();
360        Err(Error::ResponseError(ResponseContent { status, content, entity }))
361    }
362}
363