Don't include Send/Sync in trait requirements
This commit is contained in:
parent
fa85fe7fd8
commit
7a35befffe
@ -10,7 +10,7 @@ pub type GetHttp01ChallengeKeyError = acme::store::GetHttp01ChallengeKeyError;
|
||||
pub type GetCertificateError = acme::store::GetCertificateError;
|
||||
|
||||
#[mockall::automock]
|
||||
pub trait Manager: Sync + Send {
|
||||
pub trait Manager {
|
||||
fn sync_domain<'mgr>(
|
||||
&'mgr self,
|
||||
domain: domain::Name,
|
||||
@ -25,12 +25,12 @@ pub trait Manager: Sync + Send {
|
||||
}
|
||||
|
||||
pub struct ManagerImpl {
|
||||
store: Box<dyn acme::store::Store>,
|
||||
store: Box<dyn acme::store::Store + Send + Sync>,
|
||||
account: sync::Arc<acme2::Account>,
|
||||
}
|
||||
|
||||
impl ManagerImpl {
|
||||
pub async fn new<Store: acme::store::Store + 'static>(
|
||||
pub async fn new<Store: acme::store::Store + Send + Sync + 'static>(
|
||||
store: Store,
|
||||
contact_email: &str,
|
||||
) -> Result<Self, unexpected::Error> {
|
||||
|
@ -38,7 +38,7 @@ pub enum GetCertificateError {
|
||||
}
|
||||
|
||||
#[mockall::automock]
|
||||
pub trait Store: Sync + Send {
|
||||
pub trait Store {
|
||||
fn set_account_key(&self, k: &PrivateKey) -> Result<(), unexpected::Error>;
|
||||
fn get_account_key(&self) -> Result<PrivateKey, GetAccountKeyError>;
|
||||
|
||||
|
@ -39,7 +39,7 @@ pub enum SetError {
|
||||
}
|
||||
|
||||
#[mockall::automock]
|
||||
pub trait Store: Sync + Send {
|
||||
pub trait Store {
|
||||
fn get(&self, domain: &domain::Name) -> Result<Config, GetError>;
|
||||
fn set(&self, domain: &domain::Name, config: &Config) -> Result<(), SetError>;
|
||||
fn all_domains(&self) -> Result<Vec<domain::Name>, unexpected::Error>;
|
||||
|
@ -145,63 +145,66 @@ pub trait Manager: Sync + Send + rustls::server::ResolvesServerCert {
|
||||
fn all_domains(&self) -> Result<Vec<domain::Name>, unexpected::Error>;
|
||||
}
|
||||
|
||||
struct ManagerImpl {
|
||||
origin_store: Box<dyn origin::store::Store>,
|
||||
domain_config_store: Box<dyn config::Store>,
|
||||
pub struct ManagerImpl {
|
||||
origin_store: Box<dyn origin::store::Store + Send + Sync>,
|
||||
domain_config_store: Box<dyn config::Store + Send + Sync>,
|
||||
domain_checker: checker::DNSChecker,
|
||||
acme_manager: Option<Box<dyn acme::manager::Manager>>,
|
||||
acme_manager: Option<Box<dyn acme::manager::Manager + Send + Sync>>,
|
||||
}
|
||||
|
||||
async fn sync_origins(origin_store: &dyn origin::store::Store, canceller: CancellationToken) {
|
||||
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(20 * 60));
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = interval.tick() => {
|
||||
match origin_store.all_descrs() {
|
||||
Ok(iter) => iter.into_iter(),
|
||||
Err(err) => {
|
||||
log::error!("Error fetching origin descriptors: {err}");
|
||||
return;
|
||||
impl ManagerImpl {
|
||||
pub fn new<
|
||||
OriginStore: origin::store::Store + Send + Sync + 'static,
|
||||
DomainConfigStore: config::Store + Send + Sync + 'static,
|
||||
AcmeManager: acme::manager::Manager + Send + Sync + 'static,
|
||||
>(
|
||||
task_stack: &mut util::TaskStack<unexpected::Error>,
|
||||
origin_store: OriginStore,
|
||||
domain_config_store: DomainConfigStore,
|
||||
domain_checker: checker::DNSChecker,
|
||||
acme_manager: Option<AcmeManager>,
|
||||
) -> sync::Arc<dyn Manager> {
|
||||
let manager = sync::Arc::new(ManagerImpl {
|
||||
origin_store: Box::from(origin_store),
|
||||
domain_config_store: Box::from(domain_config_store),
|
||||
domain_checker: domain_checker,
|
||||
acme_manager: acme_manager
|
||||
.map(|m| Box::new(m) as Box<dyn acme::manager::Manager + Send + Sync>),
|
||||
});
|
||||
|
||||
task_stack.push_spawn(|canceller| {
|
||||
let manager = manager.clone();
|
||||
async move { Ok(manager.sync_origins(canceller).await) }
|
||||
});
|
||||
|
||||
manager
|
||||
}
|
||||
|
||||
async fn sync_origins(&self, canceller: CancellationToken) {
|
||||
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(20 * 60));
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = interval.tick() => {
|
||||
match self.origin_store.all_descrs() {
|
||||
Ok(iter) => iter.into_iter(),
|
||||
Err(err) => {
|
||||
log::error!("Error fetching origin descriptors: {err}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
.for_each(|descr| {
|
||||
if let Err(err) = self.origin_store.sync(descr.clone(), origin::store::Limits {}) {
|
||||
log::error!("Failed to sync store for {:?}: {err}", descr);
|
||||
return;
|
||||
}
|
||||
});
|
||||
},
|
||||
_ = canceller.cancelled() => return,
|
||||
}
|
||||
.for_each(|descr| {
|
||||
if let Err(err) = origin_store.sync(descr.clone(), origin::store::Limits {}) {
|
||||
log::error!("Failed to sync store for {:?}: {err}", descr);
|
||||
return;
|
||||
}
|
||||
});
|
||||
},
|
||||
_ = canceller.cancelled() => return,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new<
|
||||
OriginStore: origin::store::Store + 'static,
|
||||
DomainConfigStore: config::Store + 'static,
|
||||
AcmeManager: acme::manager::Manager + 'static,
|
||||
>(
|
||||
task_stack: &mut util::TaskStack<unexpected::Error>,
|
||||
origin_store: OriginStore,
|
||||
domain_config_store: DomainConfigStore,
|
||||
domain_checker: checker::DNSChecker,
|
||||
acme_manager: Option<AcmeManager>,
|
||||
) -> sync::Arc<dyn Manager> {
|
||||
let manager = sync::Arc::new(ManagerImpl {
|
||||
origin_store: Box::from(origin_store),
|
||||
domain_config_store: Box::from(domain_config_store),
|
||||
domain_checker: domain_checker,
|
||||
acme_manager: acme_manager.map(|m| Box::new(m) as Box<dyn acme::manager::Manager>),
|
||||
});
|
||||
|
||||
task_stack.push_spawn(|canceller| {
|
||||
let manager = manager.clone();
|
||||
async move { Ok(sync_origins(manager.origin_store.as_ref(), canceller).await) }
|
||||
});
|
||||
|
||||
manager
|
||||
}
|
||||
|
||||
impl Manager for ManagerImpl {
|
||||
fn get_config(&self, domain: &domain::Name) -> Result<config::Config, GetConfigError> {
|
||||
Ok(self.domain_config_store.get(domain)?)
|
||||
|
@ -112,7 +112,7 @@ async fn main() {
|
||||
|
||||
let mut task_stack = domani::util::TaskStack::new();
|
||||
|
||||
let domain_manager = domani::domain::manager::new(
|
||||
let domain_manager = domani::domain::manager::ManagerImpl::new(
|
||||
&mut task_stack,
|
||||
origin_store,
|
||||
domain_config_store,
|
||||
|
@ -42,7 +42,7 @@ pub enum AllDescrsError {
|
||||
|
||||
#[mockall::automock]
|
||||
/// Describes a storage mechanism for Origins. Each Origin is uniquely identified by its Descr.
|
||||
pub trait Store: Sync + Send {
|
||||
pub trait Store {
|
||||
/// If the origin is of a kind which can be updated, sync will pull down the latest version of
|
||||
/// the origin into the storage.
|
||||
fn sync(&self, descr: origin::Descr, limits: Limits) -> Result<(), SyncError>;
|
||||
|
Loading…
Reference in New Issue
Block a user