From 7e84420dfe659494318630863ff97a75b0ad32ff Mon Sep 17 00:00:00 2001 From: iximeow Date: Mon, 26 Dec 2022 00:50:26 +0000 Subject: secrets are configurable now --- src/notifier.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/notifier.rs') diff --git a/src/notifier.rs b/src/notifier.rs index 3d9964a..3ccda47 100644 --- a/src/notifier.rs +++ b/src/notifier.rs @@ -6,6 +6,7 @@ use lettre::{Message, Transport}; use lettre::transport::smtp::extension::ClientId; use lettre::transport::smtp::client::{SmtpConnection, TlsParametersBuilder}; use std::time::Duration; +use std::path::Path; use crate::DbCtx; @@ -30,29 +31,31 @@ pub enum NotifierConfig { } impl NotifierConfig { - pub fn github_from_file(path: &str) -> Result { + pub fn github_from_file>(path: P) -> Result { + let path = path.as_ref(); let bytes = std::fs::read(path) - .map_err(|e| format!("can't read notifier config at {}: {:?}", path, e))?; + .map_err(|e| format!("can't read notifier config at {}: {:?}", path.display(), e))?; let config = serde_json::from_slice(&bytes) - .map_err(|e| format!("can't deserialize notifier config at {}: {:?}", path, e))?; + .map_err(|e| format!("can't deserialize notifier config at {}: {:?}", path.display(), e))?; if matches!(config, NotifierConfig::GitHub { .. }) { Ok(config) } else { - Err(format!("config at {} doesn't look like a github config (but was otherwise valid?)", path)) + Err(format!("config at {} doesn't look like a github config (but was otherwise valid?)", path.display())) } } - pub fn email_from_file(path: &str) -> Result { + pub fn email_from_file>(path: P) -> Result { + let path = path.as_ref(); let bytes = std::fs::read(path) - .map_err(|e| format!("can't read notifier config at {}: {:?}", path, e))?; + .map_err(|e| format!("can't read notifier config at {}: {:?}", path.display(), e))?; let config = serde_json::from_slice(&bytes) - .map_err(|e| format!("can't deserialize notifier config at {}: {:?}", path, e))?; + .map_err(|e| format!("can't deserialize notifier config at {}: {:?}", path.display(), e))?; if matches!(config, NotifierConfig::Email { .. }) { Ok(config) } else { - Err(format!("config at {} doesn't look like an email config (but was otherwise valid?)", path)) + Err(format!("config at {} doesn't look like an email config (but was otherwise valid?)", path.display())) } } } -- cgit v1.1