Create or replace an RLS policy.
(&self, policy: RlsPolicy)
| 44 | |
| 45 | /// Create or replace an RLS policy. |
| 46 | pub fn create_policy(&self, policy: RlsPolicy) -> crate::Result<()> { |
| 47 | let key = policy_key(policy.tenant_id, &policy.collection); |
| 48 | let mut policies = self.lock_write(); |
| 49 | let list = policies.entry(key).or_default(); |
| 50 | |
| 51 | if let Some(existing) = list.iter_mut().find(|p| p.name == policy.name) { |
| 52 | *existing = policy; |
| 53 | } else { |
| 54 | list.push(policy); |
| 55 | } |
| 56 | Ok(()) |
| 57 | } |
| 58 | |
| 59 | /// Drop an RLS policy. Returns `true` if a policy was removed. |
| 60 | pub fn drop_policy(&self, tenant_id: u64, collection: &str, policy_name: &str) -> bool { |