]> git.proxmox.com Git - proxmox-backup.git/blob - src/api2.rs
rename src/api to src/api_schema
[proxmox-backup.git] / src / api2.rs
1 //use failure::*;
2
3 use crate::api_schema::schema::*;
4 use crate::api_schema::router::*;
5 use serde_json::{json};
6 use std::sync::Arc;
7
8 pub mod config;
9 pub mod admin;
10 pub mod node;
11 mod version;
12 mod subscription;
13 mod access;
14
15 use lazy_static::lazy_static;
16 use crate::tools::common_regex;
17
18 // common schema definitions
19
20 lazy_static! {
21 pub static ref IP_FORMAT: Arc<ApiStringFormat> = ApiStringFormat::Pattern(&common_regex::IP_REGEX).into();
22
23 pub static ref PVE_CONFIG_DIGEST_FORMAT: Arc<ApiStringFormat> =
24 ApiStringFormat::Pattern(&common_regex::SHA256_HEX_REGEX).into();
25
26 pub static ref PVE_CONFIG_DIGEST_SCHEMA: Arc<Schema> =
27 StringSchema::new("Prevent changes if current configuration file has different SHA256 digest. This can be used to prevent concurrent modifications.")
28 .format(PVE_CONFIG_DIGEST_FORMAT.clone()).into();
29
30 }
31
32 pub fn router() -> Router {
33
34 let nodes = Router::new()
35 .subdir("localhost", node::router());
36
37 let route = Router::new()
38 .get(ApiMethod::new(
39 |_,_,_| Ok(json!([
40 {"subdir": "access"},
41 {"subdir": "admin"},
42 {"subdir": "config"},
43 {"subdir": "nodes"},
44 {"subdir": "subscription"},
45 {"subdir": "version"},
46 ])),
47 ObjectSchema::new("Directory index.")))
48 .subdir("access", access::router())
49 .subdir("admin", admin::router())
50 .subdir("config", config::router())
51 .subdir("nodes", nodes)
52 .subdir("subscription", subscription::router())
53 .subdir("version", version::router());
54
55 route
56 }