1use eva_common::acl::Acl;
2use eva_common::prelude::*;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Serialize, Deserialize, Clone, Default)]
6pub struct ACI {
7 auth: AuthMode,
8 acl: String,
9 token_mode: Option<TokenMode>,
10 u: Option<String>,
11 src: Option<String>,
12}
13
14impl ACI {
15 #[inline]
16 pub fn acl_id(&self) -> &str {
17 &self.acl
18 }
19 #[inline]
20 pub fn token_mode(&self) -> Option<TokenMode> {
21 self.token_mode
22 }
23 #[inline]
24 pub fn user(&self) -> Option<&str> {
25 self.u.as_deref()
26 }
27 #[inline]
28 pub fn source(&self) -> Option<&str> {
29 self.src.as_deref()
30 }
31 #[inline]
32 pub fn writable(&self) -> bool {
33 if let Some(token_mode) = self.token_mode {
34 token_mode == TokenMode::Normal
35 } else {
36 true
37 }
38 }
39 #[inline]
40 pub fn check_write(&self) -> EResult<()> {
41 if self.writable() {
42 Ok(())
43 } else {
44 Err(Error::access("Session is in the read-only mode"))
45 }
46 }
47}
48
49#[derive(Debug, Serialize, Deserialize, Copy, Clone, Eq, PartialEq)]
50#[serde(rename_all = "lowercase")]
51pub enum TokenMode {
52 Normal,
53 Readonly,
54}
55
56#[derive(Debug, Serialize, Deserialize, Copy, Clone, Eq, PartialEq, Default)]
57#[serde(rename_all = "lowercase")]
58pub enum AuthMode {
59 Token,
60 Key,
61 #[default]
62 No,
63}
64
65#[derive(Deserialize, Serialize, Debug, Clone)]
66pub struct XParamsOwned {
67 pub method: String,
68 pub params: Value,
69 pub aci: ACI,
70 pub acl: Acl,
71}
72
73impl XParamsOwned {
74 #[inline]
75 pub fn method(&self) -> &str {
76 &self.method
77 }
78}