1use std::collections::HashMap;
8
9#[derive(Debug, Clone, Default)]
11pub struct Claims {
12 pub sub: String,
13 pub email: String,
14 pub role: String,
15 pub roles: Vec<String>,
16 pub mfa: String,
19}
20
21#[derive(Debug, Clone, Default)]
22pub struct ReqCtx {
23 pub query: String,
25 pub mount: String,
27 pub path_params: HashMap<String, String>,
28 pub headers: HashMap<String, String>,
29 pub claims: Option<Claims>,
30}
31
32impl ReqCtx {
33 pub fn new() -> Self {
34 Self::default()
35 }
36
37 pub fn with_query(mut self, query: impl Into<String>) -> Self {
38 self.query = query.into();
39 self
40 }
41
42 pub fn with_mount(mut self, mount: impl Into<String>) -> Self {
43 self.mount = mount.into();
44 self
45 }
46
47 pub fn with_claims(mut self, claims: Claims) -> Self {
48 self.claims = Some(claims);
49 self
50 }
51
52 pub fn roles(&self) -> Vec<String> {
54 match &self.claims {
55 Some(c) => {
56 let mut r = c.roles.clone();
57 if !c.role.is_empty() && !r.contains(&c.role) {
58 r.push(c.role.clone());
59 }
60 r
61 }
62 None => Vec::new(),
63 }
64 }
65}