aboutsummaryrefslogtreecommitdiff
path: root/crates/secd/src/auth/z.rs
blob: 81c363924d7bed1c94851c6a85e584f8e85cfe15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use uuid::Uuid;

use crate::{client::spice::SpiceError, Secd};

#[derive(Debug, thiserror::Error, derive_more::Display)]
pub enum AuthZError {
    SpiceClient(#[from] SpiceError),
    Todo,
}

pub type Namespace = String;
pub type Object = (Namespace, Uuid);
pub type Relation = String;

pub struct Relationship {
    pub subject: Subject,
    pub object: Object,
    pub relation: String,
}

#[derive(Clone)]
pub enum Subject {
    User(Object),
    UserSet { user: Object, relation: Relation },
}

impl Secd {
    pub async fn check(&self, r: &Relationship) -> Result<bool, AuthZError> {
        let spice = self
            .spice
            .clone()
            .expect("TODO: only supports postgres right now");

        Ok(spice.check_permission(r).await?)
    }
    pub async fn expand(&self) -> Result<(), AuthZError> {
        todo!()
    }
    pub async fn read(&self) -> Result<(), AuthZError> {
        todo!()
    }
    pub async fn watch(&self) -> Result<(), AuthZError> {
        unimplemented!()
    }
    pub async fn write(&self, ts: &[Relationship]) -> Result<(), AuthZError> {
        let spice = self
            .spice
            .clone()
            .expect("TODO: only supports postgres right now");

        spice.write_relationship(ts).await?;
        Ok(())
    }
}