diff --git a/src/api3.rs b/src/api3.rs index 4fb3667d..f74fcf64 100644 --- a/src/api3.rs +++ b/src/api3.rs @@ -1,11 +1,14 @@ use failure::*; -use std::collections::HashMap; +//use std::collections::HashMap; use crate::api::schema::*; use crate::api::router::*; use serde_json::{json, Value}; +mod config; +mod version; + fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result { println!("This is a test {}", param); @@ -24,20 +27,6 @@ fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result Result { - - Ok(json!({ - "version": PROXMOX_PKG_VERSION, - "release": PROXMOX_PKG_RELEASE, - "repoid": PROXMOX_PKG_REPOID - })) -} - pub fn router() -> Router { let route4 = Router::new() @@ -62,16 +51,17 @@ pub fn router() -> Router { let nodes = Router::new() .match_all("node", nodeinfo); - let version = Router::new() - .get(ApiMethod::new( - get_version, - ObjectSchema::new("Proxmox Backup Server API version."))); - let route = Router::new() + let route = Router::new() .get(ApiMethod::new( - get_version, + |_,_| Ok(json!([ + {"subdir": "config"}, + {"subdir": "version"}, + {"subdir": "nodes"} + ])), ObjectSchema::new("Directory index."))) - .subdir("version", version) + .subdir("config", config::router()) + .subdir("version", version::router()) .subdir("nodes", nodes); route diff --git a/src/api3/config.rs b/src/api3/config.rs new file mode 100644 index 00000000..df476581 --- /dev/null +++ b/src/api3/config.rs @@ -0,0 +1,22 @@ +use failure::*; +use std::collections::HashMap; + +use crate::api::schema::*; +use crate::api::router::*; +use serde_json::{json, Value}; + +mod datastore; + +pub fn router() -> Router { + + let route = Router::new() + .get(ApiMethod::new( + |_,_| Ok(json!([ + {"subdir": "datastore"} + ])), + ObjectSchema::new("Directory index."))) + .subdir("datastore", datastore::router()); + + + route +} diff --git a/src/api3/config/datastore.rs b/src/api3/config/datastore.rs new file mode 100644 index 00000000..ee6e82aa --- /dev/null +++ b/src/api3/config/datastore.rs @@ -0,0 +1,21 @@ +use failure::*; +use std::collections::HashMap; + +use crate::api::schema::*; +use crate::api::router::*; +use serde_json::{json, Value}; + +fn datastore_list(param: Value, _info: &ApiMethod) -> Result { + println!("This is a test {}", param); + Ok(json!({})) +} + +pub fn router() -> Router { + + let route = Router::new() + .get(ApiMethod::new( + datastore_list, + ObjectSchema::new("Directory index."))); + + route +} diff --git a/src/api3/version.rs b/src/api3/version.rs new file mode 100644 index 00000000..d70f51df --- /dev/null +++ b/src/api3/version.rs @@ -0,0 +1,28 @@ +use failure::*; + +use crate::api::schema::*; +use crate::api::router::*; +use serde_json::{json, Value}; + +const PROXMOX_PKG_VERSION: &'static str = env!("PROXMOX_PKG_VERSION"); +const PROXMOX_PKG_RELEASE: &'static str = env!("PROXMOX_PKG_RELEASE"); +const PROXMOX_PKG_REPOID: &'static str = env!("PROXMOX_PKG_REPOID"); + +fn get_version(_param: Value, _info: &ApiMethod) -> Result { + + Ok(json!({ + "version": PROXMOX_PKG_VERSION, + "release": PROXMOX_PKG_RELEASE, + "repoid": PROXMOX_PKG_REPOID + })) +} + +pub fn router() -> Router { + + let route = Router::new() + .get(ApiMethod::new( + get_version, + ObjectSchema::new("Proxmox Backup Server API version."))); + + route +} diff --git a/src/config/data_store.rs b/src/config/data_store.rs index 97c58428..c73234ac 100644 --- a/src/config/data_store.rs +++ b/src/config/data_store.rs @@ -1,6 +1,6 @@ use failure::*; -use std::fs::{File, OpenOptions}; +use std::fs::{OpenOptions}; use std::io::Read; //use std::sync::Arc; @@ -32,23 +32,23 @@ fn init() -> SectionConfig { config } -const datastore_cfg: &str = "/etc/proxmox-backup/datastore.cfg"; +const DATASTORE_CFG_FILENAME: &str = "/etc/proxmox-backup/datastore.cfg"; fn config() -> Result { let mut file = match OpenOptions::new() .create(true) .write(true) - .open(datastore_cfg) { + .open(DATASTORE_CFG_FILENAME) { Ok(file) => file, Err(err) => bail!("Unable to open '{}' - {}", - datastore_cfg, err), + DATASTORE_CFG_FILENAME, err), }; let mut contents = String::new(); file.read_to_string(&mut contents).unwrap(); - CONFIG.parse(datastore_cfg, &contents) + CONFIG.parse(DATASTORE_CFG_FILENAME, &contents) } diff --git a/src/lib.rs b/src/lib.rs index 810fe8ae..55b88080 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,4 +49,3 @@ pub mod storage { pub mod getopts; pub mod api3; -