diff options
author | Alex Auvolat <alex@adnab.me> | 2022-05-19 14:33:49 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-05-19 14:33:49 +0200 |
commit | 6be90936a108d971e0cfa3ddaa9c2d54557e30f3 (patch) | |
tree | ed0dae1b4ebf3215b808b81d9980376e9b5dee26 /src/main.rs | |
parent | 1ac56a91981bee4867dfb054bd2199c6111fe1eb (diff) | |
download | aerogramme-6be90936a108d971e0cfa3ddaa9c2d54557e30f3.tar.gz aerogramme-6be90936a108d971e0cfa3ddaa9c2d54557e30f3.zip |
Some refactoring
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 52 |
1 files changed, 4 insertions, 48 deletions
diff --git a/src/main.rs b/src/main.rs index 40dfbb8..ca66137 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ mod login; mod mailbox; mod time; mod uidindex; +mod server; use anyhow::{bail, Result}; use std::sync::Arc; @@ -14,6 +15,7 @@ use rusoto_signature::Region; use config::*; use login::{ldap_provider::*, static_provider::*, *}; use mailbox::Mailbox; +use server::Server; #[tokio::main] async fn main() { @@ -26,53 +28,7 @@ async fn main() { async fn main2() -> Result<()> { let config = read_config("mailrage.toml".into())?; - let main = Main::new(config)?; - main.run().await + let server = Server::new(config)?; + server.run().await } -struct Main { - pub s3_region: Region, - pub k2v_region: Region, - pub login_provider: Box<dyn LoginProvider>, -} - -impl Main { - fn new(config: Config) -> Result<Arc<Self>> { - let s3_region = Region::Custom { - name: config.s3_region, - endpoint: config.s3_endpoint, - }; - let k2v_region = Region::Custom { - name: config.k2v_region, - endpoint: config.k2v_endpoint, - }; - let login_provider: Box<dyn LoginProvider> = match (config.login_static, config.login_ldap) - { - (Some(st), None) => Box::new(StaticLoginProvider::new(st, k2v_region.clone())?), - (None, Some(ld)) => Box::new(LdapLoginProvider::new(ld)?), - (Some(_), Some(_)) => bail!("A single login provider must be set up in config file"), - (None, None) => bail!("No login provider is set up in config file"), - }; - Ok(Arc::new(Self { - s3_region, - k2v_region, - login_provider, - })) - } - - async fn run(self: &Arc<Self>) -> Result<()> { - let creds = self.login_provider.login("lx", "plop").await?; - - let mut mailbox = Mailbox::new( - &self.k2v_region, - &self.s3_region, - &creds, - "TestMailbox".to_string(), - ) - .await?; - - mailbox.test().await?; - - Ok(()) - } -} |