2018-11-03 09:42:48 +00:00
|
|
|
use failure::*;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
2018-11-15 16:07:10 +00:00
|
|
|
use crate::api::schema::*;
|
|
|
|
use crate::api::router::*;
|
2018-11-03 09:42:48 +00:00
|
|
|
use serde_json::{json, Value};
|
|
|
|
|
2018-11-14 16:32:17 +00:00
|
|
|
fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
2018-11-03 09:42:48 +00:00
|
|
|
println!("This is a test {}", param);
|
|
|
|
|
|
|
|
// let force: Option<bool> = Some(false);
|
|
|
|
|
|
|
|
//if let Some(force) = param.force {
|
|
|
|
//}
|
|
|
|
|
|
|
|
let _force = param["force"].as_bool()
|
|
|
|
.ok_or_else(|| format_err!("missing parameter 'force'"))?;
|
|
|
|
|
|
|
|
if let Some(_force) = param["force"].as_bool() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ok(json!(null))
|
|
|
|
}
|
|
|
|
|
2018-12-05 13:03:15 +00:00
|
|
|
fn get_version(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
|
|
|
|
|
|
|
|
|
|
|
Ok(json!({
|
|
|
|
"version": "1.0",
|
|
|
|
"release": "1",
|
|
|
|
"repoid": "AAAA"
|
|
|
|
}))
|
|
|
|
}
|
2018-11-15 12:28:15 +00:00
|
|
|
|
2018-11-15 10:46:13 +00:00
|
|
|
pub fn router() -> Router {
|
2018-11-03 09:42:48 +00:00
|
|
|
|
2018-12-05 13:03:15 +00:00
|
|
|
let route4 = Router::new()
|
2018-11-15 12:28:15 +00:00
|
|
|
.get(ApiMethod {
|
2018-11-23 10:34:15 +00:00
|
|
|
parameters: ObjectSchema::new("Another Endpoint."),
|
2018-11-15 15:56:28 +00:00
|
|
|
returns: Schema::Null,
|
2018-11-16 10:12:00 +00:00
|
|
|
handler: |param, _info| {
|
2018-11-15 16:47:59 +00:00
|
|
|
println!("This is a clousure handler: {}", param);
|
|
|
|
|
|
|
|
Ok(json!(null))
|
2018-11-16 10:12:00 +00:00
|
|
|
},
|
2018-11-15 12:28:15 +00:00
|
|
|
});
|
|
|
|
|
2018-12-05 13:03:15 +00:00
|
|
|
|
|
|
|
let nodeinfo = Router::new()
|
2018-11-03 14:10:21 +00:00
|
|
|
.get(ApiMethod {
|
2018-11-16 10:12:00 +00:00
|
|
|
handler: test_sync_api_handler,
|
2018-12-05 13:03:15 +00:00
|
|
|
parameters: ObjectSchema::new("This is a simple test.")
|
2018-11-23 12:18:41 +00:00
|
|
|
.optional("force", BooleanSchema::new("Test for boolean options")),
|
2018-11-15 15:56:28 +00:00
|
|
|
returns: Schema::Null,
|
2018-11-15 12:28:15 +00:00
|
|
|
})
|
|
|
|
.subdirs({
|
|
|
|
let mut map = HashMap::new();
|
2018-12-05 13:03:15 +00:00
|
|
|
map.insert("subdir3".into(), route4);
|
2018-11-15 12:28:15 +00:00
|
|
|
map
|
2018-11-03 14:10:21 +00:00
|
|
|
});
|
2018-11-03 09:42:48 +00:00
|
|
|
|
2018-12-05 13:03:15 +00:00
|
|
|
let nodes = Router::new()
|
|
|
|
.match_all("node", nodeinfo);
|
|
|
|
|
|
|
|
let version = Router::new()
|
|
|
|
.get(ApiMethod {
|
|
|
|
handler: get_version,
|
|
|
|
parameters: ObjectSchema::new("Proxmox Backup Server API version."),
|
|
|
|
returns: Schema::Null,
|
|
|
|
});
|
|
|
|
|
|
|
|
let route = Router::new()
|
|
|
|
.get(ApiMethod {
|
|
|
|
handler: get_version,
|
|
|
|
parameters: ObjectSchema::new("Directory index."),
|
|
|
|
returns: Schema::Null,
|
|
|
|
})
|
|
|
|
.subdirs({
|
|
|
|
let mut map = HashMap::new();
|
|
|
|
map.insert("version".into(), version);
|
|
|
|
map.insert("nodes".into(), nodes);
|
|
|
|
map
|
|
|
|
});
|
2018-11-15 12:28:15 +00:00
|
|
|
|
2018-11-03 14:10:21 +00:00
|
|
|
route
|
2018-11-03 09:42:48 +00:00
|
|
|
}
|