Add basic server config

This commit is contained in:
Pierre HUBERT 2023-09-02 10:28:08 +02:00
parent 129d23f671
commit bb31954b22
7 changed files with 57 additions and 1 deletions

View File

@ -1856,6 +1856,7 @@ dependencies = [
"actix-web", "actix-web",
"clap", "clap",
"env_logger", "env_logger",
"futures-util",
"lazy_static", "lazy_static",
"light-openid", "light-openid",
"log", "log",

View File

@ -16,3 +16,4 @@ actix-remote-ip = "0.1.0"
actix-session = { version = "0.7.2", features = ["cookie-session"] } actix-session = { version = "0.7.2", features = ["cookie-session"] }
actix-identity = "0.5.2" actix-identity = "0.5.2"
serde = { version = "1.0.175", features = ["derive"] } serde = { version = "1.0.175", features = ["derive"] }
futures-util = "0.3.28"

View File

@ -1,5 +1,20 @@
use crate::app_config::AppConfig;
use crate::extractors::local_auth_extractor::LocalAuthEnabled;
use actix_web::{HttpResponse, Responder}; use actix_web::{HttpResponse, Responder};
pub async fn root_index() -> impl Responder { pub async fn root_index() -> impl Responder {
HttpResponse::Ok().body("Hello world!") HttpResponse::Ok().body("Hello world!")
} }
#[derive(serde::Serialize)]
struct StaticConfig {
local_auth_enabled: bool,
oidc_auth_enabled: bool,
}
pub async fn static_config(local_auth: LocalAuthEnabled) -> impl Responder {
HttpResponse::Ok().json(StaticConfig {
local_auth_enabled: *local_auth,
oidc_auth_enabled: !AppConfig::get().disable_oidc,
})
}

View File

@ -0,0 +1 @@
pub mod local_auth_extractor;

View File

@ -0,0 +1,33 @@
use crate::app_config::AppConfig;
use actix_web::dev::Payload;
use actix_web::{Error, FromRequest, HttpRequest};
use futures_util::future::{ready, Ready};
use std::ops::Deref;
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct LocalAuthEnabled(bool);
impl Deref for LocalAuthEnabled {
type Target = bool;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl FromRequest for LocalAuthEnabled {
type Error = Error;
type Future = Ready<Result<Self, Error>>;
fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future {
if AppConfig::get().disable_local_auth {
return ready(Ok(Self(false)));
}
let has_disable_local_auth_header = req
.headers()
.get(&AppConfig::get().disable_auth_header_token)
.is_some();
return ready(Ok(Self(!has_disable_local_auth_header)));
}
}

View File

@ -1,3 +1,4 @@
pub mod app_config; pub mod app_config;
pub mod constants; pub mod constants;
pub mod controllers; pub mod controllers;
pub mod extractors;

View File

@ -43,6 +43,10 @@ async fn main() -> std::io::Result<()> {
proxy: AppConfig::get().proxy_ip.clone(), proxy: AppConfig::get().proxy_ip.clone(),
})) }))
.route("/", web::get().to(server_controller::root_index)) .route("/", web::get().to(server_controller::root_index))
.route(
"/api/server/static_config",
web::get().to(server_controller::static_config),
)
}) })
.bind(&AppConfig::get().listen_address)? .bind(&AppConfig::get().listen_address)?
.run() .run()