use futures::*;
use http::request::Parts;
use http::Response;
-use hyper::{Body, StatusCode};
-use hyper::header;
+use hyper::{Body, Method, StatusCode};
+use http::HeaderMap;
-use proxmox::try_block;
-use proxmox::api::RpcEnvironmentType;
-use proxmox::tools::fs::CreateOptions;
+use proxmox_lang::try_block;
+use proxmox_router::{RpcEnvironmentType, UserInformation};
+use proxmox_sys::fs::CreateOptions;
-use proxmox_rest_server::{daemon, ApiConfig, RestServer};
+use proxmox_rest_server::{daemon, AuthError, ApiConfig, RestServer, RestEnvironment, ServerAdapter};
-use proxmox_backup::server::auth::default_api_auth;
+use proxmox_backup::server::auth::check_pbs_auth;
use proxmox_backup::auth_helpers::*;
use proxmox_backup::config;
fn main() {
+ pbs_tools::setup_libc_malloc_opts();
+
proxmox_backup::tools::setup_safe_path_env();
- if let Err(err) = pbs_runtime::main(run()) {
+ if let Err(err) = proxmox_async::runtime::main(run()) {
eprintln!("Error: {}", err);
std::process::exit(-1);
}
}
-fn get_index<'a>(
- _auth_id: Option<String>,
- _language: Option<String>,
- _api: &'a ApiConfig,
- _parts: Parts,
-) -> Pin<Box<dyn Future<Output = Response<Body>> + Send + 'a>> {
- Box::pin(async move {
-
- let index = "<center><h1>Proxmox Backup API Server</h1></center>";
-
- Response::builder()
- .status(StatusCode::OK)
- .header(header::CONTENT_TYPE, "text/html")
- .body(index.into())
- .unwrap()
- })
+struct ProxmoxBackupApiAdapter;
+
+impl ServerAdapter for ProxmoxBackupApiAdapter {
+
+ fn get_index(
+ &self,
+ _env: RestEnvironment,
+ _parts: Parts,
+ ) -> Pin<Box<dyn Future<Output = Response<Body>> + Send>> {
+ Box::pin(async move {
+
+ let index = "<center><h1>Proxmox Backup API Server</h1></center>";
+
+ Response::builder()
+ .status(StatusCode::OK)
+ .header(hyper::header::CONTENT_TYPE, "text/html")
+ .body(index.into())
+ .unwrap()
+ })
+ }
+
+ fn check_auth<'a>(
+ &'a self,
+ headers: &'a HeaderMap,
+ method: &'a Method,
+ ) -> Pin<Box<dyn Future<Output = Result<(String, Box<dyn UserInformation + Sync + Send>), AuthError>> + Send + 'a>> {
+ Box::pin(async move {
+ check_pbs_auth(headers, method).await
+ })
+ }
}
async fn run() -> Result<(), Error> {
config::update_self_signed_cert(false)?;
proxmox_backup::server::create_run_dir()?;
-
- proxmox_backup::rrd::create_rrdb_dir()?;
+ proxmox_backup::server::create_state_dir()?;
proxmox_backup::server::jobstate::create_jobstate_dir()?;
proxmox_backup::tape::create_tape_status_dir()?;
proxmox_backup::tape::create_drive_state_dir()?;
pbs_buildcfg::JS_DIR,
&proxmox_backup::api2::ROUTER,
RpcEnvironmentType::PRIVILEGED,
- default_api_auth(),
- &get_index,
+ ProxmoxBackupApiAdapter,
)?;
let backup_user = pbs_config::backup_user()?;