mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-03 02:41:10 +00:00
api types/config: add sync-push
config type for push sync jobs
In order for sync jobs to be either pull or push jobs, allow to configure the direction of the job. Adds an additional config type `sync-push` to the sync job config, to clearly distinguish sync jobs configured in pull and in push direction and defines and implements the required `SyncDirection` api type. This approach was chosen in order to limit possible misconfiguration, as unintentionally switching the sync direction could potentially delete still required snapshots. Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
parent
ba850a25a3
commit
2f4c9f784e
@ -498,6 +498,44 @@ pub const TRANSFER_LAST_SCHEMA: Schema =
|
||||
.minimum(1)
|
||||
.schema();
|
||||
|
||||
#[api()]
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
/// Direction of the sync job, push or pull
|
||||
pub enum SyncDirection {
|
||||
/// Sync direction pull
|
||||
#[default]
|
||||
Pull,
|
||||
/// Sync direction push
|
||||
Push,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SyncDirection {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
SyncDirection::Pull => f.write_str("pull"),
|
||||
SyncDirection::Push => f.write_str("push"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SyncDirection {
|
||||
pub fn as_config_type_str(&self) -> &'static str {
|
||||
match self {
|
||||
SyncDirection::Pull => "sync",
|
||||
SyncDirection::Push => "sync-push",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_config_type_str(config_type: &str) -> Result<Self, anyhow::Error> {
|
||||
match config_type {
|
||||
"sync" => Ok(SyncDirection::Pull),
|
||||
"sync-push" => Ok(SyncDirection::Push),
|
||||
_ => bail!("invalid config type for sync job"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[api(
|
||||
properties: {
|
||||
id: {
|
||||
|
Loading…
Reference in New Issue
Block a user