Add basic server config
This commit is contained in:
33
virtweb_backend/src/extractors/local_auth_extractor.rs
Normal file
33
virtweb_backend/src/extractors/local_auth_extractor.rs
Normal 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)));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user