Skip to content

Commit

Permalink
Fix: remove certs folder & refactor startup.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
raghuvar-vijay committed Jan 20, 2025
1 parent 5044142 commit 447a888
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 114 deletions.
21 changes: 0 additions & 21 deletions auditor/certs/certs/cert.pem

This file was deleted.

28 changes: 0 additions & 28 deletions auditor/certs/certs/key.pem

This file was deleted.

98 changes: 36 additions & 62 deletions auditor/src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,72 +30,46 @@ pub fn run(

let db_pool = web::Data::new(db_pool);

let server = match tls_params {
let app_config = move || {
App::new()
// Logging middleware
.wrap(TracingLogger::default())
.wrap(RequestMetrics::default())
.route(
"/metrics",
web::get().to(PrometheusMetricsHandler::new(
request_metrics.prom_registry.clone(),
)),
)
// Routes
.route("/health_check", web::get().to(health_check))
.service(
web::resource("/record")
.route(web::post().to(add))
.route(web::put().to(update)),
)
.route("/record/{record_id}", web::get().to(query_one_record))
// DB connection pool
.service(
web::resource("/records")
.route(web::post().to(bulk_add))
.route(web::get().to(query_records)),
)
.app_data(db_pool.clone())
};

let server = HttpServer::new(app_config).listen(listener)?;

match tls_params {
Some(params) if params.use_tls => {
println!("********* AUDITOR running in TLS mode *********");
HttpServer::new(move || {
App::new()
// Logging middleware
.wrap(TracingLogger::default())
.wrap(RequestMetrics::default())
.route(
"/metrics",
web::get().to(PrometheusMetricsHandler::new(
request_metrics.prom_registry.clone(),
)),
)
// Routes
.route("/health_check", web::get().to(health_check))
.service(
web::resource("/record")
.route(web::post().to(add))
.route(web::put().to(update)),
)
.route("/record/{record_id}", web::get().to(query_one_record))
// DB connection pool
.service(
web::resource("/records")
.route(web::post().to(bulk_add))
.route(web::get().to(query_records)),
)
.app_data(db_pool.clone())
})
.listen(listener)?
.bind_rustls_0_23((params.https_addr, params.https_port), params.config)?
.run()
Ok(server
.bind_rustls_0_23((params.https_addr, params.https_port), params.config)?
.run())
}
_ => {
println!("********* AUDITOR running without TLS *********");
HttpServer::new(move || {
App::new()
// Logging middleware
.wrap(TracingLogger::default())
.wrap(RequestMetrics::default())
.route(
"/metrics",
web::get().to(PrometheusMetricsHandler::new(
request_metrics.prom_registry.clone(),
)),
)
// Routes
.route("/health_check", web::get().to(health_check))
.service(
web::resource("/record")
.route(web::post().to(add))
.route(web::put().to(update)),
)
.route("/record/{record_id}", web::get().to(query_one_record))
// DB connection pool
.service(
web::resource("/records")
.route(web::post().to(bulk_add))
.route(web::get().to(query_records)),
)
.app_data(db_pool.clone())
})
.listen(listener)?
.run()
Ok(server.run())
}
};
Ok(server)
}
}
2 changes: 1 addition & 1 deletion media/website/content/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ weight = 3

### New feature - TLS

TLS is added to AUDITOR, all collectors and plugins. A new config section called tls_config is required by all config files. `use-tls` is a compulsory field of type bool that defines whether to use the TLS or not.
TLS is added to AUDITOR, all collectors and plugins. A new config section called tls_config is required by all config files. `use_tls` is a compulsory field of type bool that defines whether to use the TLS or not.

## TLS Configuration Table for AUDITOR (AUDITOR is referred to as the server)

Expand Down
2 changes: 1 addition & 1 deletion pyauditor/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"License :: OSI Approved :: Apache Software License",
]

version = "0.1.0"
2 changes: 1 addition & 1 deletion scripts/test_mtls.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
#!/usr/bin/env bash

set -x
set -eo pipefail

Expand Down

0 comments on commit 447a888

Please sign in to comment.