Skip to main content

systemprompt_extension/
router.rs

1#[derive(Debug, Clone, Copy)]
2pub struct ExtensionRouterConfig {
3    pub base_path: &'static str,
4    pub requires_auth: bool,
5}
6
7impl ExtensionRouterConfig {
8    #[must_use]
9    pub const fn new(base_path: &'static str) -> Self {
10        Self {
11            base_path,
12            requires_auth: true,
13        }
14    }
15
16    #[must_use]
17    pub const fn public(base_path: &'static str) -> Self {
18        Self {
19            base_path,
20            requires_auth: false,
21        }
22    }
23}
24
25#[derive(Debug, Clone, Copy)]
26pub struct SiteAuthConfig {
27    pub login_path: &'static str,
28    pub protected_prefixes: &'static [&'static str],
29    pub public_prefixes: &'static [&'static str],
30    pub required_scope: &'static str,
31}
32
33#[derive(Debug, Clone)]
34pub struct ExtensionRouter {
35    pub router: axum::Router,
36    pub base_path: &'static str,
37    pub requires_auth: bool,
38}
39
40impl ExtensionRouter {
41    #[must_use]
42    pub const fn new(router: axum::Router, base_path: &'static str) -> Self {
43        Self {
44            router,
45            base_path,
46            requires_auth: true,
47        }
48    }
49
50    #[must_use]
51    pub const fn public(router: axum::Router, base_path: &'static str) -> Self {
52        Self {
53            router,
54            base_path,
55            requires_auth: false,
56        }
57    }
58
59    #[must_use]
60    pub const fn config(&self) -> ExtensionRouterConfig {
61        ExtensionRouterConfig {
62            base_path: self.base_path,
63            requires_auth: self.requires_auth,
64        }
65    }
66}