diff --git a/src/domain/config.rs b/src/domain/config.rs index 2c1b45b..a24efdf 100644 --- a/src/domain/config.rs +++ b/src/domain/config.rs @@ -38,23 +38,18 @@ pub enum SetError { Unexpected(#[from] unexpected::Error), } -/// Used in the return from all_domains from Store. -pub type AllDomainsResult = Result; - #[mockall::automock] -pub trait Store { +pub trait Store: Sync + Send { fn get(&self, domain: &domain::Name) -> Result; fn set(&self, domain: &domain::Name, config: &Config) -> Result<(), SetError>; - fn all_domains(&self) -> AllDomainsResult>>; + fn all_domains(&self) -> Result, unexpected::Error>; } -pub trait BoxedStore: Store + Send + Sync + Clone + 'static {} - struct FSStore { dir_path: PathBuf, } -pub fn new(dir_path: &Path) -> io::Result { +pub fn new(dir_path: &Path) -> io::Result> { fs::create_dir_all(dir_path)?; Ok(sync::Arc::new(FSStore { dir_path: dir_path.into(), @@ -71,9 +66,7 @@ impl FSStore { } } -impl BoxedStore for sync::Arc {} - -impl Store for sync::Arc { +impl Store for FSStore { fn get(&self, domain: &domain::Name) -> Result { let path = self.config_file_path(domain); let config_file = fs::File::open(path.as_path()).map_err(|e| match e.kind() { @@ -103,11 +96,11 @@ impl Store for sync::Arc { Ok(()) } - fn all_domains(&self) -> AllDomainsResult>> { - Ok(fs::read_dir(&self.dir_path) + fn all_domains(&self) -> Result, unexpected::Error> { + fs::read_dir(&self.dir_path) .or_unexpected()? .map( - |dir_entry_res: io::Result| -> AllDomainsResult { + |dir_entry_res: io::Result| -> Result { let domain = dir_entry_res.or_unexpected()?.file_name(); let domain = domain.to_str().ok_or(unexpected::Error::from( "couldn't convert os string to &str", @@ -117,7 +110,7 @@ impl Store for sync::Arc { .map_unexpected_while(|| format!("parsing {domain} as domain name")) }, ) - .collect()) + .try_collect() } } diff --git a/src/domain/manager.rs b/src/domain/manager.rs index b149b0f..bf8c09b 100644 --- a/src/domain/manager.rs +++ b/src/domain/manager.rs @@ -116,8 +116,6 @@ impl From for SyncWithConfigError { pub type GetAcmeHttp01ChallengeKeyError = acme::manager::GetHttp01ChallengeKeyError; -pub type AllDomainsResult = config::AllDomainsResult; - #[mockall::automock] pub trait Manager: Sync + Send { fn get_config(&self, domain: &domain::Name) -> Result; @@ -138,15 +136,12 @@ pub trait Manager: Sync + Send { token: &str, ) -> Result; - fn all_domains(&self) -> AllDomainsResult>>; + fn all_domains(&self) -> Result, unexpected::Error>; } -struct ManagerImpl -where - DomainConfigStore: config::BoxedStore, -{ +struct ManagerImpl { origin_store: sync::Arc, - domain_config_store: DomainConfigStore, + domain_config_store: sync::Arc, domain_checker: checker::DNSChecker, acme_manager: Option>, @@ -170,15 +165,12 @@ fn sync_origins(origin_store: &dyn origin::store::Store) { }); } -pub fn new<'mgr, DomainConfigStore>( +pub fn new( origin_store: sync::Arc, - domain_config_store: DomainConfigStore, + domain_config_store: sync::Arc, domain_checker: checker::DNSChecker, acme_manager: Option>, -) -> sync::Arc -where - DomainConfigStore: config::BoxedStore, -{ +) -> sync::Arc { let canceller = CancellationToken::new(); let origin_sync_handler = { @@ -206,10 +198,7 @@ where }) } -impl ManagerImpl -where - DomainConfigStore: config::BoxedStore, -{ +impl ManagerImpl { pub async fn stop(self) { self.canceller.cancel(); self.origin_sync_handler @@ -218,10 +207,7 @@ where } } -impl Manager for ManagerImpl -where - DomainConfigStore: config::BoxedStore, -{ +impl Manager for ManagerImpl { fn get_config(&self, domain: &domain::Name) -> Result { Ok(self.domain_config_store.get(domain)?) } @@ -278,7 +264,7 @@ where Err(GetAcmeHttp01ChallengeKeyError::NotFound) } - fn all_domains(&self) -> AllDomainsResult>> { + fn all_domains(&self) -> Result, unexpected::Error> { self.domain_config_store.all_domains() } } diff --git a/src/main.rs b/src/main.rs index 35fd20c..4341b3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -234,21 +234,16 @@ async fn main() { } for domain in domains_iter.unwrap().into_iter() { - match domain { - Ok(domain) => { - let _ = https_params - .domain_acme_manager - .sync_domain(domain.clone()) - .await - .inspect_err(|err| { - log::error!( - "Error while getting cert for {}: {err}", - domain.as_str(), - ) - }); - } - Err(err) => log::error!("Error iterating through domains: {err}"), - }; + let _ = https_params + .domain_acme_manager + .sync_domain(domain.clone()) + .await + .inspect_err(|err| { + log::error!( + "Error while getting cert for {}: {err}", + domain.as_str(), + ) + }); } } }) diff --git a/src/service.rs b/src/service.rs index a821132..820119b 100644 --- a/src/service.rs +++ b/src/service.rs @@ -292,13 +292,6 @@ impl<'svc> Service<'svc> { } }; - let domains: Vec = match domains.into_iter().try_collect() { - Ok(domains) => domains, - Err(e) => { - return self.render_error_page(500, format!("failed get all domains: {e}").as_str()) - } - }; - let mut domains: Vec = domains .into_iter() .map(|domain| domain.as_str().to_string())