diff --git a/src/section_config.rs b/src/section_config.rs index 8f57673d..21dc07f0 100644 --- a/src/section_config.rs +++ b/src/section_config.rs @@ -5,10 +5,21 @@ use std::io::Read; use std::collections::HashMap; use serde_json::{json, Value}; +use std::sync::Arc; +use crate::api::schema::*; + pub struct SectionConfigPlugin { type_name: String, + properties: ObjectSchema, } +impl SectionConfigPlugin { + + pub fn new(type_name: String, properties: ObjectSchema) -> Self { + Self { type_name, properties } + } + +} pub struct SectionConfig { plugins: HashMap, @@ -30,6 +41,10 @@ impl SectionConfig { } } + pub fn register_plugin(&mut self, plugin: SectionConfigPlugin) { + self.plugins.insert(plugin.type_name.clone(), plugin); + } + pub fn parse(&self, filename: &str, raw: &str) -> Result<(), Error> { let mut line_no = 0; @@ -124,8 +139,15 @@ fn test_section_config1() { //let mut contents = String::new(); //file.read_to_string(&mut contents).unwrap(); - let config = SectionConfig::new(); + let plugin = SectionConfigPlugin::new( + "lvmthin".to_string(), + ObjectSchema::new("lvmthin properties") + .required("thinpool", StringSchema::new("LVM thin pool name.")) + .required("vgname", StringSchema::new("LVM volume group name.")) + ); + let mut config = SectionConfig::new(); + config.register_plugin(plugin); let raw = r"