Skip to main content

rs_zero/rest/
config.rs

1use std::time::Duration;
2
3/// JWT authorization configuration.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct AuthConfig {
6    /// HS256 secret used to validate bearer tokens.
7    pub secret: String,
8    /// Exact request paths that bypass token validation.
9    pub public_paths: Vec<String>,
10}
11
12impl AuthConfig {
13    /// Returns whether `path` is public.
14    pub fn is_public(&self, path: &str) -> bool {
15        self.public_paths.iter().any(|item| item == path)
16    }
17}
18
19/// REST service runtime configuration.
20#[derive(Debug, Clone)]
21pub struct RestConfig {
22    /// Service name used by logs and traces.
23    pub name: String,
24    /// Request timeout.
25    pub timeout: Duration,
26    /// Maximum accepted request body size.
27    pub max_body_bytes: usize,
28    /// Optional JWT authorization configuration.
29    pub auth: Option<AuthConfig>,
30}
31
32impl Default for RestConfig {
33    fn default() -> Self {
34        Self {
35            name: "rs-zero".to_string(),
36            timeout: Duration::from_secs(5),
37            max_body_bytes: 1024 * 1024,
38            auth: None,
39        }
40    }
41}