diff --git a/proxmox-rest-server/src/api_config.rs b/proxmox-rest-server/src/api_config.rs index 7f5af954..f4cc30f3 100644 --- a/proxmox-rest-server/src/api_config.rs +++ b/proxmox-rest-server/src/api_config.rs @@ -65,12 +65,28 @@ impl ApiConfig { self } + /// Set the authentication handler from a function. + pub fn with_auth_handler_func(self, func: Func) -> Self + where + Func: for<'a> Fn(&'a HeaderMap, &'a Method) -> CheckAuthFuture<'a> + Send + Sync + 'static, + { + self.with_auth_handler(AuthHandler::from_fn(func)) + } + /// Set the index handler. pub fn with_index_handler(mut self, index_handler: IndexHandler) -> Self { self.index_handler = Some(index_handler); self } + /// Set the index handler from a function. + pub fn with_index_handler_func(self, func: Func) -> Self + where + Func: Fn(RestEnvironment, Parts) -> IndexFuture + Send + Sync + 'static, + { + self.with_index_handler(IndexHandler::from_fn(func)) + } + pub(crate) async fn get_index( &self, rest_env: RestEnvironment, @@ -373,13 +389,13 @@ impl IndexHandler { where B: Clone + Send + Sync + Into + 'static, { - Self::from_response_fn(move |_, _| { + Self::from_fn(move |_, _| { let body = body.clone().into(); Box::pin(async move { Response::builder().status(200).body(body).unwrap() }) }) } - pub fn from_response_fn(func: Func) -> Self + pub fn from_fn(func: Func) -> Self where Func: Fn(RestEnvironment, Parts) -> IndexFuture + Send + Sync + 'static, {