move verify.rs to pbs_config workspace

This commit is contained in:
Dietmar Maurer 2021-09-08 08:01:07 +02:00
parent a4e5a0fc9f
commit 802189f7f5
8 changed files with 20 additions and 14 deletions

View File

@ -6,6 +6,7 @@ pub mod remote;
pub mod sync;
pub mod tape_encryption_keys;
pub mod tape_job;
pub mod verify;
use anyhow::{format_err, Error};

View File

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

View File

@ -8,6 +8,7 @@ use proxmox::{list_subdirs_api_method, sortable};
use proxmox::api::{api, ApiMethod, Permission, Router, RpcEnvironment};
use pbs_api_types::{VerificationJobConfig, VerificationJobStatus, JOB_ID_SCHEMA, Authid};
use pbs_config::verify;
use crate::{
api2::types::{
@ -22,7 +23,6 @@ use crate::{
},
},
config::{
verify,
acl::{
PRIV_DATASTORE_AUDIT,
PRIV_DATASTORE_VERIFY,

View File

@ -10,6 +10,7 @@ use pbs_api_types::{
VERIFICATION_OUTDATED_AFTER_SCHEMA, VERIFICATION_SCHEDULE_SCHEMA,
DATASTORE_SCHEMA, PROXMOX_CONFIG_DIGEST_SCHEMA,
};
use pbs_config::verify;
use crate::config::acl::{
PRIV_DATASTORE_AUDIT,
@ -17,8 +18,6 @@ use crate::config::acl::{
};
use crate::config::cached_user_info::CachedUserInfo;
use crate::config::verify;
use pbs_config::open_backup_lockfile;
#[api(
input: {
@ -106,7 +105,7 @@ pub fn create_verification_job(
user_info.check_privs(&auth_id, &["datastore", &verification_job.store], PRIV_DATASTORE_VERIFY, false)?;
let _lock = open_backup_lockfile(verify::VERIFICATION_CFG_LOCKFILE, None, true)?;
let _lock = verify::lock_config()?;
let (mut config, _digest) = verify::config()?;
@ -234,7 +233,7 @@ pub fn update_verification_job(
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let user_info = CachedUserInfo::new()?;
let _lock = open_backup_lockfile(verify::VERIFICATION_CFG_LOCKFILE, None, true)?;
let _lock = verify::lock_config()?;
// pass/compare digest
let (mut config, expected_digest) = verify::config()?;
@ -319,7 +318,7 @@ pub fn delete_verification_job(
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let user_info = CachedUserInfo::new()?;
let _lock = open_backup_lockfile(verify::VERIFICATION_CFG_LOCKFILE, None, true)?;
let _lock = verify::lock_config()?;
let (mut config, expected_digest) = verify::config()?;

View File

@ -60,7 +60,7 @@ fn main() -> Result<(), Error> {
"user.cfg" => dump_section_config(&config::user::CONFIG),
"remote.cfg" => dump_section_config(&pbs_config::remote::CONFIG),
"sync.cfg" => dump_section_config(&pbs_config::sync::CONFIG),
"verification.cfg" => dump_section_config(&config::verify::CONFIG),
"verification.cfg" => dump_section_config(&pbs_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)?,
_ => bail!("docgen: got unknown type"),

View File

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

View File

@ -77,19 +77,19 @@ pub fn verify_job_commands() -> CommandLineInterface {
.insert("show",
CliCommand::new(&API_METHOD_SHOW_VERIFICATION_JOB)
.arg_param(&["id"])
.completion_cb("id", config::verify::complete_verification_job_id)
.completion_cb("id", pbs_config::verify::complete_verification_job_id)
)
.insert("create",
CliCommand::new(&api2::config::verify::API_METHOD_CREATE_VERIFICATION_JOB)
.arg_param(&["id"])
.completion_cb("id", config::verify::complete_verification_job_id)
.completion_cb("id", pbs_config::verify::complete_verification_job_id)
.completion_cb("schedule", config::datastore::complete_calendar_event)
.completion_cb("store", config::datastore::complete_datastore_name)
)
.insert("update",
CliCommand::new(&api2::config::verify::API_METHOD_UPDATE_VERIFICATION_JOB)
.arg_param(&["id"])
.completion_cb("id", config::verify::complete_verification_job_id)
.completion_cb("id", pbs_config::verify::complete_verification_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)
@ -97,7 +97,7 @@ pub fn verify_job_commands() -> CommandLineInterface {
.insert("remove",
CliCommand::new(&api2::config::verify::API_METHOD_DELETE_VERIFICATION_JOB)
.arg_param(&["id"])
.completion_cb("id", config::verify::complete_verification_job_id)
.completion_cb("id", pbs_config::verify::complete_verification_job_id)
);
cmd_def.into()

View File

@ -23,7 +23,6 @@ pub mod node;
pub mod tfa;
pub mod token_shadow;
pub mod user;
pub mod verify;
/// Check configuration directory permissions
///