Skip to content

Commit f60a368

Browse files
committed
Restore TLS reload for pre-bound API listener
1 parent 78bddda commit f60a368

File tree

6 files changed

+28
-22
lines changed

6 files changed

+28
-22
lines changed

benches/baselines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::hint::black_box;
22

3-
use criterion::{criterion_group, criterion_main, Criterion};
3+
use criterion::{Criterion, criterion_group, criterion_main};
44

55
fn fibonacci(n: u64) -> u64 {
66
match n {

src/db/migrations/m_20260203_zones_ids_uuid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl MigrationTrait for Migration {
142142
)
143143
.await?;
144144
db.execute_unprepared(
145-
"INSERT INTO records_new (id, zoneid, name, ttl, rrtype, rclass, rdata)
145+
"INSERT INTO records_new (id, zoneid, name, ttl, rrtype, rclass, rdata)
146146
SELECT record_id_map.new_id, zone_id_map.new_id, records.name, records.ttl,
147147
records.rrtype, records.rclass, records.rdata
148148
FROM records

src/resourcerecord.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ impl TryFrom<entities::records::Model> for InternalResourceRecord {
563563
}
564564
}
565565

566-
567566
impl TryFrom<entities::records_merged::Model> for InternalResourceRecord {
568567
type Error = GoatNsError;
569568
/// This is where we convert from the JSON blob in the file to an internal representation of the data.
@@ -781,7 +780,6 @@ impl TryFrom<entities::records_merged::Model> for InternalResourceRecord {
781780
}
782781
}
783782

784-
785783
impl PartialEq<RecordClass> for InternalResourceRecord {
786784
fn eq(&self, other: &RecordClass) -> bool {
787785
match self {

src/tests/e2e_test.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ mod tests {
113113

114114
// Construct a new Resolver pointing at localhost
115115
let mut resolver_config = ResolverConfig::new();
116-
resolver_config.add_name_server(NameServerConfig::new(
117-
dns_addr,
118-
Protocol::Udp,
119-
));
116+
resolver_config.add_name_server(NameServerConfig::new(dns_addr, Protocol::Udp));
120117
let resolver =
121118
Resolver::builder_with_config(resolver_config, TokioConnectionProvider::default())
122119
.build();

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::HEADER_BYTES;
12
use crate::enums::AgentState;
23
use crate::error::GoatNsError;
3-
use crate::HEADER_BYTES;
44
use crate::{datastore::Command, resourcerecord::NameAsBytes};
55
use std::cmp::min;
66
use std::str::from_utf8;

src/web/mod.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ pub async fn build(
255255
let listener_address = config.api_listener_address()?;
256256
let listener = std::net::TcpListener::bind(listener_address)
257257
.map_err(|err| GoatNsError::StartupError(format!("Failed to bind API listener: {err}")))?;
258-
listener
259-
.set_nonblocking(true)
260-
.map_err(|err| GoatNsError::StartupError(format!("Failed to set API listener nonblocking: {err}")))?;
258+
listener.set_nonblocking(true).map_err(|err| {
259+
GoatNsError::StartupError(format!("Failed to set API listener nonblocking: {err}"))
260+
})?;
261261
build_with_listener(tx, rx, config, connpool, listener).await
262262
}
263263

@@ -269,18 +269,20 @@ pub async fn build_with_listener(
269269
listener: std::net::TcpListener,
270270
) -> Result<JoinHandle<Result<(), std::io::Error>>, GoatNsError> {
271271
let router = build_router(tx, config.clone(), connpool).await?;
272-
let listener_address: SocketAddr = listener
273-
.local_addr()
274-
.map_err(|err| GoatNsError::StartupError(format!("Failed to inspect API listener: {err}")))?;
272+
let listener_address: SocketAddr = listener.local_addr().map_err(|err| {
273+
GoatNsError::StartupError(format!("Failed to inspect API listener: {err}"))
274+
})?;
275275
let hostname = config.hostname.clone();
276+
let tls_cert = config.api_tls_cert.clone();
277+
let tls_key = config.api_tls_key.clone();
278+
let tls_config = config
279+
.get_tls_config()
280+
.await
281+
.map_err(GoatNsError::StartupError)?;
276282
let mut rx = rx;
277283
let res: JoinHandle<Result<(), std::io::Error>> = tokio::spawn(async move {
278-
let tls_config = config
279-
.get_tls_config()
280-
.await
281-
.map_err(std::io::Error::other)?;
282284
let handle = axum_server::Handle::new();
283-
let server = axum_server::from_tcp_rustls(listener, tls_config)?
285+
let server = axum_server::from_tcp_rustls(listener, tls_config.clone())?
284286
.handle(handle.clone())
285287
.serve(router.into_make_service());
286288
tokio::pin!(server);
@@ -289,7 +291,14 @@ pub async fn build_with_listener(
289291
tokio::select! {
290292
Some(action) = rx.recv() => match action {
291293
ServerCommand::ReloadTls => {
292-
warn!("Ignoring TLS reload for pre-bound API listener");
294+
match tls_config.reload_from_pem_file(&tls_cert, &tls_key).await {
295+
Ok(()) => {
296+
info!("Reloaded TLS configuration for API listener.");
297+
}
298+
Err(err) => {
299+
error!("Failed to reload TLS configuration: {err}");
300+
}
301+
}
293302
}
294303
ServerCommand::ShutDown => {
295304
info!("Shutting down web server.");
@@ -308,7 +317,9 @@ pub async fn build_with_listener(
308317
});
309318
let startup_message = format!(
310319
"Started Web server on https://{} / https://{}:{}",
311-
listener_address, hostname, listener_address.port()
320+
listener_address,
321+
hostname,
322+
listener_address.port()
312323
);
313324

314325
#[cfg(test)]

0 commit comments

Comments
 (0)