mod entities;
mod rules;
use std::sync::Arc;
use sqlx::PgPool;
use systemprompt_database::DbPool;
use super::error::{AuthzError, AuthzResult};
use super::types::{Access, EntityKind, RuleType};
#[derive(Debug, Clone)]
pub struct ExportRuleRow {
pub entity_type: String,
pub entity_id: String,
pub rule_type: String,
pub rule_value: String,
pub access: String,
pub justification: Option<String>,
}
#[derive(Debug, Clone, Copy)]
pub struct UpsertRuleParams<'a> {
pub entity_type: EntityKind,
pub entity_id: &'a str,
pub rule_type: RuleType,
pub rule_value: &'a str,
pub access: Access,
pub justification: Option<&'a str>,
}
#[derive(Clone, Debug)]
pub struct AccessControlRepository {
pool: Arc<PgPool>,
write_pool: Arc<PgPool>,
}
impl AccessControlRepository {
pub fn new(db: &DbPool) -> AuthzResult<Self> {
let pool = db
.pool_arc()
.map_err(|err| AuthzError::Validation(err.to_string()))?;
let write_pool = db
.write_pool_arc()
.map_err(|err| AuthzError::Validation(err.to_string()))?;
Ok(Self { pool, write_pool })
}
pub fn from_pool(pool: Arc<PgPool>) -> Self {
let write_pool = Arc::clone(&pool);
Self { pool, write_pool }
}
}