proxmox-backup-debug api: parse parameters before sending to api

when we use http to make the api call, we have to parse the parameters
before, else we might send the string "true" instead of the boolean true
and the api rejects it with a 'Parameter verification error'.

We already have all api call schemas here, so parsing is possible.

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-03-08 13:20:56 +01:00 committed by Wolfgang Bumiller
parent a07ace0d1e
commit 9735f5de84
1 changed files with 10 additions and 6 deletions

View File

@ -143,7 +143,7 @@ fn get_api_method(
} }
fn merge_parameters( fn merge_parameters(
uri_param: HashMap<String, String>, uri_param: &HashMap<String, String>,
param: Option<Value>, param: Option<Value>,
schema: ParameterSchema, schema: ParameterSchema,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
@ -179,14 +179,18 @@ async fn call_api(
rpcenv: &mut dyn RpcEnvironment, rpcenv: &mut dyn RpcEnvironment,
params: Option<Value>, params: Option<Value>,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
let (api_method, uri_params) = get_api_method(method, path)?;
let mut params = merge_parameters(&uri_params, params, api_method.parameters)?;
if use_http_client() { if use_http_client() {
return call_api_http(method, path, params).await; // remove url parameters here
for (param, _) in uri_params {
params.as_object_mut().unwrap().remove(&param);
}
return call_api_http(method, path, Some(params)).await;
} }
let (method, uri_param) = get_api_method(method, path)?; call_api_code(api_method, rpcenv, params).await
let params = merge_parameters(uri_param, params, method.parameters)?;
call_api_code(method, rpcenv, params).await
} }
async fn call_api_http(method: &str, path: &str, params: Option<Value>) -> Result<Value, Error> { async fn call_api_http(method: &str, path: &str, params: Option<Value>) -> Result<Value, Error> {