adapt to the new ApiHandler variants

namely 'StreamingSync' and 'StreamingAsync'
in rest-server by using the new formatter function,
and in the debug binary by using 'to_value'

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Dominik Csapak 2022-04-12 16:15:09 +02:00 committed by Wolfgang Bumiller
parent 2ef2c0fe0c
commit 32e2b5abe6
2 changed files with 21 additions and 0 deletions

View File

@ -445,6 +445,19 @@ pub(crate) async fn handle_api_request<Env: RpcEnvironment, S: 'static + BuildHa
let params = parse_query_parameters(info.parameters, "", &parts, &uri_param)?; let params = parse_query_parameters(info.parameters, "", &parts, &uri_param)?;
(handler)(parts, req_body, params, info, Box::new(rpcenv)).await (handler)(parts, req_body, params, info, Box::new(rpcenv)).await
} }
ApiHandler::StreamingSync(handler) => {
let params =
get_request_parameters(info.parameters, parts, req_body, uri_param).await?;
(handler)(params, info, &mut rpcenv)
.and_then(|data| formatter.format_data_streaming(data, &rpcenv))
}
ApiHandler::StreamingAsync(handler) => {
let params =
get_request_parameters(info.parameters, parts, req_body, uri_param).await?;
(handler)(params, info, &mut rpcenv)
.await
.and_then(|data| formatter.format_data_streaming(data, &rpcenv))
}
ApiHandler::Sync(handler) => { ApiHandler::Sync(handler) => {
let params = let params =
get_request_parameters(info.parameters, parts, req_body, uri_param).await?; get_request_parameters(info.parameters, parts, req_body, uri_param).await?;

View File

@ -229,6 +229,14 @@ async fn call_api_code(
nix::unistd::setuid(backup_user.uid)?; nix::unistd::setuid(backup_user.uid)?;
} }
match method.handler { match method.handler {
ApiHandler::StreamingSync(handler) => {
let res = (handler)(params, method, rpcenv)?.to_value()?;
Ok(res)
}
ApiHandler::StreamingAsync(handler) => {
let res = (handler)(params, method, rpcenv).await?.to_value()?;
Ok(res)
}
ApiHandler::AsyncHttp(_handler) => { ApiHandler::AsyncHttp(_handler) => {
bail!("not implemented"); bail!("not implemented");
} }