api2: update for latest proxmox-api changes
- rename ApiFuture into ApiResponseFuture - impl. ApiHandler::Async
This commit is contained in:
parent
236a396aa1
commit
bb084b9c91
|
@ -9,7 +9,7 @@ use serde_json::{json, Value};
|
||||||
|
|
||||||
use proxmox::{sortable, identity};
|
use proxmox::{sortable, identity};
|
||||||
use proxmox::api::{http_err, list_subdirs_api_method};
|
use proxmox::api::{http_err, list_subdirs_api_method};
|
||||||
use proxmox::api::{ApiFuture, ApiHandler, ApiMethod, Router, RpcEnvironment, RpcEnvironmentType};
|
use proxmox::api::{ApiResponseFuture, ApiHandler, ApiMethod, Router, RpcEnvironment, RpcEnvironmentType};
|
||||||
use proxmox::api::router::SubdirMap;
|
use proxmox::api::router::SubdirMap;
|
||||||
use proxmox::api::schema::*;
|
use proxmox::api::schema::*;
|
||||||
use proxmox::tools::{try_block, fs::file_get_contents, fs::file_set_contents};
|
use proxmox::tools::{try_block, fs::file_get_contents, fs::file_set_contents};
|
||||||
|
@ -486,7 +486,7 @@ fn download_file(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
_rpcenv: Box<dyn RpcEnvironment>,
|
_rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let store = tools::required_string_param(¶m, "store")?;
|
let store = tools::required_string_param(¶m, "store")?;
|
||||||
|
@ -545,7 +545,7 @@ fn upload_backup_log(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
_rpcenv: Box<dyn RpcEnvironment>,
|
_rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let store = tools::required_string_param(¶m, "store")?;
|
let store = tools::required_string_param(¶m, "store")?;
|
||||||
|
|
|
@ -7,7 +7,7 @@ use serde_json::{json, Value};
|
||||||
|
|
||||||
use proxmox::{sortable, identity};
|
use proxmox::{sortable, identity};
|
||||||
use proxmox::api::list_subdirs_api_method;
|
use proxmox::api::list_subdirs_api_method;
|
||||||
use proxmox::api::{ApiFuture, ApiHandler, ApiMethod, Router, RpcEnvironment};
|
use proxmox::api::{ApiResponseFuture, ApiHandler, ApiMethod, Router, RpcEnvironment};
|
||||||
use proxmox::api::router::SubdirMap;
|
use proxmox::api::router::SubdirMap;
|
||||||
use proxmox::api::schema::*;
|
use proxmox::api::schema::*;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ fn upgrade_to_backup_protocol(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let debug = param["debug"].as_bool().unwrap_or(false);
|
let debug = param["debug"].as_bool().unwrap_or(false);
|
||||||
|
@ -574,7 +574,7 @@ fn dynamic_chunk_index(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let env: &BackupEnvironment = rpcenv.as_ref();
|
let env: &BackupEnvironment = rpcenv.as_ref();
|
||||||
|
@ -649,7 +649,7 @@ fn fixed_chunk_index(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let env: &BackupEnvironment = rpcenv.as_ref();
|
let env: &BackupEnvironment = rpcenv.as_ref();
|
||||||
|
|
|
@ -9,7 +9,7 @@ use hyper::http::request::Parts;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
|
||||||
use proxmox::{sortable, identity};
|
use proxmox::{sortable, identity};
|
||||||
use proxmox::api::{ApiFuture, ApiHandler, ApiMethod, RpcEnvironment};
|
use proxmox::api::{ApiResponseFuture, ApiHandler, ApiMethod, RpcEnvironment};
|
||||||
use proxmox::api::schema::*;
|
use proxmox::api::schema::*;
|
||||||
|
|
||||||
use crate::api2::types::*;
|
use crate::api2::types::*;
|
||||||
|
@ -115,7 +115,7 @@ fn upload_fixed_chunk(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let wid = tools::required_integer_param(¶m, "wid")? as usize;
|
let wid = tools::required_integer_param(¶m, "wid")? as usize;
|
||||||
|
@ -173,7 +173,7 @@ fn upload_dynamic_chunk(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let wid = tools::required_integer_param(¶m, "wid")? as usize;
|
let wid = tools::required_integer_param(¶m, "wid")? as usize;
|
||||||
|
@ -209,7 +209,7 @@ fn upload_speedtest(
|
||||||
_param: Value,
|
_param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ fn upload_blob(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let file_name = tools::required_string_param(¶m, "file-name")?.to_owned();
|
let file_name = tools::required_string_param(¶m, "file-name")?.to_owned();
|
||||||
|
|
|
@ -8,7 +8,7 @@ use serde_json::Value;
|
||||||
|
|
||||||
use proxmox::{sortable, identity};
|
use proxmox::{sortable, identity};
|
||||||
use proxmox::api::http_err;
|
use proxmox::api::http_err;
|
||||||
use proxmox::api::{ApiFuture, ApiHandler, ApiMethod, Router, RpcEnvironment};
|
use proxmox::api::{ApiResponseFuture, ApiHandler, ApiMethod, Router, RpcEnvironment};
|
||||||
use proxmox::api::schema::*;
|
use proxmox::api::schema::*;
|
||||||
|
|
||||||
use crate::api2::types::*;
|
use crate::api2::types::*;
|
||||||
|
@ -49,7 +49,7 @@ fn upgrade_to_backup_reader_protocol(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let debug = param["debug"].as_bool().unwrap_or(false);
|
let debug = param["debug"].as_bool().unwrap_or(false);
|
||||||
|
@ -172,7 +172,7 @@ fn download_file(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let env: &ReaderEnvironment = rpcenv.as_ref();
|
let env: &ReaderEnvironment = rpcenv.as_ref();
|
||||||
|
@ -223,7 +223,7 @@ fn download_chunk(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let env: &ReaderEnvironment = rpcenv.as_ref();
|
let env: &ReaderEnvironment = rpcenv.as_ref();
|
||||||
|
@ -258,7 +258,7 @@ fn download_chunk_old(
|
||||||
param: Value,
|
param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
rpcenv: Box<dyn RpcEnvironment>,
|
rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> Result<ApiFuture, Error> {
|
) -> Result<ApiResponseFuture, Error> {
|
||||||
|
|
||||||
let env: &ReaderEnvironment = rpcenv.as_ref();
|
let env: &ReaderEnvironment = rpcenv.as_ref();
|
||||||
let env2 = env.clone();
|
let env2 = env.clone();
|
||||||
|
@ -303,7 +303,7 @@ fn speedtest(
|
||||||
_param: Value,
|
_param: Value,
|
||||||
_info: &ApiMethod,
|
_info: &ApiMethod,
|
||||||
_rpcenv: Box<dyn RpcEnvironment>,
|
_rpcenv: Box<dyn RpcEnvironment>,
|
||||||
) -> ApiFuture {
|
) -> ApiResponseFuture {
|
||||||
|
|
||||||
let buffer = vec![65u8; 1024*1024]; // nonsense [A,A,A...]
|
let buffer = vec![65u8; 1024*1024]; // nonsense [A,A,A...]
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::task::{Context, Poll};
|
||||||
use futures::*;
|
use futures::*;
|
||||||
use hyper::{Body, Request, Response, StatusCode};
|
use hyper::{Body, Request, Response, StatusCode};
|
||||||
|
|
||||||
use proxmox::api::{http_err, ApiFuture, HttpError, Router, RpcEnvironment};
|
use proxmox::api::{http_err, ApiResponseFuture, HttpError, Router, RpcEnvironment};
|
||||||
|
|
||||||
use crate::tools;
|
use crate::tools;
|
||||||
use crate::server::formatter::*;
|
use crate::server::formatter::*;
|
||||||
|
@ -35,7 +35,7 @@ impl <E: RpcEnvironment + Clone> H2Service<E> {
|
||||||
if self.debug { self.worker.log(msg); }
|
if self.debug { self.worker.log(msg); }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_request(&self, req: Request<Body>) -> ApiFuture {
|
fn handle_request(&self, req: Request<Body>) -> ApiResponseFuture {
|
||||||
|
|
||||||
let (parts, body) = req.into_parts();
|
let (parts, body) = req.into_parts();
|
||||||
|
|
||||||
|
|
|
@ -285,6 +285,12 @@ pub async fn handle_api_request<Env: RpcEnvironment, S: 'static + BuildHasher +
|
||||||
(handler)(params, info, &mut rpcenv)
|
(handler)(params, info, &mut rpcenv)
|
||||||
.map(|data| (formatter.format_data)(data, &rpcenv))
|
.map(|data| (formatter.format_data)(data, &rpcenv))
|
||||||
}
|
}
|
||||||
|
ApiHandler::Async(handler) => {
|
||||||
|
let params = get_request_parameters(info.parameters, parts, req_body, uri_param).await?;
|
||||||
|
(handler)(params, info, &mut rpcenv)
|
||||||
|
.await
|
||||||
|
.map(|data| (formatter.format_data)(data, &rpcenv))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let resp = match result {
|
let resp = match result {
|
||||||
|
|
Loading…
Reference in New Issue