]> git.proxmox.com Git - proxmox-backup.git/blame - src/api3.rs
parse_arguments: work with utf8 bytes and reduce indentation
[proxmox-backup.git] / src / api3.rs
CommitLineData
504b3597 1use failure::*;
504b3597 2
f17db0ab
DM
3use crate::api::schema::*;
4use crate::api::router::*;
504b3597
DM
5use serde_json::{json, Value};
6
ea0b8b6e 7pub mod config;
6ce50400 8mod version;
15e9b4ed 9mod datastore;
03e4753d 10
08bd8d47 11fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
504b3597
DM
12 println!("This is a test {}", param);
13
14 // let force: Option<bool> = Some(false);
15
16 //if let Some(force) = param.force {
17 //}
18
19 let _force = param["force"].as_bool()
20 .ok_or_else(|| format_err!("missing parameter 'force'"))?;
21
22 if let Some(_force) = param["force"].as_bool() {
23 }
24
504b3597
DM
25 Ok(json!(null))
26}
27
e63e99d6 28pub fn router() -> Router {
504b3597 29
95b492ad 30 let route4 = Router::new()
a4b7c3f2
DM
31 .get(ApiMethod::new(
32 |param, _info| {
fe476ce8
DM
33 println!("This is a clousure handler: {}", param);
34
35 Ok(json!(null))
a4b7c3f2
DM
36 },
37 ObjectSchema::new("Another Endpoint."))
38 .returns(Schema::Null));
8a700532 39
95b492ad
DM
40
41 let nodeinfo = Router::new()
d3369f81
DM
42 .get(ApiMethod::new(
43 test_sync_api_handler,
44 ObjectSchema::new("This is a simple test.")
45 .optional("force", BooleanSchema::new("Test for boolean options")))
46 )
47 .subdir("subdir3", route4);
504b3597 48
95b492ad
DM
49 let nodes = Router::new()
50 .match_all("node", nodeinfo);
51
95b492ad 52
6ce50400 53 let route = Router::new()
a4b7c3f2 54 .get(ApiMethod::new(
6ce50400
DM
55 |_,_| Ok(json!([
56 {"subdir": "config"},
15e9b4ed 57 {"subdir": "datastore"},
6ce50400
DM
58 {"subdir": "version"},
59 {"subdir": "nodes"}
60 ])),
a4b7c3f2 61 ObjectSchema::new("Directory index.")))
6ce50400 62 .subdir("config", config::router())
15e9b4ed 63 .subdir("datastore", datastore::router())
6ce50400 64 .subdir("version", version::router())
d3369f81 65 .subdir("nodes", nodes);
8a700532 66
0dde2f04 67 route
504b3597 68}