]> git.proxmox.com Git - proxmox-offline-mirror.git/commitdiff
update dependencies to get rid of hyper
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 4 Aug 2022 13:00:39 +0000 (15:00 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 7 Sep 2022 09:16:57 +0000 (11:16 +0200)
proxmox-http to 0.7, proxmox-router to 1.3 and proxmox-subscription to
0.3.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Cargo.toml
debian/control
src/mirror.rs
src/subscription.rs

index 9a426bd82692920801edd9500426ccb1e7c26a53..2ab2c7260a406638d5016e8b14cada591acde0e1 100644 (file)
@@ -14,7 +14,6 @@ base64 = "0.13"
 bzip2 = "0.4"
 flate2 = "1.0.22"
 hex = "0.4.3"
-hyper = "0.14"
 lazy_static = "1.4"
 nix = "0.24"
 openssl = "0.10"
@@ -22,17 +21,16 @@ regex = "1.5.5"
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
 sequoia-openpgp = { version = "1.7" }
-ureq = { version = "2.4.0", features = ["native-certs"] }
 walkdir = "2.3.1"
 xz2 = "0.1"
 
 proxmox-apt = { version = "0.9.1" }
 proxmox-async = "0.4"
-proxmox-http = { version = "0.6.3", features = [ "client", "client-trait", "proxmox-async" ]}
-proxmox-router = { version = "1.1", features = [ "cli" ] }
+proxmox-http = { version = "0.7", features = [ "client-sync", "client-trait" ]}
+proxmox-router = { version = "1.3", features = [ "cli" ], default_features = false }
 proxmox-schema = { version = "1.1", features = [ "api-macro" ] }
 proxmox-section-config = "1"
 proxmox-serde = "0.1"
-proxmox-subscription = { version = "0.2", features = [ "api-types" ] }
+proxmox-subscription = { version = "0.3", features = [ "api-types" ] }
 proxmox-sys = { version = "0.4", features = [ "timer" ] }
 proxmox-time = { version = "1.1.3" }
index af751ae24dabcc4d4087d336f2b4046c83e0e417..3b64bdce94b0bee629d236da8bd18b72fd6a790b 100644 (file)
@@ -11,24 +11,21 @@ Build-Depends: debhelper (>= 12),
  librust-bzip2-0.4+default-dev,
  librust-flate2-1+default-dev (>= 1.0.22-~~),
  librust-hex-0.4+default-dev (>= 0.4.3-~~),
- librust-hyper-0.14+default-dev,
  librust-lazy-static-1+default-dev (>= 1.4-~~),
  librust-nix-0.24+default-dev,
  librust-openssl-0.10+default-dev,
  librust-proxmox-apt-0.9+default-dev (>= 0.9.1-~~),
  librust-proxmox-async-0.4+default-dev,
- librust-proxmox-http-0.6+client-dev (>= 0.6.3-~~),
- librust-proxmox-http-0.6+client-trait-dev (>= 0.6.3-~~),
- librust-proxmox-http-0.6+default-dev (>= 0.6.3-~~),
- librust-proxmox-http-0.6+proxmox-async-dev (>= 0.6.3-~~),
- librust-proxmox-router-1+cli-dev (>= 1.1-~~),
- librust-proxmox-router-1+default-dev (>= 1.1-~~),
+ 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-router-1+cli-dev (>= 1.3-~~),
  librust-proxmox-schema-1+api-macro-dev (>= 1.1-~~),
  librust-proxmox-schema-1+default-dev (>= 1.1-~~),
  librust-proxmox-section-config-1+default-dev,
  librust-proxmox-serde-0.1+default-dev,
- librust-proxmox-subscription-0.2+api-types-dev,
- librust-proxmox-subscription-0.2+default-dev,
+ librust-proxmox-subscription-0.3+api-types-dev,
+ librust-proxmox-subscription-0.3+default-dev,
  librust-proxmox-sys-0.4+default-dev,
  librust-proxmox-sys-0.4+timer-dev,
  librust-proxmox-time-1+default-dev (>= 1.1.3-~~),
@@ -37,8 +34,6 @@ Build-Depends: debhelper (>= 12),
  librust-serde-1+default-dev,
  librust-serde-1+derive-dev,
  librust-serde-json-1+default-dev,
- librust-ureq-2+default-dev (>= 2.4.0-~~),
- librust-ureq-2+native-certs-dev (>= 2.4.0-~~),
  librust-walkdir-2+default-dev (>= 2.3.1-~~),
  librust-xz2-0.1+default-dev
 Maintainer: Proxmox Support Team <support@proxmox.com>
@@ -57,24 +52,21 @@ Depends:
  librust-bzip2-0.4+default-dev,
  librust-flate2-1+default-dev (>= 1.0.22-~~),
  librust-hex-0.4+default-dev (>= 0.4.3-~~),
- librust-hyper-0.14+default-dev,
  librust-lazy-static-1+default-dev (>= 1.4-~~),
  librust-nix-0.24+default-dev,
  librust-openssl-0.10+default-dev,
  librust-proxmox-apt-0.9+default-dev (>= 0.9.1-~~),
  librust-proxmox-async-0.4+default-dev,
- librust-proxmox-http-0.6+client-dev (>= 0.6.3-~~),
- librust-proxmox-http-0.6+client-trait-dev (>= 0.6.3-~~),
- librust-proxmox-http-0.6+default-dev (>= 0.6.3-~~),
- librust-proxmox-http-0.6+proxmox-async-dev (>= 0.6.3-~~),
- librust-proxmox-router-1+cli-dev (>= 1.1-~~),
- librust-proxmox-router-1+default-dev (>= 1.1-~~),
+ 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-router-1+cli-dev (>= 1.3-~~),
  librust-proxmox-schema-1+api-macro-dev (>= 1.1-~~),
  librust-proxmox-schema-1+default-dev (>= 1.1-~~),
  librust-proxmox-section-config-1+default-dev,
  librust-proxmox-serde-0.1+default-dev,
- librust-proxmox-subscription-0.2+api-types-dev,
- librust-proxmox-subscription-0.2+default-dev,
+ librust-proxmox-subscription-0.3+api-types-dev,
+ librust-proxmox-subscription-0.3+default-dev,
  librust-proxmox-sys-0.4+default-dev,
  librust-proxmox-sys-0.4+timer-dev,
  librust-proxmox-time-1+default-dev (>= 1.1.3-~~),
@@ -83,8 +75,6 @@ Depends:
  librust-serde-1+default-dev,
  librust-serde-1+derive-dev,
  librust-serde-json-1+default-dev,
- librust-ureq-2+default-dev (>= 2.4.0-~~),
- librust-ureq-2+native-certs-dev (>= 2.4.0-~~),
  librust-walkdir-2+default-dev (>= 2.3.1-~~),
  librust-xz2-0.1+default-dev
 Provides:
index c8bdb41379025122798a0d76908e19334920fb92..091eb31cc63a1078697fa1d2a57be92d67e9a71e 100644 (file)
@@ -8,8 +8,8 @@ use std::{
 use anyhow::{bail, format_err, Error};
 use flate2::bufread::GzDecoder;
 use nix::libc;
+use proxmox_http::{client::sync::Client, HttpClient, HttpOptions};
 use proxmox_sys::fs::file_get_contents;
-use ureq::Agent;
 
 use crate::{
     config::{MirrorConfig, SubscriptionKey},
@@ -41,7 +41,7 @@ struct ParsedMirrorConfig {
     pub verify: bool,
     pub sync: bool,
     pub auth: Option<String>,
-    pub agent: Agent,
+    pub client: Client,
 }
 
 impl TryInto<ParsedMirrorConfig> for MirrorConfig {
@@ -54,9 +54,12 @@ impl TryInto<ParsedMirrorConfig> for MirrorConfig {
 
         let key = file_get_contents(Path::new(&self.key_path))?;
 
-        let agent = ureq::builder()
-            .user_agent("proxmox-offline-mirror 0.1") // TODO actually read version ;)
-            .build();
+        let options = HttpOptions {
+            user_agent: Some("proxmox-offline-mirror 0.1".to_string()),
+            ..Default::default()
+        }; // TODO actually read version ;)
+
+        let client = Client::new(options);
 
         Ok(ParsedMirrorConfig {
             repository,
@@ -66,7 +69,7 @@ impl TryInto<ParsedMirrorConfig> for MirrorConfig {
             verify: self.verify,
             sync: self.sync,
             auth: None,
-            agent,
+            client,
         })
     }
 }
@@ -96,7 +99,7 @@ fn get_repo_url(repo: &APTRepository, path: &str) -> String {
 ///
 /// Only fetches and returns data, doesn't store anything anywhere.
 fn fetch_repo_file(
-    agent: &Agent,
+    client: &Client,
     uri: &str,
     max_size: Option<u64>,
     checksums: Option<&CheckSums>,
@@ -104,26 +107,28 @@ fn fetch_repo_file(
 ) -> Result<FetchResult, Error> {
     println!("-> GET '{}'..", uri);
 
-    let request = if let Some(auth) = auth {
-        agent.get(uri).set("Authorization", auth)
+    let headers = if let Some(auth) = auth {
+        let mut map = HashMap::new();
+        map.insert("Authorization".to_string(), auth.to_string());
+        Some(map)
     } else {
-        agent.get(uri)
+        None
     };
 
-    let response = request.call()?.into_reader();
+    let response = client.get(uri, headers.as_ref())?;
 
+    let reader: Box<dyn Read> = response.into_body();
+    let mut reader = reader.take(max_size.unwrap_or(u64::MAX));
     let mut data = Vec::new();
-    let bytes = response
-        .take(max_size.unwrap_or(10_000_000))
-        .read_to_end(&mut data)?;
+    reader.read_to_end(&mut data)?;
 
     if let Some(checksums) = checksums {
         checksums.verify(&data)?;
     }
 
     Ok(FetchResult {
+        fetched: data.len(),
         data,
-        fetched: bytes,
     })
 }
 
@@ -138,14 +143,14 @@ fn fetch_release(
     let (name, fetched, sig) = if detached {
         println!("Fetching Release/Release.gpg files");
         let sig = fetch_repo_file(
-            &config.agent,
+            &config.client,
             &get_dist_url(&config.repository, "Release.gpg"),
             None,
             None,
             config.auth.as_deref(),
         )?;
         let mut fetched = fetch_repo_file(
-            &config.agent,
+            &config.client,
             &get_dist_url(&config.repository, "Release"),
             Some(32_000_000),
             None,
@@ -156,7 +161,7 @@ fn fetch_release(
     } else {
         println!("Fetching InRelease file");
         let fetched = fetch_repo_file(
-            &config.agent,
+            &config.client,
             &get_dist_url(&config.repository, "InRelease"),
             Some(32_000_000),
             None,
@@ -309,7 +314,7 @@ fn fetch_plain_file(
         }
     } else {
         let fetched = fetch_repo_file(
-            &config.agent,
+            &config.client,
             url,
             Some(5_000_000_000),
             Some(checksums),
index d5cb61d01bee4e68ddf6e810c1eeefd7d46fd657..0eb4e947c8720b27a90ff32401262b97163eda63 100644 (file)
@@ -1,6 +1,7 @@
 use anyhow::{bail, format_err, Error};
-use hyper::body::Buf;
-use proxmox_http::client::{SimpleHttp, SimpleHttpOptions};
+
+use proxmox_http::client::sync::Client;
+use proxmox_http::{HttpClient, HttpOptions};
 use proxmox_subscription::{
     sign::{SignRequest, SignedResponse},
     SubscriptionInfo,
@@ -12,14 +13,12 @@ const PRODUCT_URL: &str = "ADD URL FOR PROXMOX-APT-MIRROR";
 // TODO add version?
 const USER_AGENT: &str = "proxmox-offline-mirror";
 
-fn simple_http() -> SimpleHttp {
-    let options = SimpleHttpOptions {
-        proxy_config: None,
+fn client() -> Client {
+    let options = HttpOptions {
         user_agent: Some(USER_AGENT.to_string()),
-        tcp_keepalive: Some(30),
+        ..Default::default()
     };
-
-    SimpleHttp::with_options(options)
+    Client::new(options)
 }
 
 pub fn extract_mirror_key(keys: &[SubscriptionKey]) -> Result<SubscriptionKey, Error> {
@@ -44,7 +43,7 @@ pub async fn refresh(
         mirror_key.key.clone(),
         mirror_key.server_id.clone(),
         PRODUCT_URL.to_string(),
-        simple_http(),
+        client(),
     )?;
     offline_keys.retain(|k| k.product() != ProductType::Pom);
     if offline_keys.is_empty() {
@@ -56,7 +55,7 @@ pub async fn refresh(
             key.key.clone(),
             key.server_id.clone(),
             PRODUCT_URL.to_string(),
-            simple_http(),
+            client(),
         ) {
             errors = true;
             eprintln!("Failed to refresh subscription key {} - {}", key.key, err);
@@ -69,17 +68,15 @@ pub async fn refresh(
         mirror_key: mirror_key.into(),
         blobs: offline_keys.into_iter().map(|k| k.into()).collect(),
     };
-    let res = simple_http()
-        .post(
-            "https://shop.proxmox.com/proxmox-subscription/sign",
-            Some(serde_json::to_string(&request)?),
-            Some("text/json"),
-        )
-        .await?;
+    let res = client().post(
+        "https://shop.proxmox.com/proxmox-subscription/sign",
+        Some(serde_json::to_vec(&request)?.as_slice()),
+        Some("text/json"),
+        None,
+    )?;
     if res.status().is_success() {
-        let body = res.into_body();
-        let res: SignedResponse =
-            serde_json::from_reader(hyper::body::aggregate(body).await?.reader())?;
+        let body: Vec<u8> = res.into_body();
+        let res: SignedResponse = serde_json::from_slice(&body)?;
         res.verify(&public_key)
     } else {
         bail!("Refresh failed - {}", res.status());