/*
* Proxmox Backup Server API
*
* Generated from apidoc.js. NOT an official Proxmox specification. See https://pbs.proxmox.com/docs/api-viewer/ for the upstream documentation.
*
* The version of the OpenAPI document: 9.x
*
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for typed errors of method [`config_sync_create_sync`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConfigSyncCreateSyncError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`config_sync_delete_sync`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConfigSyncDeleteSyncError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`config_sync_get_config_sync_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConfigSyncGetConfigSyncByIdError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`config_sync_get_sync`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConfigSyncGetSyncError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`config_sync_update_sync`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConfigSyncUpdateSyncError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
/// 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.
pub async fn config_sync_create_sync(configuration: &configuration::Configuration, config_sync_create_sync_request: models::ConfigSyncCreateSyncRequest) -> Result<models::ConfigSyncCreateSyncResponse, Error<ConfigSyncCreateSyncError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_config_sync_create_sync_request = config_sync_create_sync_request;
let uri_str = format!("{}/config/sync", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
req_builder = req_builder.json(&p_body_config_sync_create_sync_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigSyncCreateSyncResponse`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConfigSyncCreateSyncError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn config_sync_delete_sync(configuration: &configuration::Configuration, id: &str, digest: Option<&str>) -> Result<models::ConfigSyncDeleteSyncResponse, Error<ConfigSyncDeleteSyncError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_query_digest = digest;
let uri_str = format!("{}/config/sync/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref param_value) = p_query_digest {
req_builder = req_builder.query(&[("digest", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigSyncDeleteSyncResponse`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConfigSyncDeleteSyncError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn config_sync_get_config_sync_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::ConfigSyncGetConfigSyncByIdResponse, Error<ConfigSyncGetConfigSyncByIdError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let uri_str = format!("{}/config/sync/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigSyncGetConfigSyncByIdResponse`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConfigSyncGetConfigSyncByIdError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn config_sync_get_sync(configuration: &configuration::Configuration, sync_direction: Option<models::PbsSyncDirectionEnum>) -> Result<models::ConfigSyncGetSyncResponse, Error<ConfigSyncGetSyncError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_sync_direction = sync_direction;
let uri_str = format!("{}/config/sync", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_sync_direction {
req_builder = req_builder.query(&[("sync-direction", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigSyncGetSyncResponse`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConfigSyncGetSyncError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn config_sync_update_sync(configuration: &configuration::Configuration, id: &str, config_sync_update_sync_request: Option<models::ConfigSyncUpdateSyncRequest>) -> Result<models::ConfigSyncUpdateSyncResponse, Error<ConfigSyncUpdateSyncError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_body_config_sync_update_sync_request = config_sync_update_sync_request;
let uri_str = format!("{}/config/sync/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
req_builder = req_builder.json(&p_body_config_sync_update_sync_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigSyncUpdateSyncResponse`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConfigSyncUpdateSyncError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}