change http_domain into a domain::Name

This commit is contained in:
Brian Picciano 2023-05-19 12:36:01 +02:00
parent 4cd5234519
commit 5b26396106
2 changed files with 16 additions and 10 deletions

View File

@ -21,7 +21,7 @@ use domiply::domain::manager::Manager;
#[command(about = "A domiply to another dimension")]
struct Cli {
#[arg(long, required = true, env = "DOMIPLY_HTTP_DOMAIN")]
http_domain: String,
http_domain: domiply::domain::Name,
#[arg(long, default_value_t = SocketAddr::from_str("[::]:3030").unwrap(), env = "DOMIPLY_HTTP_LISTEN_ADDR")]
http_listen_addr: SocketAddr,
@ -185,7 +185,11 @@ fn main() {
tokio_runtime.spawn(async move {
let addr = config.http_listen_addr;
println!("Listening on http://{}:{}", http_domain, addr.port());
println!(
"Listening on http://{}:{}",
http_domain.as_str(),
addr.port()
);
let server = hyper::Server::bind(&addr).serve(make_service);
let graceful = server.with_graceful_shutdown(async {
@ -201,15 +205,17 @@ fn main() {
// if there's an acme manager then it means that https is enabled, and we should ensure that
// the http domain for domiply itself has a valid certificate.
if let Some(domain_acme_manager) = domain_acme_manager {
let domain = domiply::domain::Name::from_str(&config.http_domain)
.expect("--http-domain parses as a domain");
let http_domain = config.http_domain.clone();
wait_group.push(tokio_runtime.spawn(async move {
_ = domain_acme_manager
.sync_domain(domain.clone())
.sync_domain(http_domain.clone())
.await
.inspect_err(|err| {
panic!("Error while getting cert for {}: {err}", domain.as_str())
println!(
"Error while getting cert for {}: {err}",
http_domain.as_str()
)
});
}));
}

View File

@ -23,7 +23,7 @@ where
domain_manager: DomainManager,
target_a: net::Ipv4Addr,
passphrase: String,
http_domain: String,
http_domain: domain::Name,
handlebars: handlebars::Handlebars<'svc>,
}
@ -31,7 +31,7 @@ pub fn new<'svc, DomainManager>(
domain_manager: DomainManager,
target_a: net::Ipv4Addr,
passphrase: String,
http_domain: String,
http_domain: domain::Name,
) -> Service<'svc, DomainManager>
where
DomainManager: domain::manager::BoxedManager,
@ -324,8 +324,8 @@ where
.map(strip_port),
req.uri().host().map(strip_port),
) {
(Some(h), _) if h != svc.http_domain => Some(h),
(_, Some(h)) if h != svc.http_domain => Some(h),
(Some(h), _) if h != svc.http_domain.as_str() => Some(h),
(_, Some(h)) if h != svc.http_domain.as_str() => Some(h),
_ => None,
}
.and_then(|h| domain::Name::from_str(h).ok());