Skip to main content

uqa_sql/catalog/
security.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7use std::collections::BTreeMap;
8pub mod columns;
9pub mod schema;
10pub mod table;
11pub use uqa_core::catalog_acl::{TableAclEntry, TablePrivileges};
12
13/// Complete table-shaped relation security state. Ownership and ACL changes are published through one value so readers cannot observe a torn authorization state.
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct TableSecurity {
16    pub role_owner: String,
17    pub acl: Option<Vec<TableAclEntry>>,
18    pub column_acls: BTreeMap<String, Vec<TableAclEntry>>,
19}
20
21impl TableSecurity {
22    pub fn owner(role_owner: impl Into<String>) -> Self {
23        Self {
24            role_owner: role_owner.into(),
25            acl: None,
26            column_acls: BTreeMap::new(),
27        }
28    }
29}
30
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct SchemaSecurity {
33    pub role_owner: String,
34    pub acl: Option<Vec<uqa_core::catalog_schema::SchemaAclEntry>>,
35}
36
37impl SchemaSecurity {
38    pub fn from_row(row: uqa_core::catalog_schema::SchemaRow) -> (String, Self) {
39        (
40            row.name,
41            Self {
42                role_owner: row.role_owner,
43                acl: row.acl,
44            },
45        )
46    }
47
48    pub fn row(&self, name: impl Into<String>) -> uqa_core::catalog_schema::SchemaRow {
49        uqa_core::catalog_schema::SchemaRow {
50            name: name.into(),
51            role_owner: self.role_owner.clone(),
52            acl: self.acl.clone(),
53        }
54    }
55
56    pub fn legacy(name: &str) -> Self {
57        let (_, security) = Self::from_row(uqa_core::catalog_schema::SchemaRow::legacy(name));
58        security
59    }
60}
61
62pub mod schema_inquiry;
63
64pub mod database;
65pub mod database_inquiry;
66
67pub mod sequence;
68pub mod sequence_grants;
69pub mod sequence_inquiry;
70
71#[derive(Debug, Clone, PartialEq, Eq)]
72pub struct SequenceSecurity {
73    pub role_owner: String,
74    pub acl: Option<Vec<uqa_core::catalog_sequence::SequenceAclEntry>>,
75}
76
77pub mod table_inquiry;
78
79pub mod view_ownership;
80
81pub mod grants;
82pub mod table_grants;
83
84pub mod view_authorization;
85
86pub mod ownership;