2021-12-15 23:42:16 +01:00
|
|
|
use std::sync::Arc;
|
2021-11-26 02:25:48 +01:00
|
|
|
use async_channel::Sender;
|
2021-12-15 23:42:16 +01:00
|
|
|
use lmdb::Environment;
|
2022-03-13 17:29:21 +01:00
|
|
|
use crate::resources::driver::Update;
|
2021-11-26 02:25:48 +01:00
|
|
|
|
2021-12-15 23:42:16 +01:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
/// Database of currently valid claims, interests and notify, as far as applicable
|
|
|
|
pub struct ClaimDB {
|
|
|
|
env: Arc<Environment>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type UserID = String;
|
|
|
|
pub type ResourceID = String;
|
|
|
|
pub struct ClaimEntry {
|
|
|
|
subject: UserID,
|
|
|
|
target: ResourceID,
|
|
|
|
level: Level,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Level {
|
|
|
|
Claim(Claim),
|
|
|
|
Interest(Interest),
|
|
|
|
Notify(Notify),
|
|
|
|
}
|
|
|
|
|
2021-11-26 02:25:48 +01:00
|
|
|
#[derive(Debug)]
|
2022-03-10 20:52:34 +01:00
|
|
|
/// A claim on a resources grants permission to update state
|
2021-11-26 02:25:48 +01:00
|
|
|
///
|
2022-03-10 20:52:34 +01:00
|
|
|
/// This permission is not necessarily exclusive, depending on the resources in question.
|
2021-11-26 02:25:48 +01:00
|
|
|
pub struct Claim {
|
2022-03-10 20:52:34 +01:00
|
|
|
/// Sending end that can be used to send state updates to a resources.
|
2021-11-26 02:25:48 +01:00
|
|
|
pub tx: Sender<Update>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2022-03-10 20:52:34 +01:00
|
|
|
/// An interest on a resources indicates that an user wants a resources to be in a specific state
|
2021-11-26 02:25:48 +01:00
|
|
|
pub struct Interest {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
/// A notify indicates that an user wants to be informed about changes in a resources' state
|
|
|
|
pub struct Notify {
|
|
|
|
|
|
|
|
}
|