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")] #[command(about = "A domiply to another dimension")]
struct Cli { struct Cli {
#[arg(long, required = true, env = "DOMIPLY_HTTP_DOMAIN")] #[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")] #[arg(long, default_value_t = SocketAddr::from_str("[::]:3030").unwrap(), env = "DOMIPLY_HTTP_LISTEN_ADDR")]
http_listen_addr: SocketAddr, http_listen_addr: SocketAddr,
@ -185,7 +185,11 @@ fn main() {
tokio_runtime.spawn(async move { tokio_runtime.spawn(async move {
let addr = config.http_listen_addr; 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 server = hyper::Server::bind(&addr).serve(make_service);
let graceful = server.with_graceful_shutdown(async { 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 // 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. // the http domain for domiply itself has a valid certificate.
if let Some(domain_acme_manager) = domain_acme_manager { if let Some(domain_acme_manager) = domain_acme_manager {
let domain = domiply::domain::Name::from_str(&config.http_domain) let http_domain = config.http_domain.clone();
.expect("--http-domain parses as a domain");
wait_group.push(tokio_runtime.spawn(async move { wait_group.push(tokio_runtime.spawn(async move {
_ = domain_acme_manager _ = domain_acme_manager
.sync_domain(domain.clone()) .sync_domain(http_domain.clone())
.await .await
.inspect_err(|err| { .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, domain_manager: DomainManager,
target_a: net::Ipv4Addr, target_a: net::Ipv4Addr,
passphrase: String, passphrase: String,
http_domain: String, http_domain: domain::Name,
handlebars: handlebars::Handlebars<'svc>, handlebars: handlebars::Handlebars<'svc>,
} }
@ -31,7 +31,7 @@ pub fn new<'svc, DomainManager>(
domain_manager: DomainManager, domain_manager: DomainManager,
target_a: net::Ipv4Addr, target_a: net::Ipv4Addr,
passphrase: String, passphrase: String,
http_domain: String, http_domain: domain::Name,
) -> Service<'svc, DomainManager> ) -> Service<'svc, DomainManager>
where where
DomainManager: domain::manager::BoxedManager, DomainManager: domain::manager::BoxedManager,
@ -324,8 +324,8 @@ where
.map(strip_port), .map(strip_port),
req.uri().host().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.as_str() => Some(h),
(_, Some(h)) if h != svc.http_domain => Some(h), (_, Some(h)) if h != svc.http_domain.as_str() => Some(h),
_ => None, _ => None,
} }
.and_then(|h| domain::Name::from_str(h).ok()); .and_then(|h| domain::Name::from_str(h).ok());