Skip to main content

uqa_core/
catalog_role.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Durable role identities shared by SQL catalogs and storage metadata.
8
9use serde::{Deserialize, Serialize};
10
11/// A catalog reference retains both the public OID and the role incarnation.
12#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
13pub struct RoleIdentity {
14    pub oid: i64,
15    pub object_id: [u8; 16],
16}
17
18impl RoleIdentity {
19    pub const BOOTSTRAP: Self = Self {
20        oid: 10,
21        object_id: *b"UQA:role00000010",
22    };
23
24    pub fn is_valid(self) -> bool {
25        self.oid > 0 && u32::try_from(self.oid).is_ok() && self.object_id != [0; 16]
26    }
27}
28
29/// One ACL path whose endpoints retain their original role incarnations.
30#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
31pub struct BoundAclEntry<Privileges> {
32    /// An explicit null grantee represents PUBLIC; a missing field is invalid.
33    #[serde(deserialize_with = "Deserialize::deserialize")]
34    pub role: Option<RoleIdentity>,
35    pub grantor: RoleIdentity,
36    pub privileges: Privileges,
37    pub grant_options: Privileges,
38}
39
40#[cfg(test)]
41mod tests;