* [pbs-devel] [PATCH proxmox-backup 1/2] proxmox-backup-debug api: parse parameters before sending to api
@ 2022-03-08 12:20 Dominik Csapak
2022-03-08 12:20 ` [pbs-devel] [PATCH proxmox-backup 2/2] proxmox-backup-debug api: rustfmt fixes Dominik Csapak
2022-03-09 9:13 ` [pbs-devel] applied-series: [PATCH proxmox-backup 1/2] proxmox-backup-debug api: parse parameters before sending to api Wolfgang Bumiller
0 siblings, 2 replies; 3+ messages in thread
From: Dominik Csapak @ 2022-03-08 12:20 UTC (permalink / raw)
To: pbs-devel
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>
---
src/bin/proxmox_backup_debug/api.rs | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/bin/proxmox_backup_debug/api.rs b/src/bin/proxmox_backup_debug/api.rs
index dd8c0e6b..64a4c01b 100644
--- a/src/bin/proxmox_backup_debug/api.rs
+++ b/src/bin/proxmox_backup_debug/api.rs
@@ -143,7 +143,7 @@ fn get_api_method(
}
fn merge_parameters(
- uri_param: HashMap<String, String>,
+ uri_param: &HashMap<String, String>,
param: Option<Value>,
schema: ParameterSchema,
) -> Result<Value, Error> {
@@ -179,14 +179,18 @@ async fn call_api(
rpcenv: &mut dyn RpcEnvironment,
params: Option<Value>,
) -> 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() {
- return call_api_http(method, path, params).await;
+ // remove url parameters here
+ for (param, _) in uri_params {
+ params.as_object_mut().unwrap().remove(¶m);
+ }
+ return call_api_http(method, path, Some(params)).await;
}
- let (method, uri_param) = get_api_method(method, path)?;
- let params = merge_parameters(uri_param, params, method.parameters)?;
-
- call_api_code(method, rpcenv, params).await
+ call_api_code(api_method, rpcenv, params).await
}
async fn call_api_http(method: &str, path: &str, params: Option<Value>) -> Result<Value, Error> {
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pbs-devel] [PATCH proxmox-backup 2/2] proxmox-backup-debug api: rustfmt fixes
2022-03-08 12:20 [pbs-devel] [PATCH proxmox-backup 1/2] proxmox-backup-debug api: parse parameters before sending to api Dominik Csapak
@ 2022-03-08 12:20 ` Dominik Csapak
2022-03-09 9:13 ` [pbs-devel] applied-series: [PATCH proxmox-backup 1/2] proxmox-backup-debug api: parse parameters before sending to api Wolfgang Bumiller
1 sibling, 0 replies; 3+ messages in thread
From: Dominik Csapak @ 2022-03-08 12:20 UTC (permalink / raw)
To: pbs-devel
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/bin/proxmox_backup_debug/api.rs | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/bin/proxmox_backup_debug/api.rs b/src/bin/proxmox_backup_debug/api.rs
index 64a4c01b..ba2117e4 100644
--- a/src/bin/proxmox_backup_debug/api.rs
+++ b/src/bin/proxmox_backup_debug/api.rs
@@ -8,8 +8,8 @@ use tokio::signal::unix::{signal, SignalKind};
use std::collections::HashMap;
use proxmox_router::{cli::*, ApiHandler, ApiMethod, RpcEnvironment, SubRoute};
-use proxmox_schema::{api, ApiType, ParameterSchema, Schema};
use proxmox_schema::format::DocumentationFormat;
+use proxmox_schema::{api, ApiType, ParameterSchema, Schema};
use pbs_api_types::{PROXMOX_UPID_REGEX, UPID};
use pbs_client::view_task_result;
@@ -23,7 +23,9 @@ const URL_ASCIISET: percent_encoding::AsciiSet = percent_encoding::NON_ALPHANUME
macro_rules! complete_api_path {
($capability:expr) => {
|complete_me: &str, _map: &HashMap<String, String>| {
- proxmox_async::runtime::block_on(async { complete_api_path_do(complete_me, $capability).await })
+ proxmox_async::runtime::block_on(async {
+ complete_api_path_do(complete_me, $capability).await
+ })
}
};
}
@@ -382,8 +384,7 @@ struct ApiDirEntry {
}
const LS_SCHEMA: &proxmox_schema::Schema =
- &proxmox_schema::ArraySchema::new("List of child links", &ApiDirEntry::API_SCHEMA)
- .schema();
+ &proxmox_schema::ArraySchema::new("List of child links", &ApiDirEntry::API_SCHEMA).schema();
async fn get_api_children(
path: String,
@@ -436,7 +437,11 @@ async fn get_api_children(
},
)]
/// Get API usage information for <path>
-async fn ls(path: Option<String>, mut param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result<(), Error> {
+async fn ls(
+ path: Option<String>,
+ mut param: Value,
+ rpcenv: &mut dyn RpcEnvironment,
+) -> Result<(), Error> {
let output_format = extract_output_format(&mut param);
let options = TableFormatOptions::new()
--
2.30.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [pbs-devel] applied-series: [PATCH proxmox-backup 1/2] proxmox-backup-debug api: parse parameters before sending to api
2022-03-08 12:20 [pbs-devel] [PATCH proxmox-backup 1/2] proxmox-backup-debug api: parse parameters before sending to api Dominik Csapak
2022-03-08 12:20 ` [pbs-devel] [PATCH proxmox-backup 2/2] proxmox-backup-debug api: rustfmt fixes Dominik Csapak
@ 2022-03-09 9:13 ` Wolfgang Bumiller
1 sibling, 0 replies; 3+ messages in thread
From: Wolfgang Bumiller @ 2022-03-09 9:13 UTC (permalink / raw)
To: Dominik Csapak; +Cc: pbs-devel
applied both patches, thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-09 9:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 12:20 [pbs-devel] [PATCH proxmox-backup 1/2] proxmox-backup-debug api: parse parameters before sending to api Dominik Csapak
2022-03-08 12:20 ` [pbs-devel] [PATCH proxmox-backup 2/2] proxmox-backup-debug api: rustfmt fixes Dominik Csapak
2022-03-09 9:13 ` [pbs-devel] applied-series: [PATCH proxmox-backup 1/2] proxmox-backup-debug api: parse parameters before sending to api Wolfgang Bumiller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox