Removed usage of sync::Arc where possible
This commit is contained in:
parent
289a185d42
commit
505015a4bd
@ -25,14 +25,14 @@ pub trait Manager: Sync + Send {
|
||||
}
|
||||
|
||||
struct ManagerImpl {
|
||||
store: sync::Arc<dyn acme::store::Store>,
|
||||
store: Box<dyn acme::store::Store>,
|
||||
account: sync::Arc<acme2::Account>,
|
||||
}
|
||||
|
||||
pub async fn new(
|
||||
store: sync::Arc<dyn acme::store::Store>,
|
||||
store: Box<dyn acme::store::Store>,
|
||||
contact_email: &str,
|
||||
) -> Result<sync::Arc<dyn Manager>, unexpected::Error> {
|
||||
) -> Result<Box<dyn Manager>, unexpected::Error> {
|
||||
let dir = acme2::DirectoryBuilder::new(LETS_ENCRYPT_URL.to_string())
|
||||
.build()
|
||||
.await
|
||||
@ -61,6 +61,7 @@ pub async fn new(
|
||||
.build()
|
||||
.await
|
||||
.or_unexpected_while("building account")?;
|
||||
|
||||
let account_key: acme::PrivateKey = account
|
||||
.private_key()
|
||||
.as_ref()
|
||||
@ -71,7 +72,7 @@ pub async fn new(
|
||||
.set_account_key(&account_key)
|
||||
.or_unexpected_while("storing account key")?;
|
||||
|
||||
Ok(sync::Arc::new(ManagerImpl { store, account }))
|
||||
Ok(Box::new(ManagerImpl { store, account }))
|
||||
}
|
||||
|
||||
impl Manager for ManagerImpl {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::io::{Read, Write};
|
||||
use std::str::FromStr;
|
||||
use std::{fs, path, sync};
|
||||
use std::{fs, path};
|
||||
|
||||
use crate::domain::acme::{Certificate, PrivateKey};
|
||||
use crate::error::unexpected::{self, Mappable};
|
||||
@ -70,7 +70,7 @@ struct FSStore {
|
||||
dir_path: path::PathBuf,
|
||||
}
|
||||
|
||||
pub fn new(dir_path: &path::Path) -> Result<sync::Arc<dyn Store>, unexpected::Error> {
|
||||
pub fn new(dir_path: &path::Path) -> Result<Box<dyn Store>, unexpected::Error> {
|
||||
vec![
|
||||
dir_path,
|
||||
dir_path.join("http01_challenge_keys").as_ref(),
|
||||
@ -82,7 +82,7 @@ pub fn new(dir_path: &path::Path) -> Result<sync::Arc<dyn Store>, unexpected::Er
|
||||
})
|
||||
.try_collect()?;
|
||||
|
||||
Ok(sync::Arc::new(FSStore {
|
||||
Ok(Box::new(FSStore {
|
||||
dir_path: dir_path.into(),
|
||||
}))
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::{fs, io, sync};
|
||||
use std::{fs, io};
|
||||
|
||||
use crate::error::unexpected::{self, Intoable, Mappable};
|
||||
use crate::{domain, origin};
|
||||
@ -49,9 +49,9 @@ struct FSStore {
|
||||
dir_path: PathBuf,
|
||||
}
|
||||
|
||||
pub fn new(dir_path: &Path) -> io::Result<sync::Arc<dyn Store>> {
|
||||
pub fn new(dir_path: &Path) -> io::Result<Box<dyn Store>> {
|
||||
fs::create_dir_all(dir_path)?;
|
||||
Ok(sync::Arc::new(FSStore {
|
||||
Ok(Box::new(FSStore {
|
||||
dir_path: dir_path.into(),
|
||||
}))
|
||||
}
|
||||
|
@ -147,9 +147,9 @@ pub trait Manager: Sync + Send + rustls::server::ResolvesServerCert {
|
||||
|
||||
struct ManagerImpl {
|
||||
origin_store: Box<dyn origin::store::Store>,
|
||||
domain_config_store: sync::Arc<dyn config::Store>,
|
||||
domain_config_store: Box<dyn config::Store>,
|
||||
domain_checker: checker::DNSChecker,
|
||||
acme_manager: Option<sync::Arc<dyn acme::manager::Manager>>,
|
||||
acme_manager: Option<Box<dyn acme::manager::Manager>>,
|
||||
}
|
||||
|
||||
async fn sync_origins(origin_store: &dyn origin::store::Store, canceller: CancellationToken) {
|
||||
@ -180,9 +180,9 @@ async fn sync_origins(origin_store: &dyn origin::store::Store, canceller: Cancel
|
||||
pub fn new(
|
||||
task_stack: &mut util::TaskStack<unexpected::Error>,
|
||||
origin_store: Box<dyn origin::store::Store>,
|
||||
domain_config_store: sync::Arc<dyn config::Store>,
|
||||
domain_config_store: Box<dyn config::Store>,
|
||||
domain_checker: checker::DNSChecker,
|
||||
acme_manager: Option<sync::Arc<dyn acme::manager::Manager>>,
|
||||
acme_manager: Option<Box<dyn acme::manager::Manager>>,
|
||||
) -> sync::Arc<dyn Manager> {
|
||||
let manager = sync::Arc::new(ManagerImpl {
|
||||
origin_store,
|
||||
|
32
src/main.rs
32
src/main.rs
@ -5,8 +5,8 @@ use futures::stream::StreamExt;
|
||||
use signal_hook_tokio::Signals;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
use std::path;
|
||||
use std::str::FromStr;
|
||||
use std::{path, sync};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version)]
|
||||
@ -60,12 +60,6 @@ struct Cli {
|
||||
domain_acme_contact_email: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct HTTPSParams {
|
||||
https_listen_addr: SocketAddr,
|
||||
domain_acme_manager: sync::Arc<dyn domiply::domain::acme::manager::Manager>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let config = Cli::parse();
|
||||
@ -92,7 +86,7 @@ async fn main() {
|
||||
let domain_config_store = domiply::domain::config::new(&config.domain_config_store_dir_path)
|
||||
.expect("domain config store initialization failed");
|
||||
|
||||
let https_params = if let Some(https_listen_addr) = config.https_listen_addr {
|
||||
let domain_acme_manager = if config.https_listen_addr.is_some() {
|
||||
let domain_acme_store_dir_path = config.domain_acme_store_dir_path.unwrap();
|
||||
|
||||
let domain_acme_store = domiply::domain::acme::store::new(&domain_acme_store_dir_path)
|
||||
@ -102,15 +96,11 @@ async fn main() {
|
||||
// settings.
|
||||
let domain_acme_contact_email = config.domain_acme_contact_email.unwrap();
|
||||
|
||||
let domain_acme_manager =
|
||||
Some(
|
||||
domiply::domain::acme::manager::new(domain_acme_store, &domain_acme_contact_email)
|
||||
.await
|
||||
.expect("domain acme manager initialization failed");
|
||||
|
||||
Some(HTTPSParams {
|
||||
https_listen_addr,
|
||||
domain_acme_manager,
|
||||
})
|
||||
.expect("domain acme manager initialization failed"),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@ -122,7 +112,7 @@ async fn main() {
|
||||
origin_store,
|
||||
domain_config_store,
|
||||
domain_checker,
|
||||
https_params.as_ref().map(|p| p.domain_acme_manager.clone()),
|
||||
domain_acme_manager,
|
||||
);
|
||||
|
||||
let _ = domiply::service::http::new(
|
||||
@ -132,10 +122,12 @@ async fn main() {
|
||||
config.passphrase,
|
||||
config.http_listen_addr.clone(),
|
||||
config.http_domain.clone(),
|
||||
https_params.map(|p| domiply::service::http::HTTPSParams {
|
||||
listen_addr: p.https_listen_addr,
|
||||
cert_resolver: domain_manager.clone(),
|
||||
}),
|
||||
config
|
||||
.https_listen_addr
|
||||
.map(|listen_addr| domiply::service::http::HTTPSParams {
|
||||
listen_addr,
|
||||
cert_resolver: domain_manager.clone(),
|
||||
}),
|
||||
);
|
||||
|
||||
let mut signals =
|
||||
|
Loading…
Reference in New Issue
Block a user