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