Skip to content

dev: extract tls optional before blocking thread #1429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/axum-http-tracker-server/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ impl Environment<Stopped> {

let bind_to = container.http_tracker_core_container.http_tracker_config.bind_address;

let tls = block_on(make_rust_tls(
&container.http_tracker_core_container.http_tracker_config.tsl_config,
))
.map(|tls| tls.expect("tls config failed"));
let tls = if let Some(tls_config) = &container.http_tracker_core_container.http_tracker_config.tsl_config {
block_on(make_rust_tls(tls_config)).map(|tls| tls.expect("tls config failed"))
} else {
None
};

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

Expand Down
41 changes: 18 additions & 23 deletions packages/axum-server/src/tsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,27 @@ pub enum Error {
},
}

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

if !cert.exists() || !key.exists() {
return Some(Err(Error::MissingTlsConfig {
location: Location::caller(),
}));
}
if !cert.exists() || !key.exists() {
return Some(Err(Error::MissingTlsConfig {
location: Location::caller(),
}));
}

tracing::info!("Using https: cert path: {cert}.");
tracing::info!("Using https: key path: {key}.");
tracing::info!("Using https: cert path: {cert}.");
tracing::info!("Using https: key path: {key}.");

Some(
RustlsConfig::from_pem_file(cert, key)
.await
.map_err(|err| Error::BadTlsConfig {
source: (Arc::new(err) as DynError).into(),
}),
)
}
None => None,
}
Some(
RustlsConfig::from_pem_file(cert, key)
.await
.map_err(|err| Error::BadTlsConfig {
source: (Arc::new(err) as DynError).into(),
}),
)
}

#[cfg(test)]
Expand Down
Loading