Skip to main content

cratestack_policy/
read_types.rs

1//! Read-side policy types (predicates / expressions / literals).
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum RelationQuantifier {
5    ToOne,
6    Some,
7    Every,
8    None,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum PolicyLiteral {
13    Bool(bool),
14    Int(i64),
15    String(&'static str),
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum ReadPredicate {
20    AuthNotNull,
21    AuthIsNull,
22    HasRole {
23        role: &'static str,
24    },
25    InTenant {
26        tenant_id: &'static str,
27    },
28    AuthFieldEqLiteral {
29        auth_field: &'static str,
30        value: PolicyLiteral,
31    },
32    AuthFieldNeLiteral {
33        auth_field: &'static str,
34        value: PolicyLiteral,
35    },
36    FieldIsTrue {
37        column: &'static str,
38    },
39    FieldEqLiteral {
40        column: &'static str,
41        value: PolicyLiteral,
42    },
43    FieldNeLiteral {
44        column: &'static str,
45        value: PolicyLiteral,
46    },
47    FieldEqAuth {
48        column: &'static str,
49        auth_field: &'static str,
50    },
51    FieldNeAuth {
52        column: &'static str,
53        auth_field: &'static str,
54    },
55    Relation {
56        quantifier: RelationQuantifier,
57        parent_table: &'static str,
58        parent_column: &'static str,
59        related_table: &'static str,
60        related_column: &'static str,
61        expr: &'static PolicyExpr,
62    },
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66pub struct ReadPolicy {
67    pub expr: PolicyExpr,
68}
69
70#[derive(Debug, Clone, Copy, PartialEq, Eq)]
71pub enum PolicyExpr {
72    Predicate(ReadPredicate),
73    And(&'static [PolicyExpr]),
74    Or(&'static [PolicyExpr]),
75}