Remove final Boxed types
This commit is contained in:
parent
3d3dfb34ed
commit
6941ceec8e
@ -38,23 +38,18 @@ pub enum SetError {
|
|||||||
Unexpected(#[from] unexpected::Error),
|
Unexpected(#[from] unexpected::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used in the return from all_domains from Store.
|
|
||||||
pub type AllDomainsResult<T> = Result<T, unexpected::Error>;
|
|
||||||
|
|
||||||
#[mockall::automock]
|
#[mockall::automock]
|
||||||
pub trait Store {
|
pub trait Store: Sync + Send {
|
||||||
fn get(&self, domain: &domain::Name) -> Result<Config, GetError>;
|
fn get(&self, domain: &domain::Name) -> Result<Config, GetError>;
|
||||||
fn set(&self, domain: &domain::Name, config: &Config) -> Result<(), SetError>;
|
fn set(&self, domain: &domain::Name, config: &Config) -> Result<(), SetError>;
|
||||||
fn all_domains(&self) -> AllDomainsResult<Vec<AllDomainsResult<domain::Name>>>;
|
fn all_domains(&self) -> Result<Vec<domain::Name>, unexpected::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait BoxedStore: Store + Send + Sync + Clone + 'static {}
|
|
||||||
|
|
||||||
struct FSStore {
|
struct FSStore {
|
||||||
dir_path: PathBuf,
|
dir_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(dir_path: &Path) -> io::Result<impl BoxedStore> {
|
pub fn new(dir_path: &Path) -> io::Result<sync::Arc<dyn Store>> {
|
||||||
fs::create_dir_all(dir_path)?;
|
fs::create_dir_all(dir_path)?;
|
||||||
Ok(sync::Arc::new(FSStore {
|
Ok(sync::Arc::new(FSStore {
|
||||||
dir_path: dir_path.into(),
|
dir_path: dir_path.into(),
|
||||||
@ -71,9 +66,7 @@ impl FSStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BoxedStore for sync::Arc<FSStore> {}
|
impl Store for FSStore {
|
||||||
|
|
||||||
impl Store for sync::Arc<FSStore> {
|
|
||||||
fn get(&self, domain: &domain::Name) -> Result<Config, GetError> {
|
fn get(&self, domain: &domain::Name) -> Result<Config, GetError> {
|
||||||
let path = self.config_file_path(domain);
|
let path = self.config_file_path(domain);
|
||||||
let config_file = fs::File::open(path.as_path()).map_err(|e| match e.kind() {
|
let config_file = fs::File::open(path.as_path()).map_err(|e| match e.kind() {
|
||||||
@ -103,11 +96,11 @@ impl Store for sync::Arc<FSStore> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_domains(&self) -> AllDomainsResult<Vec<AllDomainsResult<domain::Name>>> {
|
fn all_domains(&self) -> Result<Vec<domain::Name>, unexpected::Error> {
|
||||||
Ok(fs::read_dir(&self.dir_path)
|
fs::read_dir(&self.dir_path)
|
||||||
.or_unexpected()?
|
.or_unexpected()?
|
||||||
.map(
|
.map(
|
||||||
|dir_entry_res: io::Result<fs::DirEntry>| -> AllDomainsResult<domain::Name> {
|
|dir_entry_res: io::Result<fs::DirEntry>| -> Result<domain::Name, unexpected::Error> {
|
||||||
let domain = dir_entry_res.or_unexpected()?.file_name();
|
let domain = dir_entry_res.or_unexpected()?.file_name();
|
||||||
let domain = domain.to_str().ok_or(unexpected::Error::from(
|
let domain = domain.to_str().ok_or(unexpected::Error::from(
|
||||||
"couldn't convert os string to &str",
|
"couldn't convert os string to &str",
|
||||||
@ -117,7 +110,7 @@ impl Store for sync::Arc<FSStore> {
|
|||||||
.map_unexpected_while(|| format!("parsing {domain} as domain name"))
|
.map_unexpected_while(|| format!("parsing {domain} as domain name"))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.collect())
|
.try_collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +116,6 @@ impl From<config::SetError> for SyncWithConfigError {
|
|||||||
|
|
||||||
pub type GetAcmeHttp01ChallengeKeyError = acme::manager::GetHttp01ChallengeKeyError;
|
pub type GetAcmeHttp01ChallengeKeyError = acme::manager::GetHttp01ChallengeKeyError;
|
||||||
|
|
||||||
pub type AllDomainsResult<T> = config::AllDomainsResult<T>;
|
|
||||||
|
|
||||||
#[mockall::automock]
|
#[mockall::automock]
|
||||||
pub trait Manager: Sync + Send {
|
pub trait Manager: Sync + Send {
|
||||||
fn get_config(&self, domain: &domain::Name) -> Result<config::Config, GetConfigError>;
|
fn get_config(&self, domain: &domain::Name) -> Result<config::Config, GetConfigError>;
|
||||||
@ -138,15 +136,12 @@ pub trait Manager: Sync + Send {
|
|||||||
token: &str,
|
token: &str,
|
||||||
) -> Result<String, GetAcmeHttp01ChallengeKeyError>;
|
) -> Result<String, GetAcmeHttp01ChallengeKeyError>;
|
||||||
|
|
||||||
fn all_domains(&self) -> AllDomainsResult<Vec<AllDomainsResult<domain::Name>>>;
|
fn all_domains(&self) -> Result<Vec<domain::Name>, unexpected::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ManagerImpl<DomainConfigStore>
|
struct ManagerImpl {
|
||||||
where
|
|
||||||
DomainConfigStore: config::BoxedStore,
|
|
||||||
{
|
|
||||||
origin_store: sync::Arc<dyn origin::store::Store>,
|
origin_store: sync::Arc<dyn origin::store::Store>,
|
||||||
domain_config_store: DomainConfigStore,
|
domain_config_store: sync::Arc<dyn config::Store>,
|
||||||
domain_checker: checker::DNSChecker,
|
domain_checker: checker::DNSChecker,
|
||||||
acme_manager: Option<sync::Arc<dyn acme::manager::Manager>>,
|
acme_manager: Option<sync::Arc<dyn acme::manager::Manager>>,
|
||||||
|
|
||||||
@ -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<dyn origin::store::Store>,
|
origin_store: sync::Arc<dyn origin::store::Store>,
|
||||||
domain_config_store: DomainConfigStore,
|
domain_config_store: sync::Arc<dyn config::Store>,
|
||||||
domain_checker: checker::DNSChecker,
|
domain_checker: checker::DNSChecker,
|
||||||
acme_manager: Option<sync::Arc<dyn acme::manager::Manager>>,
|
acme_manager: Option<sync::Arc<dyn acme::manager::Manager>>,
|
||||||
) -> sync::Arc<dyn Manager>
|
) -> sync::Arc<dyn Manager> {
|
||||||
where
|
|
||||||
DomainConfigStore: config::BoxedStore,
|
|
||||||
{
|
|
||||||
let canceller = CancellationToken::new();
|
let canceller = CancellationToken::new();
|
||||||
|
|
||||||
let origin_sync_handler = {
|
let origin_sync_handler = {
|
||||||
@ -206,10 +198,7 @@ where
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DomainConfigStore> ManagerImpl<DomainConfigStore>
|
impl ManagerImpl {
|
||||||
where
|
|
||||||
DomainConfigStore: config::BoxedStore,
|
|
||||||
{
|
|
||||||
pub async fn stop(self) {
|
pub async fn stop(self) {
|
||||||
self.canceller.cancel();
|
self.canceller.cancel();
|
||||||
self.origin_sync_handler
|
self.origin_sync_handler
|
||||||
@ -218,10 +207,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<DomainConfigStore> Manager for ManagerImpl<DomainConfigStore>
|
impl Manager for ManagerImpl {
|
||||||
where
|
|
||||||
DomainConfigStore: config::BoxedStore,
|
|
||||||
{
|
|
||||||
fn get_config(&self, domain: &domain::Name) -> Result<config::Config, GetConfigError> {
|
fn get_config(&self, domain: &domain::Name) -> Result<config::Config, GetConfigError> {
|
||||||
Ok(self.domain_config_store.get(domain)?)
|
Ok(self.domain_config_store.get(domain)?)
|
||||||
}
|
}
|
||||||
@ -278,7 +264,7 @@ where
|
|||||||
Err(GetAcmeHttp01ChallengeKeyError::NotFound)
|
Err(GetAcmeHttp01ChallengeKeyError::NotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_domains(&self) -> AllDomainsResult<Vec<AllDomainsResult<domain::Name>>> {
|
fn all_domains(&self) -> Result<Vec<domain::Name>, unexpected::Error> {
|
||||||
self.domain_config_store.all_domains()
|
self.domain_config_store.all_domains()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,8 +234,6 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for domain in domains_iter.unwrap().into_iter() {
|
for domain in domains_iter.unwrap().into_iter() {
|
||||||
match domain {
|
|
||||||
Ok(domain) => {
|
|
||||||
let _ = https_params
|
let _ = https_params
|
||||||
.domain_acme_manager
|
.domain_acme_manager
|
||||||
.sync_domain(domain.clone())
|
.sync_domain(domain.clone())
|
||||||
@ -247,9 +245,6 @@ async fn main() {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Err(err) => log::error!("Error iterating through domains: {err}"),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -292,13 +292,6 @@ impl<'svc> Service<'svc> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let domains: Vec<domain::Name> = 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<String> = domains
|
let mut domains: Vec<String> = domains
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|domain| domain.as_str().to_string())
|
.map(|domain| domain.as_str().to_string())
|
||||||
|
Loading…
Reference in New Issue
Block a user