]> git.proxmox.com Git - proxmox-backup.git/blame - src/api2.rs
src/bin/proxmox-backup-proxy.rs: implement unpriviledged server
[proxmox-backup.git] / src / api2.rs
CommitLineData
248cb518
DM
1use failure::*;
2
3use crate::api::schema::*;
4use crate::api::router::*;
5use serde_json::{json, Value};
46b79b9e 6use std::sync::Arc;
248cb518
DM
7
8pub mod config;
9pub mod admin;
b2b3485d 10pub mod node;
248cb518
DM
11mod version;
12mod subscription;
13
46b79b9e
DM
14use lazy_static::lazy_static;
15use crate::tools::common_regex;
16
17// common schema definitions
18
19lazy_static! {
20 pub static ref IP_FORMAT: Arc<ApiStringFormat> = ApiStringFormat::Pattern(&common_regex::IP_REGEX).into();
21
af2fddea
DM
22 pub static ref PVE_CONFIG_DIGEST_FORMAT: Arc<ApiStringFormat> =
23 ApiStringFormat::Pattern(&common_regex::SHA256_HEX_REGEX).into();
24
25 pub static ref PVE_CONFIG_DIGEST_SCHEMA: Arc<Schema> =
26 StringSchema::new("Prevent changes if current configuration file has different SHA256 digest. This can be used to prevent concurrent modifications.")
27 .format(PVE_CONFIG_DIGEST_FORMAT.clone()).into();
46b79b9e
DM
28
29}
30
31
32
6049b71f
DM
33fn test_sync_api_handler(
34 param: Value,
35 _info: &ApiMethod,
36 _rpcenv: &mut RpcEnvironment,
37) -> Result<Value, Error> {
248cb518
DM
38 println!("This is a test {}", param);
39
40 // let force: Option<bool> = Some(false);
41
42 //if let Some(force) = param.force {
43 //}
44
45 let _force = param["force"].as_bool()
46 .ok_or_else(|| format_err!("missing parameter 'force'"))?;
47
48 if let Some(_force) = param["force"].as_bool() {
49 }
50
51 Ok(json!(null))
52}
53
54pub fn router() -> Router {
55
56 let route4 = Router::new()
57 .get(ApiMethod::new(
6049b71f 58 |param, _info, _rpcenv| {
248cb518
DM
59 println!("This is a clousure handler: {}", param);
60
61 Ok(json!(null))
62 },
63 ObjectSchema::new("Another Endpoint."))
64 .returns(Schema::Null));
65
66
67 let nodeinfo = Router::new()
68 .get(ApiMethod::new(
69 test_sync_api_handler,
70 ObjectSchema::new("This is a simple test.")
71 .optional("force", BooleanSchema::new("Test for boolean options")))
72 )
73 .subdir("subdir3", route4);
74
75 let nodes = Router::new()
b2b3485d 76 .subdir("localhost", node::router());
248cb518
DM
77
78
79 let route = Router::new()
80 .get(ApiMethod::new(
6049b71f 81 |_,_,_| Ok(json!([
248cb518
DM
82 {"subdir": "config"},
83 {"subdir": "admin"},
84 {"subdir": "nodes"},
85 {"subdir": "subscription"},
86 {"subdir": "version"},
87 ])),
88 ObjectSchema::new("Directory index.")))
89 .subdir("admin", admin::router())
90 .subdir("config", config::router())
91 .subdir("nodes", nodes)
92 .subdir("subscription", subscription::router())
93 .subdir("version", version::router());
94
95 route
96}