diff options
author | iximeow <git@iximeow.net> | 2022-12-26 00:50:26 +0000 |
---|---|---|
committer | iximeow <git@iximeow.net> | 2022-12-26 00:50:26 +0000 |
commit | 7e84420dfe659494318630863ff97a75b0ad32ff (patch) | |
tree | b24cd3318c2b5891e246ac4bd4678603f8bad3c9 /src/notifier.rs | |
parent | 99f81b94fdc7289dcdb34a98e57b9550b3bd170b (diff) |
secrets are configurable now
Diffstat (limited to 'src/notifier.rs')
-rw-r--r-- | src/notifier.rs | 19 |
1 files changed, 11 insertions, 8 deletions
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<Self, String> { + pub fn github_from_file<P: AsRef<Path>>(path: P) -> Result<Self, String> { + 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<Self, String> { + pub fn email_from_file<P: AsRef<Path>>(path: P) -> Result<Self, String> { + 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())) } } } |