[pve-devel] [PATCH v3 proxmox-perl-rs 32/66] notify: add context for getting http_proxy from datacenter.cfg

Lukas Wagner l.wagner at proxmox.com
Mon Jul 17 17:00:17 CEST 2023


Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 pve-rs/src/notify.rs | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/pve-rs/src/notify.rs b/pve-rs/src/notify.rs
index 04e902c..0c00b03 100644
--- a/pve-rs/src/notify.rs
+++ b/pve-rs/src/notify.rs
@@ -60,6 +60,11 @@ impl Context for PVEContext {
             .and_then(|content| lookup_datacenter_config_key(&content, "mail_from"))
             .unwrap_or_else(|| String::from("root"))
     }
+
+    fn http_proxy_config(&self) -> Option<String> {
+        let content = attempt_file_read("/etc/pve/datacenter.cfg");
+        content.and_then(|content| lookup_datacenter_config_key(&content, "http_proxy"))
+    }
 }
 
 #[cfg(test)]
@@ -87,6 +92,7 @@ user:no-mail at pve:1:0::::::
 
     const DC_CONFIG: &str = "
 email_from: user at example.com
+http_proxy: http://localhost:1234
 keyboard: en-us
 ";
     #[test]
@@ -95,6 +101,11 @@ keyboard: en-us
             lookup_datacenter_config_key(DC_CONFIG, "email_from"),
             Some("user at example.com".to_string())
         );
+        assert_eq!(
+            lookup_datacenter_config_key(DC_CONFIG, "http_proxy"),
+            Some("http://localhost:1234".to_string())
+        );
+        assert_eq!(lookup_datacenter_config_key(DC_CONFIG, "foo"), None);
     }
 }
 
-- 
2.39.2






More information about the pve-devel mailing list