Files
SolarEnergy/central_backend/src/server/unsecure_server/unsecure_pki_controller.rs
Pierre HUBERT 665a04c8a0
All checks were successful
continuous-integration/drone/push Build is passing
Update backend code to Rust Edition 2024
2025-03-28 19:25:15 +01:00

33 lines
903 B
Rust

use crate::app_config::AppConfig;
use crate::server::custom_error::HttpResult;
use actix_web::{HttpResponse, web};
#[derive(serde::Deserialize)]
pub struct ServeCRLPath {
file: String,
}
/// Serve PKI files (unsecure server)
pub async fn serve_pki_file(path: web::Path<ServeCRLPath>) -> HttpResult {
for f in std::fs::read_dir(AppConfig::get().pki_path())? {
let f = f?;
let file_name = f.file_name().to_string_lossy().to_string();
if !file_name.ends_with(".crl") && !file_name.ends_with(".crt") {
continue;
}
if file_name != path.file {
continue;
}
let crl = std::fs::read(f.path())?;
return Ok(HttpResponse::Ok()
.content_type("application/x-pem-file")
.body(crl));
}
Ok(HttpResponse::NotFound()
.content_type("text/plain")
.body("file not found!"))
}