Skip to content

Commit

Permalink
secure_utils: migrate to tracing_slog_compat
Browse files Browse the repository at this point in the history
Summary:
We are migrating from `slog` to `tracing`.
Modify the `rust/shed/secure_utils` crate to accept `tracing_slog_compat` instances of `Logger`, as well as regular `slog::Logger` instances.

Differential Revision: D68857142

fbshipit-source-id: 18e01e31853812a0a6c64a1664e150b06baf5d9d
  • Loading branch information
lmvasquezg authored and facebook-github-bot committed Jan 31, 2025
1 parent 84a517a commit 15d4715
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions shed/secure_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ openssl-sys = "0.9.99"
serde = { version = "1.0.185", features = ["derive", "rc"] }
serde_json = { version = "1.0.132", features = ["float_roundtrip", "unbounded_depth"] }
slog = { version = "2.7", features = ["max_level_trace", "nested-values"] }
tracing_slog_compat = { version = "0.1.0", path = "../tracing_slog_compat" }

[lints]
rust = { unexpected_cfgs = { check-cfg = ["cfg(fbcode_build)"], level = "warn" } }
20 changes: 18 additions & 2 deletions shed/secure_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use openssl::ssl::SslAcceptorBuilder;
use openssl::ssl::SslMethod;
use openssl::ssl::SslVerifyMode;
use openssl::x509::X509;
use slog::Logger;

/// Certificates for the TLS acceptor
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -60,7 +59,7 @@ impl SslConfig {
}

/// Builds the tls acceptor
pub fn build_tls_acceptor(self, logger: Logger) -> Result<SslAcceptor> {
pub fn build_tls_acceptor(self, logger: impl IntoLogger) -> Result<SslAcceptor> {
Ok(self.tls_acceptor_builder(logger)?.build())
}

Expand Down Expand Up @@ -134,3 +133,20 @@ fn read_bytes<T: AsRef<Path>>(path: T) -> Result<Vec<u8>> {
})()
.with_context(|| format!("While reading file {}", path.display()))
}

#[doc(hidden)]
pub trait IntoLogger {
fn into_logger(self) -> tracing_slog_compat::Logger;
}

impl IntoLogger for slog::Logger {
fn into_logger(self) -> tracing_slog_compat::Logger {
tracing_slog_compat::Logger::Slog(self)
}
}

impl IntoLogger for tracing_slog_compat::Logger {
fn into_logger(self) -> tracing_slog_compat::Logger {
self
}
}
4 changes: 2 additions & 2 deletions shed/secure_utils/src/oss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

use anyhow::Result;
use openssl::ssl::SslAcceptorBuilder;
use slog::Logger;

use crate::IntoLogger;
use crate::SslConfig;

impl SslConfig {
/// Creates the tls acceptor builder
pub fn tls_acceptor_builder(self, _: Logger) -> Result<SslAcceptorBuilder> {
pub fn tls_acceptor_builder(self, _: impl IntoLogger) -> Result<SslAcceptorBuilder> {
self.inner_tls_acceptor_builder()
}
}

0 comments on commit 15d4715

Please sign in to comment.