X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=src%2Fapi2.rs;h=023bd867d136193cca7905691050cdf00b6f5ca5;hb=c6d203bbd3e7c1010f0d455920e8905c948caa32;hp=42a55989ede4fdf2fef22a5bc73dee1fb88e64c3;hpb=34f956bc25e7cf419c6da7e111fb90424b7ac74b;p=proxmox-backup.git diff --git a/src/api2.rs b/src/api2.rs index 42a55989..023bd867 100644 --- a/src/api2.rs +++ b/src/api2.rs @@ -1,99 +1,28 @@ -use failure::*; - -use crate::api::schema::*; -use crate::api::router::*; -use serde_json::{json, Value}; -use std::sync::Arc; - +pub mod types; pub mod config; pub mod admin; +pub mod backup; pub mod node; mod version; mod subscription; mod access; -use lazy_static::lazy_static; -use crate::tools::common_regex; - -// common schema definitions - -lazy_static! { - pub static ref IP_FORMAT: Arc = ApiStringFormat::Pattern(&common_regex::IP_REGEX).into(); - - pub static ref PVE_CONFIG_DIGEST_FORMAT: Arc = - ApiStringFormat::Pattern(&common_regex::SHA256_HEX_REGEX).into(); - - pub static ref PVE_CONFIG_DIGEST_SCHEMA: Arc = - StringSchema::new("Prevent changes if current configuration file has different SHA256 digest. This can be used to prevent concurrent modifications.") - .format(PVE_CONFIG_DIGEST_FORMAT.clone()).into(); - -} - - - -fn test_sync_api_handler( - param: Value, - _info: &ApiMethod, - _rpcenv: &mut RpcEnvironment, -) -> Result { - println!("This is a test {}", param); - - // let force: Option = 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)) -} +use crate::api_schema::router::*; pub fn router() -> Router { - let route4 = Router::new() - .get(ApiMethod::new( - |param, _info, _rpcenv| { - println!("This is a clousure handler: {}", param); - - Ok(json!(null)) - }, - ObjectSchema::new("Another Endpoint.")) - .returns(Schema::Null)); - - - let nodeinfo = Router::new() - .get(ApiMethod::new( - test_sync_api_handler, - ObjectSchema::new("This is a simple test.") - .optional("force", BooleanSchema::new("Test for boolean options"))) - ) - .subdir("subdir3", route4); - let nodes = Router::new() - .subdir("localhost", node::router()); - + .match_all("node", node::router()); let route = Router::new() - .get(ApiMethod::new( - |_,_,_| Ok(json!([ - {"subdir": "access"}, - {"subdir": "admin"}, - {"subdir": "config"}, - {"subdir": "nodes"}, - {"subdir": "subscription"}, - {"subdir": "version"}, - ])), - ObjectSchema::new("Directory index."))) .subdir("access", access::router()) .subdir("admin", admin::router()) + .subdir("backup", backup::router()) .subdir("config", config::router()) .subdir("nodes", nodes) .subdir("subscription", subscription::router()) - .subdir("version", version::router()); + .subdir("version", version::router()) + .list_subdirs(); route }