From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 607F0659EE for ; Tue, 8 Mar 2022 13:20:59 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 51B01256C for ; Tue, 8 Mar 2022 13:20:59 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 7815F2559 for ; Tue, 8 Mar 2022 13:20:58 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4958F41A52 for ; Tue, 8 Mar 2022 13:20:58 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 8 Mar 2022 13:20:56 +0100 Message-Id: <20220308122057.3059305-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.153 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [api.rs] Subject: [pbs-devel] [PATCH proxmox-backup 1/2] proxmox-backup-debug api: parse parameters before sending to api X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Mar 2022 12:20:59 -0000 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 --- 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, + uri_param: &HashMap, param: Option, schema: ParameterSchema, ) -> Result { @@ -179,14 +179,18 @@ async fn call_api( rpcenv: &mut dyn RpcEnvironment, params: Option, ) -> Result { + 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) -> Result { -- 2.30.2