]> git.proxmox.com Git - proxmox-backup.git/blob - proxmox-rest-server/src/lib.rs
move ApiConfig, FileLogger and CommandoSocket to proxmox-rest-server workspace
[proxmox-backup.git] / proxmox-rest-server / src / lib.rs
1 use anyhow::{bail, Error};
2
3 mod state;
4 pub use state::*;
5
6 mod command_socket;
7 pub use command_socket::*;
8
9 mod file_logger;
10 pub use file_logger::{FileLogger, FileLogOptions};
11
12 mod api_config;
13 pub use api_config::ApiConfig;
14
15 pub enum AuthError {
16 Generic(Error),
17 NoData,
18 }
19
20 impl From<Error> for AuthError {
21 fn from(err: Error) -> Self {
22 AuthError::Generic(err)
23 }
24 }
25
26 pub trait ApiAuth {
27 fn check_auth(
28 &self,
29 headers: &http::HeaderMap,
30 method: &hyper::Method,
31 ) -> Result<String, AuthError>;
32 }
33
34 static mut SHUTDOWN_REQUESTED: bool = false;
35
36 pub fn request_shutdown() {
37 unsafe {
38 SHUTDOWN_REQUESTED = true;
39 }
40 crate::server_shutdown();
41 }
42
43 #[inline(always)]
44 pub fn shutdown_requested() -> bool {
45 unsafe { SHUTDOWN_REQUESTED }
46 }
47
48 pub fn fail_on_shutdown() -> Result<(), Error> {
49 if shutdown_requested() {
50 bail!("Server shutdown requested - aborting task");
51 }
52 Ok(())
53 }
54