[pbs-devel] [PATCH proxmox-backup 2/4] fix #3296: node conf: add http_proxy to config

Dylan Whyte d.whyte at proxmox.com
Fri May 7 12:53:01 CEST 2021


add http_proxy to server's node config, as well as functions for setting
retrieving

Signed-off-by: Dylan Whyte <d.whyte at proxmox.com>
---
 src/config/node.rs | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/config/node.rs b/src/config/node.rs
index 6f48409f..e4bbc3e5 100644
--- a/src/config/node.rs
+++ b/src/config/node.rs
@@ -10,8 +10,12 @@ use proxmox::api::api;
 use proxmox::api::schema::{ApiStringFormat, Updater};
 use proxmox::tools::fs::{replace_file, CreateOptions};
 
-use crate::api2::types::{AcmeDomain, AcmeAccountName, ACME_DOMAIN_PROPERTY_SCHEMA};
+use crate::api2::types::{AcmeDomain,
+                        AcmeAccountName,
+                        ACME_DOMAIN_PROPERTY_SCHEMA,
+                        HTTP_PROXY_SCHEMA};
 use crate::acme::AcmeClient;
+use crate::tools::http::ProxyConfig;
 
 const CONF_FILE: &str = configdir!("/node.cfg");
 const LOCK_FILE: &str = configdir!("/.node.lck");
@@ -88,6 +92,10 @@ pub struct AcmeConfig {
             schema: ACME_DOMAIN_PROPERTY_SCHEMA,
             optional: true,
         },
+        http_proxy: {
+            schema: HTTP_PROXY_SCHEMA,
+            optional: true,
+        },
     },
 )]
 #[derive(Deserialize, Serialize, Updater)]
@@ -111,6 +119,9 @@ pub struct NodeConfig {
 
     #[serde(skip_serializing_if = "Updater::is_empty")]
     acmedomain4: Option<String>,
+
+    #[serde(skip_serializing_if = "Updater::is_empty")]
+    http_proxy: Option<String>,
 }
 
 impl NodeConfig {
@@ -137,6 +148,21 @@ impl NodeConfig {
         AcmeDomainIter::new(self)
     }
 
+    pub fn http_proxy(&self) -> Option<ProxyConfig> {
+        if let Some(http_proxy) = &self.http_proxy {
+            match ProxyConfig::parse_proxy_url(&http_proxy) {
+                Ok(proxy) => Some(proxy),
+                Err(_) => None,
+            }
+        } else {
+            None
+        }
+    }
+
+    pub fn set_proxy(&mut self, http_proxy: Option<String>) {
+        self.http_proxy = http_proxy;
+    }
+
     /// Validate the configuration.
     pub fn validate(&self) -> Result<(), Error> {
         let mut domains = HashSet::new();
-- 
2.20.1






More information about the pbs-devel mailing list