All checks were successful
continuous-integration/drone/push Build is passing
34 lines
893 B
Rust
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)))
|
|
}
|
|
}
|