Add basic server config

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

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)));
}
}