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