Skip to content

Commit 2c03271

Browse files
committed
dev: extract tls optional before blocking thread
1 parent 326e577 commit 2c03271

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

packages/axum-http-tracker-server/src/environment.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ impl Environment<Stopped> {
4343

4444
let bind_to = container.http_tracker_core_container.http_tracker_config.bind_address;
4545

46-
let tls = block_on(make_rust_tls(
47-
&container.http_tracker_core_container.http_tracker_config.tsl_config,
48-
))
49-
.map(|tls| tls.expect("tls config failed"));
46+
let tls = if let Some(tls_config) = &container.http_tracker_core_container.http_tracker_config.tsl_config {
47+
block_on(make_rust_tls(tls_config)).map(|tls| tls.expect("tls config failed"))
48+
} else {
49+
None
50+
};
5051

5152
let server = HttpServer::new(Launcher::new(bind_to, tls));
5253

packages/axum-server/src/tsl.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,27 @@ pub enum Error {
2121
},
2222
}
2323

24-
#[instrument(skip(opt_tsl_config))]
25-
pub async fn make_rust_tls(opt_tsl_config: &Option<TslConfig>) -> Option<Result<RustlsConfig, Error>> {
26-
match opt_tsl_config {
27-
Some(tsl_config) => {
28-
let cert = tsl_config.ssl_cert_path.clone();
29-
let key = tsl_config.ssl_key_path.clone();
24+
#[instrument(skip(tsl_config))]
25+
pub async fn make_rust_tls(tsl_config: &TslConfig) -> Option<Result<RustlsConfig, Error>> {
26+
let cert = tsl_config.ssl_cert_path.clone();
27+
let key = tsl_config.ssl_key_path.clone();
3028

31-
if !cert.exists() || !key.exists() {
32-
return Some(Err(Error::MissingTlsConfig {
33-
location: Location::caller(),
34-
}));
35-
}
29+
if !cert.exists() || !key.exists() {
30+
return Some(Err(Error::MissingTlsConfig {
31+
location: Location::caller(),
32+
}));
33+
}
3634

37-
tracing::info!("Using https: cert path: {cert}.");
38-
tracing::info!("Using https: key path: {key}.");
35+
tracing::info!("Using https: cert path: {cert}.");
36+
tracing::info!("Using https: key path: {key}.");
3937

40-
Some(
41-
RustlsConfig::from_pem_file(cert, key)
42-
.await
43-
.map_err(|err| Error::BadTlsConfig {
44-
source: (Arc::new(err) as DynError).into(),
45-
}),
46-
)
47-
}
48-
None => None,
49-
}
38+
Some(
39+
RustlsConfig::from_pem_file(cert, key)
40+
.await
41+
.map_err(|err| Error::BadTlsConfig {
42+
source: (Arc::new(err) as DynError).into(),
43+
}),
44+
)
5045
}
5146

5247
#[cfg(test)]

0 commit comments

Comments
 (0)