mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-14 15:33:47 +00:00
rest-server: make adapter optional
when no user information or index needs to be defined Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
4a5360aef4
commit
6904dcf4e6
@ -1,4 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::future::Future;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
@ -40,18 +41,14 @@ impl ApiConfig {
|
|||||||
/// (index). Please note that this functions gets a reference to
|
/// (index). Please note that this functions gets a reference to
|
||||||
/// the [ApiConfig], so it can use [Handlebars] templates
|
/// the [ApiConfig], so it can use [Handlebars] templates
|
||||||
/// ([render_template](Self::render_template) to generate pages.
|
/// ([render_template](Self::render_template) to generate pages.
|
||||||
pub fn new<B: Into<PathBuf>>(
|
pub fn new<B: Into<PathBuf>>(basedir: B, env_type: RpcEnvironmentType) -> Self {
|
||||||
basedir: B,
|
|
||||||
env_type: RpcEnvironmentType,
|
|
||||||
adapter: impl ServerAdapter + 'static,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
basedir: basedir.into(),
|
basedir: basedir.into(),
|
||||||
aliases: HashMap::new(),
|
aliases: HashMap::new(),
|
||||||
env_type,
|
env_type,
|
||||||
request_log: None,
|
request_log: None,
|
||||||
auth_log: None,
|
auth_log: None,
|
||||||
adapter: Box::pin(adapter),
|
adapter: Box::pin(DummyAdapter),
|
||||||
handlers: Vec::new(),
|
handlers: Vec::new(),
|
||||||
|
|
||||||
#[cfg(feature = "templates")]
|
#[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) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user