From: "Max Carrara" <m.carrara@proxmox.com>
To: "Proxmox Datacenter Manager development discussion"
<pdm-devel@lists.proxmox.com>
Subject: Re: [pdm-devel] [PATCH proxmox-datacenter-manager 2/2] pbs-client: make use of query builder
Date: Fri, 28 Mar 2025 13:37:49 +0100 [thread overview]
Message-ID: <D8RWL5JD1TGA.15IR1UERQNHN8@proxmox.com> (raw)
In-Reply-To: <20250326150636.460010-2-m.sandoval@proxmox.com>
On Wed Mar 26, 2025 at 4:06 PM CET, Maximiliano Sandoval wrote:
> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
What I said in my response to patch 1 also applies here: Since I've
also looked at the patch for proxmox-client [1], this LGTM.
Consider:
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
[1]: https://lore.proxmox.com/pbs-devel/20250326144410.430616-1-m.sandoval@proxmox.com/T/#u
> ---
> server/src/pbs_client.rs | 33 +++++++++------------------------
> 1 file changed, 9 insertions(+), 24 deletions(-)
>
> diff --git a/server/src/pbs_client.rs b/server/src/pbs_client.rs
> index c4115c1..20d31f2 100644
> --- a/server/src/pbs_client.rs
> +++ b/server/src/pbs_client.rs
> @@ -7,7 +7,7 @@
> use anyhow::bail; // don't import Error as default error in here
> use serde::Deserialize;
>
> -use proxmox_client::{Error, HttpApiClient};
> +use proxmox_client::{ApiPathBuilder, Error, HttpApiClient};
> use proxmox_router::stream::JsonRecords;
> use proxmox_schema::api;
> use proxmox_section_config::typed::SectionConfigData;
> @@ -100,8 +100,10 @@ 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,
> - ));
> - }
> -}
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next prev parent reply other threads:[~2025-03-28 12:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 15:06 [pdm-devel] [PATCH proxmox-datacenter-manager 1/2] pdm-client: " Maximiliano Sandoval
2025-03-26 15:06 ` [pdm-devel] [PATCH proxmox-datacenter-manager 2/2] pbs-client: " Maximiliano Sandoval
2025-03-28 12:37 ` Max Carrara [this message]
2025-03-28 12:37 ` [pdm-devel] [PATCH proxmox-datacenter-manager 1/2] pdm-client: " Max Carrara
2025-05-06 11:57 ` [pdm-devel] applied-series: " Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D8RWL5JD1TGA.15IR1UERQNHN8@proxmox.com \
--to=m.carrara@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal