surrealdb_expr/expr/access.rs
1use crate::expr::{Expr, Literal};
2use crate::val::Duration;
3
4#[derive(Debug, Hash, Clone, Eq, PartialEq)]
5// Durations representing the expiration of different elements of the access method
6// In this context, the None variant represents that the element does not expire
7pub struct AccessDuration {
8 // Duration after which the grants generated with the access method expire
9 // For access methods whose grants are tokens, this value is irrelevant
10 pub grant: Expr,
11 // Duration after which the tokens obtained with the access method expire
12 // For access methods that cannot issue tokens, this value is irrelevant
13 pub token: Expr,
14 // Duration after which the session authenticated with the access method expires
15 pub session: Expr,
16}
17
18impl Default for AccessDuration {
19 fn default() -> Self {
20 Self {
21 // By default, access grants expire in 30 days.
22 grant: Expr::Literal(Literal::Duration(
23 Duration::from_days(30).expect("30 days should fit in a duration"),
24 )),
25 // By default, tokens expire after one hour
26 token: Expr::Literal(Literal::Duration(
27 Duration::from_hours(1).expect("1 hour should fit in a duration"),
28 )),
29 // By default, sessions do not expire
30 session: Expr::Literal(Literal::None),
31 }
32 }
33}