Skip to content

Commit

Permalink
fix: fix system acl column type to support \l command
Browse files Browse the repository at this point in the history
  • Loading branch information
yezizp2012 committed Nov 13, 2024
1 parent 0ddb6eb commit ab778ee
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 36 deletions.
25 changes: 10 additions & 15 deletions src/frontend/src/catalog/system_catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,8 @@ fn get_acl_items(
for_dml_table: bool,
users: &Vec<UserCatalog>,
username_map: &HashMap<UserId, String>,
) -> String {
let mut res = String::from("{");
let mut empty_flag = true;
) -> Vec<String> {
let mut res = vec![];
let super_privilege = available_prost_privilege(*object, for_dml_table);
for user in users {
let privileges = if user.is_super {
Expand All @@ -263,25 +262,21 @@ fn get_acl_items(
})
});
for (granted_by, actions) in grantor_map {
if empty_flag {
empty_flag = false;
} else {
res.push(',');
}
res.push_str(&user.name);
res.push('=');
let mut aclitem = String::new();
aclitem.push_str(&user.name);
aclitem.push('=');
for (action, option) in actions {
res.push_str(&AclMode::from(action).to_string());
aclitem.push_str(&AclMode::from(action).to_string());
if option {
res.push('*');
aclitem.push('*');
}
}
res.push('/');
aclitem.push('/');
// should be able to query grantor's name
res.push_str(username_map.get(&granted_by).unwrap());
aclitem.push_str(username_map.get(&granted_by).unwrap());
res.push(aclitem);
}
}
res.push('}');
res
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ struct PgDatabase {
datallowconn: bool,
datconnlimit: i32,
dattablespace: i32,
datacl: String,
datacl: Vec<String>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ struct PgNamespace {
oid: i32,
nspname: String,
nspowner: i32,
nspacl: String,
nspacl: Vec<String>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ struct PgTablespace {
oid: i32,
spcname: String,
spcowner: i32,
spcacl: String,
spcacl: Vec<String>,
spcoptions: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct RwConnection {
owner: i32,
type_: String,
provider: String,
acl: String,
acl: Vec<String>,
}

#[system_catalog(table, "rw_catalog.rw_connections")]
Expand All @@ -44,7 +44,7 @@ fn read_rw_connections(reader: &SysCatalogReaderImpl) -> Result<Vec<RwConnection
owner: conn.owner as i32,
type_: conn.connection_type().into(),
provider: conn.provider().into(),
acl: "".into(),
acl: vec![],
})
})
.collect())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct RwDatabases {
id: i32,
name: String,
owner: i32,
acl: String,
acl: Vec<String>,
}

#[system_catalog(table, "rw_catalog.rw_databases")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct RwFunction {
return_type_id: i32,
language: String,
link: Option<String>,
acl: String,
acl: Vec<String>,
always_retry_on_network_error: bool,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct RwIndex {
schema_id: i32,
owner: i32,
definition: String,
acl: String,
acl: Vec<String>,
initialized_at: Option<Timestamptz>,
created_at: Option<Timestamptz>,
initialized_at_cluster_version: Option<String>,
Expand Down Expand Up @@ -76,7 +76,7 @@ fn read_rw_indexes(reader: &SysCatalogReaderImpl) -> Result<Vec<RwIndex>> {
schema_id: schema.id() as i32,
owner: index.index_table.owner as i32,
definition: index.index_table.create_sql(),
acl: "".into(),
acl: vec![],
initialized_at: index.initialized_at_epoch.map(|e| e.as_timestamptz()),
created_at: index.created_at_epoch.map(|e| e.as_timestamptz()),
initialized_at_cluster_version: index.initialized_at_cluster_version.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct RwInternalTable {
schema_id: i32,
owner: i32,
definition: String,
acl: String,
acl: Vec<String>,
initialized_at: Option<Timestamptz>,
created_at: Option<Timestamptz>,
initialized_at_cluster_version: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct RwMaterializedView {
owner: i32,
definition: String,
append_only: bool,
acl: String,
acl: Vec<String>,
initialized_at: Option<Timestamptz>,
created_at: Option<Timestamptz>,
initialized_at_cluster_version: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ struct RwRelation {
schema_id: i32,
owner: i32,
definition: String,
acl: String,
acl: Vec<String>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct RwSchema {
id: i32,
name: String,
owner: i32,
acl: String,
acl: Vec<String>,
}

#[system_catalog(table, "rw_catalog.rw_schemas")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct RwSecret {
id: i32,
name: String,
owner: i32,
acl: String,
acl: Vec<String>,
}

#[system_catalog(table, "rw_catalog.rw_secrets")]
Expand All @@ -38,7 +38,7 @@ fn read_rw_view_info(reader: &SysCatalogReaderImpl) -> Result<Vec<RwSecret>> {
id: secret.id.secret_id() as i32,
name: secret.name.clone(),
owner: secret.owner as i32,
acl: "".into(),
acl: vec![],
})
})
.collect())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct RwSink {
sink_type: String,
connection_id: Option<i32>,
definition: String,
acl: String,
acl: Vec<String>,
initialized_at: Option<Timestamptz>,
created_at: Option<Timestamptz>,
initialized_at_cluster_version: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct RwSource {
associated_table_id: Option<i32>,
connection_id: Option<i32>,
definition: String,
acl: String,
acl: Vec<String>,
initialized_at: Option<Timestamptz>,
created_at: Option<Timestamptz>,
initialized_at_cluster_version: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct RwSubscription {
schema_id: i32,
owner: i32,
definition: String,
acl: String,
acl: Vec<String>,
initialized_at: Option<Timestamptz>,
created_at: Option<Timestamptz>,
initialized_at_cluster_version: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct SystemTable {
schema_id: i32,
owner: i32,
definition: Option<String>,
acl: String,
acl: Vec<String>,
}

#[system_catalog(table, "rw_catalog.rw_system_tables")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct RwTable {
owner: i32,
definition: String,
append_only: bool,
acl: String,
acl: Vec<String>,
initialized_at: Option<Timestamptz>,
created_at: Option<Timestamptz>,
initialized_at_cluster_version: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct RwView {
schema_id: i32,
owner: i32,
definition: String,
acl: String,
acl: Vec<String>,
}

#[system_catalog(table, "rw_catalog.rw_views")]
Expand Down

0 comments on commit ab778ee

Please sign in to comment.