From 576e3bf252f969efa2b38ad3d929b59e23701691 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 22 Jan 2019 12:10:38 +0100 Subject: [PATCH] rename api3 back to api2 There is no real need to change the path, so using api2 we can reuse all helpers (like tools from proxmox widget toolkit). --- src/{api3 => api2}/admin.rs | 0 src/{api3 => api2}/admin/datastore.rs | 0 src/{api3 => api2}/admin/datastore/catar.rs | 0 src/{api3 => api2}/config.rs | 0 src/{api3 => api2}/config/datastore.rs | 0 src/{api3 => api2}/version.rs | 0 src/api3.rs | 68 ------------------- src/bin/proxmox-backup-api.rs | 2 +- src/bin/proxmox-backup-client.rs | 4 +- src/bin/proxmox-backup-manager.rs | 16 ++--- src/lib.rs | 2 +- src/server/rest.rs | 2 +- www/Utils.js | 74 --------------------- www/VersionInfo.js | 2 +- 14 files changed, 14 insertions(+), 156 deletions(-) rename src/{api3 => api2}/admin.rs (100%) rename src/{api3 => api2}/admin/datastore.rs (100%) rename src/{api3 => api2}/admin/datastore/catar.rs (100%) rename src/{api3 => api2}/config.rs (100%) rename src/{api3 => api2}/config/datastore.rs (100%) rename src/{api3 => api2}/version.rs (100%) delete mode 100644 src/api3.rs diff --git a/src/api3/admin.rs b/src/api2/admin.rs similarity index 100% rename from src/api3/admin.rs rename to src/api2/admin.rs diff --git a/src/api3/admin/datastore.rs b/src/api2/admin/datastore.rs similarity index 100% rename from src/api3/admin/datastore.rs rename to src/api2/admin/datastore.rs diff --git a/src/api3/admin/datastore/catar.rs b/src/api2/admin/datastore/catar.rs similarity index 100% rename from src/api3/admin/datastore/catar.rs rename to src/api2/admin/datastore/catar.rs diff --git a/src/api3/config.rs b/src/api2/config.rs similarity index 100% rename from src/api3/config.rs rename to src/api2/config.rs diff --git a/src/api3/config/datastore.rs b/src/api2/config/datastore.rs similarity index 100% rename from src/api3/config/datastore.rs rename to src/api2/config/datastore.rs diff --git a/src/api3/version.rs b/src/api2/version.rs similarity index 100% rename from src/api3/version.rs rename to src/api2/version.rs diff --git a/src/api3.rs b/src/api3.rs deleted file mode 100644 index 6b5dc087..00000000 --- a/src/api3.rs +++ /dev/null @@ -1,68 +0,0 @@ -use failure::*; - -use crate::api::schema::*; -use crate::api::router::*; -use serde_json::{json, Value}; - -pub mod config; -pub mod admin; -mod version; - -fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> 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)) -} - -pub fn router() -> Router { - - let route4 = Router::new() - .get(ApiMethod::new( - |param, _info| { - 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() - .match_all("node", nodeinfo); - - - let route = Router::new() - .get(ApiMethod::new( - |_,_| Ok(json!([ - {"subdir": "config"}, - {"subdir": "admin"}, - {"subdir": "version"}, - {"subdir": "nodes"} - ])), - ObjectSchema::new("Directory index."))) - .subdir("admin", admin::router()) - .subdir("config", config::router()) - .subdir("version", version::router()) - .subdir("nodes", nodes); - - route -} diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index 1982ecc6..7a1cb543 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -67,7 +67,7 @@ fn main() { let addr = ([0,0,0,0,0,0,0,0], 8007).into(); lazy_static!{ - static ref ROUTER: Router = proxmox_backup::api3::router(); + static ref ROUTER: Router = proxmox_backup::api2::router(); } let mut config = ApiConfig::new("/usr/share/javascript/proxmox-backup", &ROUTER); diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 7ee5d0e3..10176f39 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -32,7 +32,7 @@ fn backup_directory(body: Body, store: &str, archive_name: &str) -> Result<(), E .append_pair("time", &epoch.to_string()) .finish(); - let path = format!("api3/json/admin/datastore/{}/catar?{}", store, query); + let path = format!("api2/json/admin/datastore/{}/catar?{}", store, query); client.upload("application/x-proxmox-backup-catar", body, &path)?; @@ -71,7 +71,7 @@ fn list_backups(param: Value, _info: &ApiMethod) -> Result { let client = HttpClient::new("localhost"); - let path = format!("api3/json/admin/datastore/{}/backups", store); + let path = format!("api2/json/admin/datastore/{}/backups", store); let result = client.get(&path)?; diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index eef4bf57..c9007b0c 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -1,21 +1,21 @@ extern crate proxmox_backup; -//use proxmox_backup::api3; +//use proxmox_backup::api2; use proxmox_backup::cli::command::*; fn datastore_commands() -> CommandLineInterface { use proxmox_backup::config; - use proxmox_backup::api3; + use proxmox_backup::api2; let cmd_def = CliCommandMap::new() - .insert("list", CliCommand::new(api3::config::datastore::get()).into()) + .insert("list", CliCommand::new(api2::config::datastore::get()).into()) .insert("create", - CliCommand::new(api3::config::datastore::post()) + CliCommand::new(api2::config::datastore::post()) .arg_param(vec!["name", "path"]) .into()) .insert("remove", - CliCommand::new(api3::config::datastore::delete()) + CliCommand::new(api2::config::datastore::delete()) .arg_param(vec!["name"]) .completion_cb("name", config::datastore::complete_datastore_name) .into()); @@ -28,16 +28,16 @@ fn datastore_commands() -> CommandLineInterface { fn garbage_collection_commands() -> CommandLineInterface { use proxmox_backup::config; - use proxmox_backup::api3; + use proxmox_backup::api2; let cmd_def = CliCommandMap::new() .insert("status", - CliCommand::new(api3::admin::datastore::api_method_garbage_collection_status()) + CliCommand::new(api2::admin::datastore::api_method_garbage_collection_status()) .arg_param(vec!["name"]) .completion_cb("name", config::datastore::complete_datastore_name) .into()) .insert("start", - CliCommand::new(api3::admin::datastore::api_method_start_garbage_collection()) + CliCommand::new(api2::admin::datastore::api_method_start_garbage_collection()) .arg_param(vec!["name"]) .completion_cb("name", config::datastore::complete_datastore_name) .into()); diff --git a/src/lib.rs b/src/lib.rs index 017fa843..43cb7aba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,7 +55,7 @@ pub mod cli { } -pub mod api3; +pub mod api2; pub mod client { diff --git a/src/server/rest.rs b/src/server/rest.rs index c4c78880..c2b175c2 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -384,7 +384,7 @@ pub fn handle_request(api: Arc, req: Request) -> BoxFut { println!("REQUEST {} {}", method, path); println!("COMPO {:?}", components); - if comp_len >= 1 && components[0] == "api3" { + if comp_len >= 1 && components[0] == "api2" { println!("GOT API REQUEST"); if comp_len >= 2 { let format = components[1]; diff --git a/www/Utils.js b/www/Utils.js index 8841b0cb..4b5bafd3 100644 --- a/www/Utils.js +++ b/www/Utils.js @@ -6,80 +6,6 @@ console.log("Starting Backup Server GUI"); Ext.define('PBS.Utils', { singleton: true, - // Ext.Ajax.request - API3Request: function(reqOpts) { - - var newopts = Ext.apply({ - waitMsg: gettext('Please wait...') - }, reqOpts); - - if (!newopts.url.match(/^\/api3/)) { - newopts.url = '/api3/extjs' + newopts.url; - } - delete newopts.callback; - - var createWrapper = function(successFn, callbackFn, failureFn) { - Ext.apply(newopts, { - success: function(response, options) { - if (options.waitMsgTarget) { - if (Proxmox.Utils.toolkit === 'touch') { - options.waitMsgTarget.setMasked(false); - } else { - options.waitMsgTarget.setLoading(false); - } - } - var result = Ext.decode(response.responseText); - response.result = result; - if (!result.success) { - response.htmlStatus = Proxmox.Utils.extractRequestError(result, true); - Ext.callback(callbackFn, options.scope, [options, false, response]); - Ext.callback(failureFn, options.scope, [response, options]); - return; - } - Ext.callback(callbackFn, options.scope, [options, true, response]); - Ext.callback(successFn, options.scope, [response, options]); - }, - failure: function(response, options) { - if (options.waitMsgTarget) { - if (Proxmox.Utils.toolkit === 'touch') { - options.waitMsgTarget.setMasked(false); - } else { - options.waitMsgTarget.setLoading(false); - } - } - response.result = {}; - try { - response.result = Ext.decode(response.responseText); - } catch(e) {} - var msg = gettext('Connection error') + ' - server offline?'; - if (response.aborted) { - msg = gettext('Connection error') + ' - aborted.'; - } else if (response.timedout) { - msg = gettext('Connection error') + ' - Timeout.'; - } else if (response.status && response.statusText) { - msg = gettext('Connection error') + ' ' + response.status + ': ' + response.statusText; - } - response.htmlStatus = msg; - Ext.callback(callbackFn, options.scope, [options, false, response]); - Ext.callback(failureFn, options.scope, [response, options]); - } - }); - }; - - createWrapper(reqOpts.success, reqOpts.callback, reqOpts.failure); - - var target = newopts.waitMsgTarget; - if (target) { - if (Proxmox.Utils.toolkit === 'touch') { - target.setMasked({ xtype: 'loadmask', message: newopts.waitMsg} ); - } else { - // Note: ExtJS bug - this does not work when component is not rendered - target.setLoading(newopts.waitMsg); - } - } - Ext.Ajax.request(newopts); - }, - constructor: function() { var me = this; diff --git a/www/VersionInfo.js b/www/VersionInfo.js index a0298d33..0112825c 100644 --- a/www/VersionInfo.js +++ b/www/VersionInfo.js @@ -21,7 +21,7 @@ Ext.define('PBS.view.main.VersionInfo',{ me.callParent(); if (me.makeApiCall) { - PBS.Utils.API3Request({ + Proxmox.Utils.API2Request({ url: '/version', method: 'GET', success: function(response) { -- 2.39.2