1 use std
::collections
::HashMap
;
4 use lazy_static
::lazy_static
;
7 use proxmox_section_config
::{SectionConfig, SectionConfigData, SectionConfigPlugin}
;
9 use pbs_api_types
::{JOB_ID_SCHEMA, VerificationJobConfig}
;
11 use crate::{open_backup_lockfile, replace_backup_config, BackupLockGuard}
;
14 pub static ref CONFIG
: SectionConfig
= init();
17 fn init() -> SectionConfig
{
18 let obj_schema
= match VerificationJobConfig
::API_SCHEMA
{
19 Schema
::Object(ref obj_schema
) => obj_schema
,
23 let plugin
= SectionConfigPlugin
::new("verification".to_string(), Some(String
::from("id")), obj_schema
);
24 let mut config
= SectionConfig
::new(&JOB_ID_SCHEMA
);
25 config
.register_plugin(plugin
);
30 pub const VERIFICATION_CFG_FILENAME
: &str = "/etc/proxmox-backup/verification.cfg";
31 pub const VERIFICATION_CFG_LOCKFILE
: &str = "/etc/proxmox-backup/.verification.lck";
33 /// Get exclusive lock
34 pub fn lock_config() -> Result
<BackupLockGuard
, Error
> {
35 open_backup_lockfile(VERIFICATION_CFG_LOCKFILE
, None
, true)
38 pub fn config() -> Result
<(SectionConfigData
, [u8;32]), Error
> {
40 let content
= proxmox
::tools
::fs
::file_read_optional_string(VERIFICATION_CFG_FILENAME
)?
;
41 let content
= content
.unwrap_or_else(String
::new
);
43 let digest
= openssl
::sha
::sha256(content
.as_bytes());
44 let data
= CONFIG
.parse(VERIFICATION_CFG_FILENAME
, &content
)?
;
48 pub fn save_config(config
: &SectionConfigData
) -> Result
<(), Error
> {
49 let raw
= CONFIG
.write(VERIFICATION_CFG_FILENAME
, &config
)?
;
50 replace_backup_config(VERIFICATION_CFG_FILENAME
, raw
.as_bytes())
53 // shell completion helper
54 pub fn complete_verification_job_id(_arg
: &str, _param
: &HashMap
<String
, String
>) -> Vec
<String
> {
56 Ok((data
, _digest
)) => data
.sections
.iter().map(|(id
, _
)| id
.to_string()).collect(),
57 Err(_
) => return vec
![],