diff --git a/src/api/router.rs b/src/api/router.rs index 67b8c483..a70b56ee 100644 --- a/src/api/router.rs +++ b/src/api/router.rs @@ -13,7 +13,7 @@ pub type BoxFut = Box, Error = failure::Error> + Se type ApiHandlerFn = fn(Value, &ApiMethod) -> Result; -type ApiUploadHandlerFn = fn(Parts, Body, Value, &ApiUploadMethod) -> Result; +type ApiAsyncHandlerFn = fn(Parts, Body, Value, &ApiAsyncMethod) -> Result; pub struct ApiMethod { pub parameters: ObjectSchema, @@ -39,15 +39,15 @@ impl ApiMethod { } } -pub struct ApiUploadMethod { +pub struct ApiAsyncMethod { pub parameters: ObjectSchema, pub returns: Arc, - pub handler: ApiUploadHandlerFn, + pub handler: ApiAsyncHandlerFn, } -impl ApiUploadMethod { +impl ApiAsyncMethod { - pub fn new(handler: ApiUploadHandlerFn, parameters: ObjectSchema) -> Self { + pub fn new(handler: ApiAsyncHandlerFn, parameters: ObjectSchema) -> Self { Self { parameters, handler, @@ -72,7 +72,7 @@ pub enum SubRoute { pub enum MethodDefinition { None, Simple(ApiMethod), - Upload(ApiUploadMethod), + Async(ApiAsyncMethod), } pub struct Router { @@ -137,11 +137,17 @@ impl Router { self } - pub fn upload(mut self, m: ApiUploadMethod) -> Self { - self.post = MethodDefinition::Upload(m); + pub fn upload(mut self, m: ApiAsyncMethod) -> Self { + self.post = MethodDefinition::Async(m); self } + pub fn download(mut self, m: ApiAsyncMethod) -> Self { + self.get = MethodDefinition::Async(m); + self + } + + pub fn delete(mut self, m: ApiMethod) -> Self { self.delete = MethodDefinition::Simple(m); self diff --git a/src/api3/admin/datastore.rs b/src/api3/admin/datastore.rs index 78efded6..2e0424fd 100644 --- a/src/api3/admin/datastore.rs +++ b/src/api3/admin/datastore.rs @@ -12,7 +12,7 @@ use crate::config::datastore; use crate::backup::datastore::*; -mod upload_catar; +mod catar; // this is just a test for mutability/mutex handling - will remove later fn start_garbage_collection(param: Value, _info: &ApiMethod) -> Result { @@ -75,9 +75,10 @@ pub fn router() -> Router { .required("store", StringSchema::new("Datastore name."))) ) .subdir( - "upload_catar", + "catar", Router::new() - .upload(upload_catar::api_method_upload_catar())) + .download(catar::api_method_download_catar()) + .upload(catar::api_method_upload_catar())) .subdir( "gc", Router::new() diff --git a/src/api3/admin/datastore/upload_catar.rs b/src/api3/admin/datastore/catar.rs similarity index 77% rename from src/api3/admin/datastore/upload_catar.rs rename to src/api3/admin/datastore/catar.rs index 114443bc..52529dc3 100644 --- a/src/api3/admin/datastore/upload_catar.rs +++ b/src/api3/admin/datastore/catar.rs @@ -44,7 +44,7 @@ impl Future for UploadCaTar { } } -fn upload_catar(parts: Parts, req_body: Body, param: Value, _info: &ApiUploadMethod) -> Result { +fn upload_catar(parts: Parts, req_body: Body, param: Value, _info: &ApiAsyncMethod) -> Result { let store = tools::required_string_param(¶m, "store")?; let archive_name = tools::required_string_param(¶m, "archive_name")?; @@ -91,8 +91,8 @@ fn upload_catar(parts: Parts, req_body: Body, param: Value, _info: &ApiUploadMet Ok(Box::new(resp)) } -pub fn api_method_upload_catar() -> ApiUploadMethod { - ApiUploadMethod::new( +pub fn api_method_upload_catar() -> ApiAsyncMethod { + ApiAsyncMethod::new( upload_catar, ObjectSchema::new("Upload .catar backup file.") .required("store", StringSchema::new("Datastore name.")) @@ -105,3 +105,24 @@ pub fn api_method_upload_catar() -> ApiUploadMethod { ) } + +fn download_catar(parts: Parts, req_body: Body, param: Value, _info: &ApiAsyncMethod) -> Result { + + bail!("not implemeneted"); +} + +pub fn api_method_download_catar() -> ApiAsyncMethod { + ApiAsyncMethod::new( + download_catar, + ObjectSchema::new("Download .catar backup file.") + .required("store", StringSchema::new("Datastore name.")) + .required("archive_name", StringSchema::new("Backup archive name.")) + .required("type", StringSchema::new("Backup type.") + .format(Arc::new(ApiStringFormat::Enum(vec!["ct".into(), "host".into()])))) + .required("id", StringSchema::new("Backup ID.")) + .required("time", IntegerSchema::new("Backup time (Unix epoch.)") + .minimum(1547797308)) + + ) +} + diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index e8d98454..bc9e9b76 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/{}/upload_catar?{}", store, query); + let path = format!("api3/json/admin/datastore/{}/catar?{}", store, query); client.upload("application/x-proxmox-backup-catar", body, &path)?; diff --git a/src/server/rest.rs b/src/server/rest.rs index 1bd724eb..74cf1049 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -178,8 +178,8 @@ fn handle_sync_api_request( Box::new(resp) } -fn handle_upload_api_request( - info: &'static ApiUploadMethod, +fn handle_async_api_request( + info: &'static ApiAsyncMethod, formatter: &'static OutputFormatter, parts: Parts, req_body: Body, @@ -405,8 +405,8 @@ pub fn handle_request(api: Arc, req: Request) -> BoxFut { MethodDefinition::Simple(api_method) => { return handle_sync_api_request(api_method, formatter, parts, body, uri_param); } - MethodDefinition::Upload(upload_method) => { - return handle_upload_api_request(upload_method, formatter, parts, body, uri_param); + MethodDefinition::Async(async_method) => { + return handle_async_api_request(async_method, formatter, parts, body, uri_param); } } }