From 58eba821e6cc622a19d0aea211b9b339d0f42ca2 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 30 Sep 2021 13:49:29 +0200 Subject: [PATCH] proxmox-rest-server: start module docs --- proxmox-rest-server/src/lib.rs | 18 ++++++++++++++++++ proxmox-rest-server/src/rest.rs | 13 +++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/proxmox-rest-server/src/lib.rs b/proxmox-rest-server/src/lib.rs index da52c673..6ac2b146 100644 --- a/proxmox-rest-server/src/lib.rs +++ b/proxmox-rest-server/src/lib.rs @@ -1,3 +1,21 @@ +//! # Proxmox REST server +//! +//! This module provides convenient building blocks to implement a +//! REST server. +//! +//! ## Features +//! +//! * HTTP and HTTP2 +//! * highly threaded code, uses Rust async +//! * static API definitions using schemas +//! * restartable systemd daemons using `systemd_notify` +//! * support for long running worker tasks (threads or async tokio tasks) +//! * supports separate access and authentification log files +//! * separate control socket to trigger management operations +//! - logfile rotation +//! - worker task management +//! * generic interface to authenticate user + use std::sync::atomic::{Ordering, AtomicBool}; use anyhow::{bail, format_err, Error}; diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs index bf4dbb40..bb7d7e05 100644 --- a/proxmox-rest-server/src/rest.rs +++ b/proxmox-rest-server/src/rest.rs @@ -19,6 +19,7 @@ use serde_json::Value; use tokio::fs::File; use tokio::time::Instant; use url::form_urlencoded; +use tower_service::Service; use proxmox::api::schema::{ parse_parameter_strings, parse_simple_value, verify_json_object, ObjectSchemaType, @@ -53,6 +54,9 @@ impl UserInformation for EmptyUserInformation { } /// REST server implementation (configured with [ApiConfig]) +/// +/// This struct implements the [Service] trait in order to use it with +/// [hyper::server::Builder::serve]. pub struct RestServer { api_config: Arc, } @@ -61,6 +65,7 @@ const MAX_URI_QUERY_LENGTH: usize = 3072; const CHUNK_SIZE_LIMIT: u64 = 32 * 1024; impl RestServer { + /// Creates a new instance. pub fn new(api_config: ApiConfig) -> Self { Self { api_config: Arc::new(api_config), @@ -68,7 +73,7 @@ impl RestServer { } } -impl tower_service::Service<&Pin>>> +impl Service<&Pin>>> for RestServer { type Response = ApiService; @@ -94,7 +99,7 @@ impl tower_service::Service<&Pin for RestServer { +impl Service<&hyper::server::conn::AddrStream> for RestServer { type Response = ApiService; type Error = Error; type Future = Pin> + Send>>; @@ -113,7 +118,7 @@ impl tower_service::Service<&hyper::server::conn::AddrStream> for RestServer { } } -impl tower_service::Service<&tokio::net::UnixStream> for RestServer { +impl Service<&tokio::net::UnixStream> for RestServer { type Response = ApiService; type Error = Error; type Future = Pin> + Send>>; @@ -220,7 +225,7 @@ fn get_user_agent(headers: &HeaderMap) -> Option { .ok() } -impl tower_service::Service> for ApiService { +impl Service> for ApiService { type Response = Response; type Error = Error; #[allow(clippy::type_complexity)]