use crate::auth::AuthContext;
use crate::error::GatewayError;
#[derive(Debug, Clone)]
pub struct Policy {
pub name: String,
pub table: String,
pub filter: Option<String>,
pub required_role: Option<String>,
pub operations: Vec<Operation>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Operation {
Read,
Create,
Update,
Delete,
}
#[derive(Debug, Default)]
pub struct PolicyEngine {
policies: Vec<Policy>,
}
impl PolicyEngine {
pub fn new() -> Self {
Self::default()
}
pub fn load_from_file(&mut self, _path: &str) -> Result<(), GatewayError> {
tracing::info!("Policy loading not yet implemented");
Ok(())
}
pub fn check_access(
&self,
_auth: &AuthContext,
_table: &str,
_operation: Operation,
) -> Result<(), GatewayError> {
Ok(())
}
pub fn get_filter(
&self,
_auth: &AuthContext,
_table: &str,
) -> Option<String> {
None
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_policy_engine_allows_by_default() {
let engine = PolicyEngine::new();
let auth = AuthContext::anonymous();
let result = engine.check_access(&auth, "users", Operation::Read);
assert!(result.is_ok());
}
}