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/ci_driver.rs | 23 +++++++++++++++++++---- src/dbctx.rs | 18 +++++++++++++----- src/notifier.rs | 19 +++++++++++-------- 3 files changed, 43 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/ci_driver.rs b/src/ci_driver.rs index ef224b8..35c9b07 100644 --- a/src/ci_driver.rs +++ b/src/ci_driver.rs @@ -437,18 +437,33 @@ async fn make_api_server(dbctx: Arc) -> (Router, mpsc::Receiver, } @@ -84,9 +86,9 @@ impl ArtifactDescriptor { } impl DbCtx { - pub fn new(config_path: &str, db_path: &str) -> Self { + pub fn new>(config_path: P, db_path: P) -> Self { DbCtx { - config_path: config_path.to_owned(), + config_path: config_path.as_ref().to_owned(), conn: Mutex::new(Connection::open(db_path).unwrap()) } } @@ -293,17 +295,23 @@ impl DbCtx { for remote in remotes.into_iter() { match remote.remote_api.as_str() { "github" => { + let mut notifier_path = self.config_path.clone(); + notifier_path.push(&remote.notifier_config_path); + let notifier = RemoteNotifier { remote_path: remote.remote_path, - notifier: NotifierConfig::github_from_file(&format!("{}/{}", self.config_path, remote.notifier_config_path)) + notifier: NotifierConfig::github_from_file(¬ifier_path) .expect("can load notifier config") }; notifiers.push(notifier); }, "email" => { + let mut notifier_path = self.config_path.clone(); + notifier_path.push(&remote.notifier_config_path); + let notifier = RemoteNotifier { remote_path: remote.remote_path, - notifier: NotifierConfig::email_from_file(&format!("{}/{}", self.config_path, remote.notifier_config_path)) + notifier: NotifierConfig::email_from_file(¬ifier_path) .expect("can load notifier config") }; notifiers.push(notifier); 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