proxmox-rest-server: make check_auth async

This commit is contained in:
Dietmar Maurer
2021-10-01 07:29:11 +02:00
parent b914b94773
commit 038f385089
5 changed files with 59 additions and 35 deletions

View File

@ -1,7 +1,10 @@
//! Provides authentication primitives for the HTTP server
use anyhow::format_err;
use std::sync::Arc;
use std::future::Future;
use std::pin::Pin;
use anyhow::format_err;
use proxmox::api::UserInformation;
@ -55,16 +58,15 @@ impl UserApiAuth {
_ => None,
}
}
}
impl ApiAuth for UserApiAuth {
fn check_auth(
async fn check_auth_async(
&self,
headers: &http::HeaderMap,
method: &hyper::Method,
) -> Result<(String, Box<dyn UserInformation + Sync + Send>), AuthError> {
// fixme: make all IO async
let user_info = CachedUserInfo::new()?;
let auth_data = Self::extract_auth_data(headers);
@ -124,3 +126,13 @@ impl ApiAuth for UserApiAuth {
}
}
}
impl ApiAuth for UserApiAuth {
fn check_auth<'a>(
&'a self,
headers: &'a http::HeaderMap,
method: &'a hyper::Method,
) -> Pin<Box<dyn Future<Output = Result<(String, Box<dyn UserInformation + Sync + Send>), AuthError>> + Send + 'a>> {
Box::pin(self.check_auth_async(headers, method))
}
}