move sync.rs to pbs_config workspace

This commit is contained in:
Dietmar Maurer 2021-09-08 06:57:23 +02:00
parent 58bfa3b19c
commit a4e5a0fc9f
9 changed files with 22 additions and 15 deletions

View File

@ -3,6 +3,7 @@ pub mod drive;
pub mod key_config;
pub mod media_pool;
pub mod remote;
pub mod sync;
pub mod tape_encryption_keys;
pub mod tape_job;

View File

@ -13,6 +13,8 @@ use proxmox::api::{
use pbs_api_types::{JOB_ID_SCHEMA, SyncJobConfig};
use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard};
lazy_static! {
pub static ref CONFIG: SectionConfig = init();
}
@ -34,6 +36,11 @@ fn init() -> SectionConfig {
pub const SYNC_CFG_FILENAME: &str = "/etc/proxmox-backup/sync.cfg";
pub const SYNC_CFG_LOCKFILE: &str = "/etc/proxmox-backup/.sync.lck";
/// Get exclusive lock
pub fn lock_config() -> Result<BackupLockGuard, Error> {
open_backup_lockfile(SYNC_CFG_LOCKFILE, None, true)
}
pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
let content = proxmox::tools::fs::file_read_optional_string(SYNC_CFG_FILENAME)?
@ -46,7 +53,7 @@ pub fn config() -> Result<(SectionConfigData, [u8;32]), Error> {
pub fn save_config(config: &SectionConfigData) -> Result<(), Error> {
let raw = CONFIG.write(SYNC_CFG_FILENAME, &config)?;
pbs_config::replace_backup_config(SYNC_CFG_FILENAME, raw.as_bytes())
replace_backup_config(SYNC_CFG_FILENAME, raw.as_bytes())
}
// shell completion helper

View File

@ -8,6 +8,7 @@ use proxmox::api::router::SubdirMap;
use proxmox::{list_subdirs_api_method, sortable};
use pbs_api_types::{DATASTORE_SCHEMA, JOB_ID_SCHEMA, Authid, SyncJobConfig, SyncJobStatus};
use pbs_config::sync;
use crate::{
api2::{
@ -19,7 +20,6 @@ use crate::{
},
config::{
cached_user_info::CachedUserInfo,
sync,
},
server::{
jobstate::{

View File

@ -10,10 +10,10 @@ use pbs_api_types::{
REMOTE_ID_SCHEMA, REMOTE_PASSWORD_SCHEMA, Remote, RemoteConfig, RemoteConfigUpdater,
Authid, PROXMOX_CONFIG_DIGEST_SCHEMA, DataStoreListItem, SyncJobConfig,
};
use pbs_config::sync;
use crate::config::cached_user_info::CachedUserInfo;
use crate::config::acl::{PRIV_REMOTE_AUDIT, PRIV_REMOTE_MODIFY};
use crate::config::sync;
#[api(
input: {

View File

@ -9,6 +9,7 @@ use pbs_api_types::{
SINGLE_LINE_COMMENT_SCHEMA, JOB_ID_SCHEMA, REMOTE_ID_SCHEMA, DATASTORE_SCHEMA,
REMOVE_VANISHED_BACKUPS_SCHEMA, SYNC_SCHEDULE_SCHEMA, PROXMOX_CONFIG_DIGEST_SCHEMA,
};
use pbs_config::sync;
use crate::config::acl::{
PRIV_DATASTORE_AUDIT,
@ -19,8 +20,7 @@ use crate::config::acl::{
PRIV_REMOTE_READ,
};
use crate::config::{sync, cached_user_info::CachedUserInfo};
use pbs_config::open_backup_lockfile;
use crate::config::cached_user_info::CachedUserInfo;
pub fn check_sync_job_read_access(
user_info: &CachedUserInfo,
@ -155,7 +155,7 @@ pub fn create_sync_job(
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let user_info = CachedUserInfo::new()?;
let _lock = open_backup_lockfile(sync::SYNC_CFG_LOCKFILE, None, true)?;
let _lock = sync::lock_config()?;
let sync_job: SyncJobConfig = serde_json::from_value(param)?;
if !check_sync_job_modify_access(&user_info, &auth_id, &sync_job) {
@ -299,7 +299,7 @@ pub fn update_sync_job(
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let user_info = CachedUserInfo::new()?;
let _lock = open_backup_lockfile(sync::SYNC_CFG_LOCKFILE, None, true)?;
let _lock = sync::lock_config()?;
// pass/compare digest
let (mut config, expected_digest) = sync::config()?;
@ -382,7 +382,7 @@ pub fn delete_sync_job(
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let user_info = CachedUserInfo::new()?;
let _lock = open_backup_lockfile(sync::SYNC_CFG_LOCKFILE, None, true)?;
let _lock = sync::lock_config()?;
let (mut config, expected_digest) = sync::config()?;

View File

@ -59,7 +59,7 @@ fn main() -> Result<(), Error> {
"tape-job.cfg" => dump_section_config(&pbs_config::tape_job::CONFIG),
"user.cfg" => dump_section_config(&config::user::CONFIG),
"remote.cfg" => dump_section_config(&pbs_config::remote::CONFIG),
"sync.cfg" => dump_section_config(&config::sync::CONFIG),
"sync.cfg" => dump_section_config(&pbs_config::sync::CONFIG),
"verification.cfg" => dump_section_config(&config::verify::CONFIG),
"media-pool.cfg" => dump_section_config(&pbs_config::media_pool::CONFIG),
"config::acl::Role" => dump_enum_properties(&config::acl::Role::API_SCHEMA)?,

View File

@ -521,7 +521,7 @@ async fn schedule_datastore_prune() {
async fn schedule_datastore_sync_jobs() {
let config = match proxmox_backup::config::sync::config() {
let config = match pbs_config::sync::config() {
Err(err) => {
eprintln!("unable to read sync job config - {}", err);
return;

View File

@ -77,12 +77,12 @@ pub fn sync_job_commands() -> CommandLineInterface {
.insert("show",
CliCommand::new(&API_METHOD_SHOW_SYNC_JOB)
.arg_param(&["id"])
.completion_cb("id", config::sync::complete_sync_job_id)
.completion_cb("id", pbs_config::sync::complete_sync_job_id)
)
.insert("create",
CliCommand::new(&api2::config::sync::API_METHOD_CREATE_SYNC_JOB)
.arg_param(&["id"])
.completion_cb("id", config::sync::complete_sync_job_id)
.completion_cb("id", pbs_config::sync::complete_sync_job_id)
.completion_cb("schedule", config::datastore::complete_calendar_event)
.completion_cb("store", config::datastore::complete_datastore_name)
.completion_cb("remote", pbs_config::remote::complete_remote_name)
@ -91,7 +91,7 @@ pub fn sync_job_commands() -> CommandLineInterface {
.insert("update",
CliCommand::new(&api2::config::sync::API_METHOD_UPDATE_SYNC_JOB)
.arg_param(&["id"])
.completion_cb("id", config::sync::complete_sync_job_id)
.completion_cb("id", pbs_config::sync::complete_sync_job_id)
.completion_cb("schedule", config::datastore::complete_calendar_event)
.completion_cb("store", config::datastore::complete_datastore_name)
.completion_cb("remote-store", crate::complete_remote_datastore_name)
@ -99,7 +99,7 @@ pub fn sync_job_commands() -> CommandLineInterface {
.insert("remove",
CliCommand::new(&api2::config::sync::API_METHOD_DELETE_SYNC_JOB)
.arg_param(&["id"])
.completion_cb("id", config::sync::complete_sync_job_id)
.completion_cb("id", pbs_config::sync::complete_sync_job_id)
);
cmd_def.into()

View File

@ -20,7 +20,6 @@ pub mod cached_user_info;
pub mod datastore;
pub mod network;
pub mod node;
pub mod sync;
pub mod tfa;
pub mod token_shadow;
pub mod user;