alpha
Login
or
Join now
pds.dad
/
pds-gatekeeper
Star
0
Fork
3
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Microservice to bring 2FA to self hosted PDSes
Star
0
Fork
3
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
light changes to logging changes
author
Bailey Townsend
committer
tangled.org
date
3 months ago
(Mar 3, 2026, 5:17 AM UTC)
commit
9605d15d
9605d15d67317eb0965e484c14a6eeb59624e4a6
parent
70f45371
70f453718a1453a35acfc4b0fcc966948676bc6a
+40
-35
3 changed files
Expand all
Collapse all
Unified
Split
Cargo.lock
Cargo.toml
src
main.rs
+1
Cargo.lock
Reviewed
···
2812
2812
"tracing-subscriber",
2813
2813
"url",
2814
2814
"urlencoding",
2815
2815
+
"valuable",
2815
2816
]
2816
2817
2817
2818
[[package]]
+3
-2
Cargo.toml
Reviewed
···
11
11
dotenvy = "0.15.7"
12
12
serde = { version = "1.0", features = ["derive"] }
13
13
serde_json = "1.0"
14
14
-
tracing = "0.1"
15
15
-
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json"] }
14
14
+
tracing = { version = "0.1.44" }
15
15
+
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json", "serde", ] }
16
16
hyper-util = { version = "0.1.19", features = ["client", "client-legacy"] }
17
17
tower-http = { version = "0.6", features = ["cors", "compression-zstd", "trace"] }
18
18
tower_governor = { version = "0.8.0", features = ["axum", "tracing"] }
···
40
40
josekit = "0.10.3"
41
41
dashmap = "6.1"
42
42
tower = "0.5"
43
43
+
valuable = "0.1.1"
+36
-33
src/main.rs
Reviewed
···
31
31
use tower_governor::{
32
32
GovernorLayer, governor::GovernorConfigBuilder, key_extractor::SmartIpKeyExtractor,
33
33
};
34
34
+
use tower_http::cors::AllowHeaders;
35
35
+
use tower_http::trace::{DefaultOnRequest, HttpMakeClassifier};
34
36
use tower_http::{
35
37
compression::CompressionLayer,
36
38
cors::{Any, CorsLayer},
37
39
trace::TraceLayer,
38
40
};
39
39
-
use tracing::log;
41
41
+
use tracing::{Span, log};
40
42
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
41
43
42
44
mod auth;
···
200
202
201
203
#[tokio::main]
202
204
async fn main() -> Result<(), Box<dyn std::error::Error>> {
203
203
-
setup_tracing();
204
205
let pds_env_location =
205
206
env::var("PDS_ENV_LOCATION").unwrap_or_else(|_| "/pds/pds.env".to_string());
206
207
···
210
211
"Error loading pds.env file (ignore if you loaded your variables in the environment somehow else): {e}"
211
212
);
212
213
}
214
214
+
// Sets up after the pds.env file is loaded
215
215
+
setup_tracing();
213
216
214
217
let pds_root =
215
218
env::var("PDS_DATA_DIRECTORY").expect("PDS_DATA_DIRECTORY is not set in your pds.env file");
···
390
393
.map(|v| v.eq_ignore_ascii_case("true") || v == "1")
391
394
.unwrap_or(false);
392
395
393
393
-
let app = if request_logging {
394
394
-
app.layer(TraceLayer::new_for_http()
395
395
-
.make_span_with(|req: &axum::http::Request<Body>| {
396
396
-
let headers: std::collections::HashMap<&str, Vec<&str>> = req.headers()
397
397
-
.keys()
398
398
-
.map(|k| {
399
399
-
let vals: Vec<&str> = req.headers()
400
400
-
.get_all(k)
401
401
-
.iter()
402
402
-
.filter_map(|v| v.to_str().ok())
403
403
-
.collect();
404
404
-
(k.as_str(), vals)
405
405
-
})
406
406
-
.collect();
407
407
-
let headers_json = serde_json::to_string(&headers).unwrap_or_default();
396
396
+
if request_logging {
397
397
+
app = app.layer(request_trace_layer());
398
398
+
}
408
399
409
409
-
tracing::info_span!("request",
410
410
-
method = %req.method(),
411
411
-
path = %req.uri().path(),
412
412
-
headers = %headers_json,
413
413
-
)
414
414
-
})
415
415
-
.on_response(|resp: &axum::http::Response<Body>, latency: Duration, _span: &tracing::Span| {
416
416
-
tracing::info!(status = resp.status().as_u16(), latency_ms = latency.as_millis() as u64, "response");
417
417
-
})
418
418
-
)
400
400
+
let app = app
419
401
.layer(CompressionLayer::new())
420
402
.layer(cors)
421
421
-
.with_state(state)
422
422
-
} else {
423
423
-
app.layer(CompressionLayer::new())
424
424
-
.layer(cors)
425
425
-
.with_state(state)
426
426
-
};
403
403
+
.with_state(state);
427
404
428
405
let host = env::var("GATEKEEPER_HOST").unwrap_or_else(|_| "0.0.0.0".to_string());
429
406
let port: u16 = env::var("GATEKEEPER_PORT")
···
493
470
_ = terminate => {},
494
471
}
495
472
}
473
473
+
474
474
+
fn request_trace_layer() -> TraceLayer<
475
475
+
HttpMakeClassifier,
476
476
+
impl Fn(&axum::http::Request<Body>) -> Span + Clone,
477
477
+
DefaultOnRequest,
478
478
+
impl Fn(&axum::http::Response<Body>, Duration, &Span) + Clone,
479
479
+
> {
480
480
+
TraceLayer::new_for_http()
481
481
+
.make_span_with(|req: &axum::http::Request<Body>| {
482
482
+
let headers = req.headers();
483
483
+
tracing::info_span!("request",
484
484
+
method = %req.method(),
485
485
+
path = %req.uri().path(),
486
486
+
headers = %format!("{:?}", headers),
487
487
+
)
488
488
+
})
489
489
+
.on_response(
490
490
+
|resp: &axum::http::Response<Body>, latency: Duration, _span: &tracing::Span| {
491
491
+
tracing::info!(
492
492
+
status = resp.status().as_u16(),
493
493
+
latency_ms = latency.as_millis() as u64,
494
494
+
"response"
495
495
+
);
496
496
+
},
497
497
+
)
498
498
+
}