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).
This commit is contained in:
Dietmar Maurer 2019-01-22 12:10:38 +01:00
parent b0ee976fbf
commit 576e3bf252
14 changed files with 14 additions and 156 deletions

View File

@ -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<Value, Error> {
println!("This is a test {}", param);
// let force: Option<bool> = 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
}

View File

@ -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);

View File

@ -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<Value, Error> {
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)?;

View File

@ -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());

View File

@ -55,7 +55,7 @@ pub mod cli {
}
pub mod api3;
pub mod api2;
pub mod client {

View File

@ -384,7 +384,7 @@ pub fn handle_request(api: Arc<ApiConfig>, req: Request<Body>) -> 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];

View File

@ -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;

View File

@ -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) {