]> git.proxmox.com Git - proxmox.git/commitdiff
rest-server: make adapter optional
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 24 Jan 2023 14:02:56 +0000 (15:02 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 2 Mar 2023 15:14:04 +0000 (16:14 +0100)
when no user information or index needs to be defined

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-rest-server/src/api_config.rs

index ba21fcd3161c3d4dd0a5d6434f5c886141a6f36b..8d81a7e25b96adc389eb68dfdf3552af8c217f35 100644 (file)
@@ -1,4 +1,5 @@
 use std::collections::HashMap;
+use std::future::Future;
 use std::path::PathBuf;
 use std::pin::Pin;
 use std::sync::{Arc, Mutex};
@@ -40,18 +41,14 @@ impl ApiConfig {
     /// (index). Please note that this functions gets a reference to
     /// the [ApiConfig], so it can use [Handlebars] templates
     /// ([render_template](Self::render_template) to generate pages.
-    pub fn new<B: Into<PathBuf>>(
-        basedir: B,
-        env_type: RpcEnvironmentType,
-        adapter: impl ServerAdapter + 'static,
-    ) -> Self {
+    pub fn new<B: Into<PathBuf>>(basedir: B, env_type: RpcEnvironmentType) -> Self {
         Self {
             basedir: basedir.into(),
             aliases: HashMap::new(),
             env_type,
             request_log: None,
             auth_log: None,
-            adapter: Box::pin(adapter),
+            adapter: Box::pin(DummyAdapter),
             handlers: Vec::new(),
 
             #[cfg(feature = "templates")]
@@ -336,3 +333,28 @@ mod templates {
         }
     }
 }
+
+pub struct DummyAdapter;
+
+impl ServerAdapter for DummyAdapter {
+    fn get_index(
+        &self,
+        _rest_env: RestEnvironment,
+        _parts: Parts,
+    ) -> Pin<Box<dyn Future<Output = Response<Body>> + Send>> {
+        Box::pin(async move {
+            Response::builder()
+                .status(400)
+                .body("no index defined".into())
+                .unwrap()
+        })
+    }
+
+    fn check_auth<'a>(
+        &'a self,
+        _headers: &'a http::HeaderMap,
+        _method: &'a http::Method,
+    ) -> crate::ServerAdapterCheckAuth<'a> {
+        Box::pin(async move { Err(crate::AuthError::NoData) })
+    }
+}