]> git.proxmox.com Git - proxmox-perl-rs.git/commitdiff
update to proxmox-http 0.7
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 4 Aug 2022 08:31:37 +0000 (10:31 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 7 Sep 2022 08:25:12 +0000 (10:25 +0200)
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
common/src/subscription.rs
pmg-rs/Cargo.toml
pmg-rs/debian/control
pve-rs/Cargo.toml
pve-rs/debian/control

index 8711d51226f924a6e26f87df96fa968945ab58c9..d4c722736db0f9fcde49ffcd8086e80718ee8224 100644 (file)
@@ -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<String>,
-    }
-
-    impl UreqClient {
-        fn agent(&self) -> Result<ureq::Agent, Error> {
-            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<Response<String>, 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<String> for UreqClient {
-        fn get(&self, uri: &str) -> Result<Response<String>, 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<Response<String>, 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<Option<SubscriptionInfo>, Error> {
@@ -130,7 +65,12 @@ mod export {
         user_agent: String,
         proxy: Option<String>,
     ) -> Result<SubscriptionInfo, Error> {
-        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)
     }
index 4dfa813cdea753ac636a4cd91c939fad9a4c0b67..2339aead0457e4fd8ffcbb286023a428017fac6e 100644 (file)
@@ -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"] }
index aebf869a39ac462fe7d9041a97b7f0d6865ef0cd..090c67bcfb2b61255ea55cfe041de366f1f45c10 100644 (file)
@@ -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
index 4b45413e34cc4f9d1f8e5dcb0fb91406e318042e..7598a64ac3fee2859bd2fe139b2a2e5e72bf9d7d 100644 (file)
@@ -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"
index ee8d141c7c8baf15c39d2f9fe5e8a3cc71a3c480..ac87ddf95917f7f6e0628984fcddcffd627bc887 100644 (file)
@@ -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 <support@proxmox.com>
 Standards-Version: 4.5.1