]> git.proxmox.com Git - proxmox-offline-mirror.git/commitdiff
fix #4445: mirror: subscription: add proxy support
authorLukas Wagner <l.wagner@proxmox.com>
Thu, 19 Jan 2023 10:40:40 +0000 (11:40 +0100)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 27 Jan 2023 09:02:12 +0000 (10:02 +0100)
This commit adds support for HTTP proxies, configurable via the
ALL_PROXY environment variable.

For example:
  $ ALL_PROXY="localhost:3128" proxmox-offline-mirror mirror <...>

Note: `ureq` seems to use HTTP CONNECT for *all* connections, including
HTTP on port 80. Proxies need to be configured to allow that - Squid by
default allows CONNECT only for HTTPS on port 443.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
src/mirror.rs
src/subscription.rs

index 86974b7c34d31d56584fe021ba6d07a38ac99767..787e223ce94b1d2fc803e26e9c1caf11748a5f89 100644 (file)
@@ -9,7 +9,7 @@ use anyhow::{bail, format_err, Error};
 use flate2::bufread::GzDecoder;
 use globset::{Glob, GlobSet, GlobSetBuilder};
 use nix::libc;
-use proxmox_http::{client::sync::Client, HttpClient, HttpOptions};
+use proxmox_http::{client::sync::Client, HttpClient, HttpOptions, ProxyConfig};
 use proxmox_sys::fs::file_get_contents;
 
 use crate::{
@@ -64,6 +64,7 @@ impl TryInto<ParsedMirrorConfig> for MirrorConfig {
 
         let options = HttpOptions {
             user_agent: Some("proxmox-offline-mirror 0.1".to_string()),
+            proxy_config: ProxyConfig::from_proxy_env()?,
             ..Default::default()
         }; // TODO actually read version ;)
 
index 42794fe473c5b3fed005ffa65848a8182c576d4d..d186a95c34261441588c9742004b1ae1a4766abd 100644 (file)
@@ -1,7 +1,7 @@
 use anyhow::{bail, format_err, Error};
 
 use proxmox_http::client::sync::Client;
-use proxmox_http::{HttpClient, HttpOptions};
+use proxmox_http::{HttpClient, HttpOptions, ProxyConfig};
 use proxmox_subscription::SubscriptionStatus;
 use proxmox_subscription::{
     sign::{SignRequest, SignedResponse},
@@ -15,12 +15,13 @@ const PRODUCT_URL: &str = "-";
 // TODO add version?
 const USER_AGENT: &str = "proxmox-offline-mirror";
 
-fn client() -> Client {
+fn client() -> Result<Client, Error> {
     let options = HttpOptions {
         user_agent: Some(USER_AGENT.to_string()),
+        proxy_config: ProxyConfig::from_proxy_env()?,
         ..Default::default()
     };
-    Client::new(options)
+    Ok(Client::new(options))
 }
 
 pub fn extract_mirror_key(keys: &[SubscriptionKey]) -> Result<SubscriptionKey, Error> {
@@ -61,7 +62,7 @@ pub fn refresh_offline_keys(
             key.key.clone(),
             key.server_id.clone(),
             PRODUCT_URL.to_string(),
-            client(),
+            client()?,
         ) {
             errors = true;
             eprintln!("Failed to refresh subscription key {} - {}", key.key, err);
@@ -74,7 +75,7 @@ pub fn refresh_offline_keys(
         mirror_key: mirror_key.into(),
         blobs: offline_keys.into_iter().map(|k| k.into()).collect(),
     };
-    let res = client().post(
+    let res = client()?.post(
         "https://shop.proxmox.com/proxmox-subscription/sign",
         Some(serde_json::to_vec(&request)?.as_slice()),
         Some("text/json"),
@@ -98,6 +99,6 @@ pub fn refresh_mirror_key(mirror_key: SubscriptionKey) -> Result<SubscriptionInf
         mirror_key.key,
         mirror_key.server_id,
         PRODUCT_URL.to_string(),
-        client(),
+        client()?,
     )
 }