diff --git a/src/api_schema.rs b/src/api_schema.rs index 5ac6a0b3..27ef3194 100644 --- a/src/api_schema.rs +++ b/src/api_schema.rs @@ -8,6 +8,5 @@ //! hierarchy of API entries, and provides ways to find an API //! definition by path. -//pub mod registry; pub mod config; pub mod format; diff --git a/src/api_schema/registry.rs b/src/api_schema/registry.rs deleted file mode 100644 index ae4c3875..00000000 --- a/src/api_schema/registry.rs +++ /dev/null @@ -1,90 +0,0 @@ -use crate::api_schema::*; - -use failure::*; -use std::collections::HashMap; -use std::sync::Arc; - -#[derive(Default)] -pub struct Registry { - formats: HashMap<&'static str, Arc>, - options: HashMap<&'static str, Arc>, -} - -impl Registry { - - pub fn new() -> Self { - - let mut me = Self { - formats: HashMap::new(), - options: HashMap::new(), - }; - - me.initialize_formats(); - - me.initialize_options(); - - me - } - - pub fn register_format(&mut self, name: &'static str, format: ApiStringFormat) { - - if let Some(_format) = self.formats.get(name) { - panic!("standard format '{}' already registered.", name); // fixme: really panic? - } - - self.formats.insert(name, Arc::new(format)); - } - - pub fn lookup_format(&self, name: &str) -> Option> { - - if let Some(format) = self.formats.get(name) { - return Some(format.clone()); - } - None - } - - pub fn register_option>(&mut self, name: &'static str, schema: S) { - - if let Some(_schema) = self.options.get(name) { - panic!("standard option '{}' already registered.", name); // fixme: really panic? - } - - self.options.insert(name, Arc::new(schema.into())); - } - - pub fn lookup_option(&self, name: &str) -> Option> { - - if let Some(schema) = self.options.get(name) { - return Some(schema.clone()); - } - None - } - - fn initialize_formats(&mut self) { - - self.register_format("pve-node", ApiStringFormat::VerifyFn(verify_pve_node)); - - } - - fn initialize_options(&mut self) { - - self.register_option( - "pve-vmid", - IntegerSchema::new("The (unique) ID of the VM.") - .minimum(1) - ); - - self.register_option( - "pve-node", - StringSchema::new("The cluster node name.") - .format(self.lookup_format("pve-node").unwrap()) //fixme: unwrap? - ); - } - -} - -fn verify_pve_node(_value: &str) -> Result<(), Error> { - - // fixme: ?? - Ok(()) -}