diff --git a/src/config/data_store.rs b/src/config/data_store.rs new file mode 100644 index 00000000..97c58428 --- /dev/null +++ b/src/config/data_store.rs @@ -0,0 +1,54 @@ +use failure::*; + +use std::fs::{File, OpenOptions}; +use std::io::Read; + +//use std::sync::Arc; +use crate::api::schema::*; + +use crate::section_config::*; + +use lazy_static::lazy_static; + +lazy_static!{ + static ref CONFIG: SectionConfig = init(); +} + +fn init() -> SectionConfig { + + let plugin = SectionConfigPlugin::new( + "datastore".to_string(), + ObjectSchema::new("DataStore properties") + .required("path", StringSchema::new("Directory name")) + ); + + let id_schema = StringSchema::new("DataStore ID schema.") + .min_length(3) + .into(); + + let mut config = SectionConfig::new(id_schema); + config.register_plugin(plugin); + + config +} + +const datastore_cfg: &str = "/etc/proxmox-backup/datastore.cfg"; + +fn config() -> Result { + + let mut file = match OpenOptions::new() + .create(true) + .write(true) + .open(datastore_cfg) { + Ok(file) => file, + Err(err) => bail!("Unable to open '{}' - {}", + datastore_cfg, err), + }; + + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + + CONFIG.parse(datastore_cfg, &contents) +} + + diff --git a/src/lib.rs b/src/lib.rs index 0d800d05..810fe8ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,11 @@ pub mod backup { pub mod chunk_store; } +pub mod config { + + pub mod data_store; +} + pub mod storage { pub mod config;