From ff90b5fb2de9c389604117b809a2d9539ac3de1f Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 30 Mar 2021 22:00:59 +0200 Subject: [PATCH] job: move blacklist processing to request --- src/job.rs | 7 ------- src/main.rs | 16 +++++++++++++++- src/settings.rs | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/job.rs b/src/job.rs index 0477704..2e91cf1 100644 --- a/src/job.rs +++ b/src/job.rs @@ -190,13 +190,6 @@ impl Job { } pub(crate) fn run(&mut self, homedir: &Path, config: &GlobalSettings) -> anyhow::Result<()> { - if config - .blacklist - .iter() - .any(|re| re.is_match(&self.repo.full_name)) - { - return Ok(()); - } let local_path = homedir.join(&self.repo.full_name); assert!(local_path.is_absolute()); self.local_path = Some(local_path); diff --git a/src/main.rs b/src/main.rs index ce09507..812615d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,19 @@ struct JobSender(Mutex>); struct Secret(String); #[post("/", data = "")] -fn gitea_webhook(payload: SignedJson, sender: State) -> Status { +fn gitea_webhook( + payload: SignedJson, + sender: State, + config: State, +) -> Status { + if config + .blacklist + .iter() + .any(|re| re.is_match(&payload.repository.full_name)) + { + return Status::Ok; + } + { let sender = sender.0.lock().unwrap(); let repo = &payload.repository; @@ -74,6 +86,7 @@ fn main() -> anyhow::Result<()> { .expect("please provide a secret, otherwise anyone can send you a malicious webhook"); let config = parse_config(homedir.clone())?; + let config_state = config.clone(); thread::spawn(move || { repo_updater(receiver, homedir, config); @@ -83,6 +96,7 @@ fn main() -> anyhow::Result<()> { .mount("/", routes![gitea_webhook]) .manage(JobSender(Mutex::new(sender))) .manage(Secret(secret)) + .manage(config_state) .launch(); Ok(()) diff --git a/src/settings.rs b/src/settings.rs index 976264f..8dc71f9 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -2,7 +2,7 @@ use serde::Deserialize; pub(crate) type RepoUrl = String; // FIXME: probably needs a better type than this -#[derive(Default, Deserialize)] +#[derive(Clone, Default, Deserialize)] pub(crate) struct GlobalSettings { /// List of remote stems to use when no `.lohr` file is found #[serde(default)]