]> git.proxmox.com Git - proxmox-backup.git/commitdiff
add data_store configuration
authorDietmar Maurer <dietmar@proxmox.com>
Sat, 8 Dec 2018 12:58:45 +0000 (13:58 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Sat, 8 Dec 2018 12:58:45 +0000 (13:58 +0100)
src/config/data_store.rs [new file with mode: 0644]
src/lib.rs

diff --git a/src/config/data_store.rs b/src/config/data_store.rs
new file mode 100644 (file)
index 0000000..97c5842
--- /dev/null
@@ -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<SectionConfigData, Error> {
+
+    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)
+}
+
+
index 0d800d05275539267459e009f08d7dd2ee114aa7..810fe8ae0b31c798fc300debf6a9d3d76366c3fd 100644 (file)
@@ -35,6 +35,11 @@ pub mod backup {
     pub mod chunk_store;
 }
 
+pub mod config {
+
+    pub mod data_store;
+}
+
 pub mod storage {
 
     pub mod config;