Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
moubctez committed Aug 12, 2024
1 parent 7da819e commit b2c7ec3
Show file tree
Hide file tree
Showing 8 changed files with 474 additions and 610 deletions.
1,021 changes: 441 additions & 580 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/DefGuard/proxy"
[dependencies]
# base `axum` deps
axum = { version = "0.7", features = ["macros", "tracing"] }
axum-client-ip = "0.5"
axum-client-ip = "0.6"
axum-extra = { version = "0.9", features = [
"cookie",
"cookie-private",
Expand All @@ -29,24 +29,24 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
toml = { version = "0.8", default-features = false, features = ["parse"] }
# gRPC
tonic = { version = "0.10", features = ["gzip", "tls", "tls-roots"] }
prost = "0.12"
tonic = { version = "0.12", features = ["gzip", "tls", "tls-roots"] }
prost = "0.13"
# error handling
thiserror = "1.0"
anyhow = "1.0"
# CLI
clap = { version = "4.4", features = ["derive", "env", "cargo"] }
clap = { version = "4.5", features = ["derive", "env", "cargo"] }
# other utils
dotenvy = "0.15"
url = "2.4"
url = "2.5"
tower_governor = "0.4"
# UI embedding
rust-embed = { version = "8.4", features = ["include-exclude"] }
rust-embed = { version = "8.5", features = ["include-exclude"] }
mime_guess = "2.0"

[build-dependencies]
tonic-build = { version = "0.10" }
prost-build = { version = "0.12" }
tonic-build = { version = "0.12" }
prost-build = { version = "0.13" }

[profile.release]
lto = "thin"
Expand Down
2 changes: 0 additions & 2 deletions rust-toolchain.toml

This file was deleted.

5 changes: 3 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{fs, io::Error as IoError};

use clap::Parser;
use log::LevelFilter;
use serde::Deserialize;
use std::{fs, io::Error as IoError};
use tracing::info;
use tracing::log::LevelFilter;

#[derive(Parser, Debug, Deserialize)]
#[command(version)]
Expand Down
20 changes: 11 additions & 9 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ fn get_client_addr(request: &Request<Body>) -> String {
.get("X-Forwarded-For")
.and_then(|h| h.to_str().ok())
.and_then(|h| h.split(',').next())
.map(|ip| ip.trim().to_string())
.unwrap_or_else(|| {
request
.extensions()
.get::<ConnectInfo<SocketAddr>>()
.map_or("unknown".to_string(), |addr| addr.0.to_string())
})
.map_or_else(
|| {
request
.extensions()
.get::<ConnectInfo<SocketAddr>>()
.map_or("unknown".to_string(), |addr| addr.0.to_string())
},
|ip| ip.trim().to_string(),
)
}

pub async fn run_server(config: Config) -> anyhow::Result<()> {
Expand All @@ -110,7 +112,7 @@ pub async fn run_server(config: Config) -> anyhow::Result<()> {
};

// read gRPC TLS cert and key
debug!("Configuring grpc certificates");
debug!("Configuring certificates for gRPC");
let grpc_cert = config
.grpc_cert
.as_ref()
Expand All @@ -119,7 +121,7 @@ pub async fn run_server(config: Config) -> anyhow::Result<()> {
.grpc_key
.as_ref()
.and_then(|path| read_to_string(path).ok());
debug!("Configured grpc certificates, cert: {grpc_cert:?}, key: {grpc_key:?}");
debug!("Configured certificates for gRPC, cert: {grpc_cert:?}");

// Start gRPC server.
debug!("Spawning gRPC server");
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ mod error;
mod grpc;
mod handlers;
pub mod http;
pub mod tracing;
pub mod logging;

pub(crate) mod proto {
tonic::include_proto!("defguard.proxy");
}

#[macro_use]
extern crate tracing as rust_tracing;
extern crate tracing;
14 changes: 8 additions & 6 deletions src/tracing.rs → src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use rust_tracing::{Event, Subscriber};
use log::LevelFilter;
use tracing::{Event, Subscriber};
use tracing_subscriber::{
fmt::{
self,
format::{self, FormatEvent, FormatFields, Writer},
time::{FormatTime, SystemTime},
FmtContext, FormattedFields,
},
layer::SubscriberExt,
registry::LookupSpan,
util::SubscriberInitExt,
EnvFilter,
};

use tracing::log::LevelFilter;
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

// Initializes tracing with the specified log level.
// Allows fine-grained filtering with `EnvFilter` directives.
// The directives are read from `DEFGUARD_PROXY_LOG_FILTER` env variable.
Expand Down Expand Up @@ -71,7 +73,7 @@ where
write!(writer, "{}: ", meta.target(),)?;

// iterate and accumulate spans storing our special span in separate variable if encountered
let mut context_logs: String = "".to_string();
let mut context_logs = String::new();
let mut http_log: Option<String> = None;
if let Some(scope) = ctx.event_scope() {
let mut seen = false;
Expand Down Expand Up @@ -103,7 +105,7 @@ where

let addr = split.get(5).map(|s| s.replace('"', ""));
let ip = addr
.and_then(|s| s.split(':').next().map(|s| s.to_string()))
.and_then(|s| s.split(':').next().map(ToString::to_string))
.unwrap_or("unknown".to_string());
write!(writer, "{ip} {method} {path} ")?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use defguard_proxy::{config::get_config, http::run_server, tracing::init_tracing};
use defguard_proxy::{config::get_config, http::run_server, logging::init_tracing};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down

0 comments on commit b2c7ec3

Please sign in to comment.