use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Permission {
KvRead {
project_id: String,
#[serde(default)]
scope_id: Option<String>,
#[serde(default)]
prefix: Option<Vec<u8>>,
},
KvWrite {
project_id: String,
#[serde(default)]
scope_id: Option<String>,
#[serde(default)]
prefix: Option<Vec<u8>>,
},
TableRead {
project_id: String,
scope_id: String,
table_name: String,
},
TableWrite {
project_id: String,
scope_id: String,
table_name: String,
},
IndexRead {
project_id: String,
scope_id: String,
table_name: String,
index_name: String,
},
TableDdl { project_id: String },
GlobalAdmin,
ProjectAdmin { project_id: String },
ScopeAdmin {
project_id: String,
scope_id: String,
},
PolicyBypass {
project_id: String,
#[serde(default)]
table_name: Option<String>,
},
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct CallerContext {
pub caller_id: String,
#[serde(default, skip_deserializing)]
internal_system: bool,
}
impl CallerContext {
pub fn new(caller_id: impl Into<String>) -> Self {
Self {
caller_id: caller_id.into(),
internal_system: false,
}
}
#[cfg(test)]
pub(crate) fn system_internal() -> Self {
Self {
caller_id: "system".to_string(),
internal_system: true,
}
}
pub(crate) fn is_internal_system(&self) -> bool {
self.internal_system && self.caller_id == "system"
}
}