Add authentication layer
This commit is contained in:
2
central_backend/src/server/unsecure_server/mod.rs
Normal file
2
central_backend/src/server/unsecure_server/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod unsecure_pki_controller;
|
||||
pub mod unsecure_server_controller;
|
@ -0,0 +1,32 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
#[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(".pem") {
|
||||
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!"))
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
use actix_web::HttpResponse;
|
||||
|
||||
pub async fn unsecure_home() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/plain")
|
||||
.body("SolarEnergy unsecure central backend")
|
||||
}
|
Reference in New Issue
Block a user