Files
VirtWeb/virtweb_backend/src/extractors/local_auth_extractor.rs
Pierre HUBERT e9e3103938
All checks were successful
continuous-integration/drone/push Build is passing
Format all code following migration to Rust edition 2024
2025-03-28 10:23:37 +01:00

34 lines
893 B
Rust

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();
ready(Ok(Self(!has_disable_local_auth_header)))
}
}