From 95b9307776feb48d4bdbbfd60138121d8a854ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Thu, 4 Aug 2022 10:31:37 +0200 Subject: [PATCH] update to proxmox-http 0.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Grünbichler --- common/src/subscription.rs | 78 +++++--------------------------------- pmg-rs/Cargo.toml | 3 +- pmg-rs/debian/control | 7 ++-- pve-rs/Cargo.toml | 3 +- pve-rs/debian/control | 7 ++-- 5 files changed, 17 insertions(+), 81 deletions(-) diff --git a/common/src/subscription.rs b/common/src/subscription.rs index 8711d51..d4c7227 100644 --- a/common/src/subscription.rs +++ b/common/src/subscription.rs @@ -1,70 +1,3 @@ -mod client { - use anyhow::{format_err, Error}; - use http::Response; - - pub(crate) struct UreqClient { - pub user_agent: String, - pub proxy: Option, - } - - impl UreqClient { - fn agent(&self) -> Result { - let mut builder = ureq::AgentBuilder::new(); - if let Some(proxy) = &self.proxy { - builder = builder.proxy(ureq::Proxy::new(proxy)?); - } - - Ok(builder.build()) - } - - fn exec_request( - &self, - req: ureq::Request, - body: Option<&str>, - ) -> Result, Error> { - let req = req.set("User-Agent", &self.user_agent); - let res = match body { - Some(body) => req.send_string(body), - None => req.call(), - }?; - - let mut builder = http::response::Builder::new() - .status(http::status::StatusCode::from_u16(res.status())?); - - for header in res.headers_names() { - if let Some(value) = res.header(&header) { - builder = builder.header(header, value); - } - } - builder - .body(res.into_string()?) - .map_err(|err| format_err!("Failed to convert HTTP response - {err}")) - } - } - - impl proxmox_http::HttpClient for UreqClient { - fn get(&self, uri: &str) -> Result, Error> { - let req = self.agent()?.get(uri); - - self.exec_request(req, None) - } - - fn post( - &self, - uri: &str, - body: Option<&str>, - content_type: Option<&str>, - ) -> Result, Error> { - let mut req = self.agent()?.post(uri); - if let Some(content_type) = content_type { - req = req.set("Content-Type", content_type); - } - - self.exec_request(req, body) - } - } -} - #[perlmod::package(name = "Proxmox::RS::Subscription")] mod export { use anyhow::{bail, format_err, Error}; @@ -72,7 +5,9 @@ mod export { use proxmox_subscription::SubscriptionInfo; use proxmox_sys::fs::CreateOptions; - use super::client::UreqClient; + use proxmox_http::ProxyConfig; + use proxmox_http::HttpOptions; + use proxmox_http::client::sync::Client; #[export] fn read_subscription(path: String) -> Result, Error> { @@ -130,7 +65,12 @@ mod export { user_agent: String, proxy: Option, ) -> Result { - let client = UreqClient { user_agent, proxy }; + let proxy_config = match proxy { + Some(url) => Some(ProxyConfig::parse_proxy_url(&url)?), + None => None, + }; + let options = HttpOptions { proxy_config, user_agent: Some(user_agent) , ..Default::default() }; + let client = Client::new(options); proxmox_subscription::check::check_subscription(key, server_id, product_url, client) } diff --git a/pmg-rs/Cargo.toml b/pmg-rs/Cargo.toml index 4dfa813..2339aea 100644 --- a/pmg-rs/Cargo.toml +++ b/pmg-rs/Cargo.toml @@ -28,14 +28,13 @@ openssl = "0.10.40" serde = "1.0" serde_bytes = "0.11.3" serde_json = "1.0" -ureq = { version = "2.4", features = ["native-certs"] } url = "2" perlmod = { version = "0.13", features = [ "exporter" ] } proxmox-acme-rs = { version = "0.4", features = ["client"] } proxmox-apt = "0.9" -proxmox-http = { version = "0.6.4", features = ["client-trait"] } +proxmox-http = { version = "0.7", features = ["client-sync", "client-trait"] } proxmox-subscription = "0.2" proxmox-sys = "0.4" proxmox-tfa = { version = "2.1", features = ["api"] } diff --git a/pmg-rs/debian/control b/pmg-rs/debian/control index aebf869..090c67b 100644 --- a/pmg-rs/debian/control +++ b/pmg-rs/debian/control @@ -19,8 +19,9 @@ Build-Depends: librust-proxmox-acme-rs-0.4+client-dev, librust-proxmox-acme-rs-0.4+default-dev, librust-proxmox-apt-0.9+default-dev, - librust-proxmox-http-0.6+client-trait-dev (>= 0.6.4-~~), - librust-proxmox-http-0.6+default-dev (>= 0.6.4-~~), + librust-proxmox-http-0.7+client-sync-dev, + librust-proxmox-http-0.7+client-trait-dev, + librust-proxmox-http-0.7+default-dev, librust-proxmox-subscription-0.2+default-dev, librust-proxmox-sys-0.4+default-dev, librust-proxmox-tfa-2+api-dev (>= 2.1-~~), @@ -29,8 +30,6 @@ Build-Depends: librust-serde-1+default-dev, librust-serde-bytes-0.11+default-dev (>= 0.11.3-~~), librust-serde-json-1+default-dev, - librust-ureq-2+default-dev (>= 2.4-~~), - librust-ureq-2+native-certs-dev (>= 2.4-~~), librust-url-2+default-dev, Standards-Version: 4.3.0 Homepage: https://www.proxmox.com diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml index 4b45413..7598a64 100644 --- a/pve-rs/Cargo.toml +++ b/pve-rs/Cargo.toml @@ -26,13 +26,12 @@ openssl = "0.10.40" serde = "1.0" serde_bytes = "0.11" serde_json = "1.0" -ureq = { version = "2.4", features = ["native-certs"] } url = "2" perlmod = { version = "0.13", features = [ "exporter" ] } proxmox-apt = "0.9" -proxmox-http = { version = "0.6.4", features = ["client-trait"] } +proxmox-http = { version = "0.7", features = ["client-sync", "client-trait"] } proxmox-openid = "0.9.5" proxmox-subscription = "0.2" proxmox-sys = "0.4" diff --git a/pve-rs/debian/control b/pve-rs/debian/control index ee8d141..ac87ddf 100644 --- a/pve-rs/debian/control +++ b/pve-rs/debian/control @@ -18,8 +18,9 @@ Build-Depends: librust-perlmod-0.13+default-dev, librust-perlmod-0.13+exporter-dev, librust-proxmox-apt-0.9+default-dev, - librust-proxmox-http-0.6+client-trait-dev (>= 0.6.4-~~), - librust-proxmox-http-0.6+default-dev (>= 0.6.4-~~), + librust-proxmox-http-0.7+client-sync-dev, + librust-proxmox-http-0.7+client-trait-dev, + librust-proxmox-http-0.7+default-dev, librust-proxmox-openid-0.9+default-dev (>= 0.9.5-~~), librust-proxmox-subscription-0.2+default-dev, librust-proxmox-sys-0.4+default-dev, @@ -29,8 +30,6 @@ Build-Depends: librust-serde-1+default-dev, librust-serde-bytes-0.11+default-dev, librust-serde-json-1+default-dev, - librust-ureq-2+default-dev (>= 2.4-~~), - librust-ureq-2+native-certs-dev (>= 2.4-~~), librust-url-2+default-dev, Maintainer: Proxmox Support Team Standards-Version: 4.5.1