notify: add context for getting http_proxy from datacenter.cfg

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
This commit is contained in:
Lukas Wagner 2023-07-20 16:32:01 +02:00 committed by Wolfgang Bumiller
parent 178196e1ae
commit de59ffe4ec

View File

@ -62,6 +62,11 @@ impl Context for PVEContext {
.and_then(|content| lookup_datacenter_config_key(&content, "mail_from")) .and_then(|content| lookup_datacenter_config_key(&content, "mail_from"))
.unwrap_or_else(|| String::from("root")) .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)] #[cfg(test)]
@ -89,6 +94,7 @@ user:no-mail@pve:1:0::::::
const DC_CONFIG: &str = " const DC_CONFIG: &str = "
email_from: user@example.com email_from: user@example.com
http_proxy: http://localhost:1234
keyboard: en-us keyboard: en-us
"; ";
#[test] #[test]
@ -97,6 +103,11 @@ keyboard: en-us
lookup_datacenter_config_key(DC_CONFIG, "email_from"), lookup_datacenter_config_key(DC_CONFIG, "email_from"),
Some("user@example.com".to_string()) Some("user@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);
} }
} }