From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pdm-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id E3FE31FF164 for <inbox@lore.proxmox.com>; Fri, 14 Feb 2025 15:12:00 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 681C41B9D0; Fri, 14 Feb 2025 15:12:01 +0100 (CET) From: Maximiliano Sandoval <m.sandoval@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Fri, 14 Feb 2025 15:11:27 +0100 Message-Id: <20250214141127.405323-3-m.sandoval@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250214141127.405323-1-m.sandoval@proxmox.com> References: <20250214141127.405323-1-m.sandoval@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.102 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [RFC PATCH 3/3] pbs-client: make use of query builder X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion <pdm-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/> List-Post: <mailto:pdm-devel@lists.proxmox.com> List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Datacenter Manager development discussion <pdm-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com> --- server/Cargo.toml | 1 + server/src/pbs_client.rs | 31 ++++++++----------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/server/Cargo.toml b/server/Cargo.toml index 7b0058e..0c30f93 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -71,6 +71,7 @@ proxmox-acme-api = { workspace = true, features = [ "impl" ] } pdm-api-types.workspace = true pdm-buildcfg.workspace = true pdm-config.workspace = true +pdm-client.workspace = true pve-api-types = { workspace = true, features = [ "client" ] } pbs-api-types.workspace = true diff --git a/server/src/pbs_client.rs b/server/src/pbs_client.rs index c4115c1..ad9ef95 100644 --- a/server/src/pbs_client.rs +++ b/server/src/pbs_client.rs @@ -13,6 +13,7 @@ use proxmox_schema::api; use proxmox_section_config::typed::SectionConfigData; use pdm_api_types::remotes::{Remote, RemoteType}; +use pdm_client::api_path_builder::ApiPathBuilder; pub fn get_remote<'a>( config: &'a SectionConfigData<Remote>, @@ -100,8 +101,9 @@ impl PbsClient { datastore: &str, namespace: Option<&str>, ) -> Result<JsonRecords<pbs_api_types::SnapshotListItem>, anyhow::Error> { - let mut path = format!("/api2/extjs/admin/datastore/{datastore}/snapshots"); - add_query_arg(&mut path, &mut '?', "ns", &namespace); + let path = ApiPathBuilder::new(format!("/api2/extjs/admin/datastore/{datastore}/snapshots")) + .maybe_arg("ns", &namespace) + .build(); let response = self .0 .streaming_request(http::Method::GET, &path, None::<()>) @@ -169,10 +171,10 @@ impl PbsClient { history: Option<bool>, start_time: Option<i64>, ) -> Result<pbs_api_types::Metrics, Error> { - let mut path = "/api2/extjs/status/metrics".to_string(); - let mut sep = '?'; - add_query_arg(&mut path, &mut sep, "history", &history); - add_query_arg(&mut path, &mut sep, "start-time", &start_time); + let path = ApiPathBuilder::new("/api2/extjs/status/metrics") + .maybe_arg("history", &history) + .maybe_arg("start-time", &start_time) + .build(); Ok(self.0.get(&path).await?.expect_json()?.data) } @@ -192,20 +194,3 @@ impl PbsClient { struct JsonData<T> { data: T, } - -/// Add an optional string parameter to the query, and if it was added, change `separator` to `&`. -fn add_query_arg<T>(query: &mut String, separator: &mut char, name: &str, value: &Option<T>) -where - T: std::fmt::Display, -{ - if let Some(value) = value { - query.push(*separator); - *separator = '&'; - query.push_str(name); - query.push('='); - query.extend(percent_encoding::percent_encode( - value.to_string().as_bytes(), - percent_encoding::NON_ALPHANUMERIC, - )); - } -} -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel