diff --git a/pbs-api-types/src/jobs.rs b/pbs-api-types/src/jobs.rs index bf7a6bd5..e8056beb 100644 --- a/pbs-api-types/src/jobs.rs +++ b/pbs-api-types/src/jobs.rs @@ -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 { + match config_type { + "sync" => Ok(SyncDirection::Pull), + "sync-push" => Ok(SyncDirection::Push), + _ => bail!("invalid config type for sync job"), + } + } +} + #[api( properties: { id: { diff --git a/pbs-config/src/sync.rs b/pbs-config/src/sync.rs index 45453abb..7fc977e7 100644 --- a/pbs-config/src/sync.rs +++ b/pbs-config/src/sync.rs @@ -6,7 +6,7 @@ use anyhow::Error; use proxmox_schema::{ApiType, Schema}; use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; -use pbs_api_types::{SyncJobConfig, JOB_ID_SCHEMA}; +use pbs_api_types::{SyncDirection, SyncJobConfig, JOB_ID_SCHEMA}; use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}; @@ -18,9 +18,19 @@ fn init() -> SectionConfig { _ => unreachable!(), }; - let plugin = SectionConfigPlugin::new("sync".to_string(), Some(String::from("id")), obj_schema); + let pull_plugin = SectionConfigPlugin::new( + SyncDirection::Pull.as_config_type_str().to_string(), + Some(String::from("id")), + obj_schema, + ); + let push_plugin = SectionConfigPlugin::new( + SyncDirection::Push.as_config_type_str().to_string(), + Some(String::from("id")), + obj_schema, + ); let mut config = SectionConfig::new(&JOB_ID_SCHEMA); - config.register_plugin(plugin); + config.register_plugin(pull_plugin); + config.register_plugin(push_plugin); config }