Ensure that the user specified in `config` has: -`SELECT` privileges for the identified `tables`. `tables`'s elements should be of the structure `[ , ]`. - `USAGE` privileges on the schemas references in `tables`. # Panics If `config` does not specify a user.
(
client: &Client,
table_oids: &[Oid],
)
| 860 | /// # Panics |
| 861 | /// If `config` does not specify a user. |
| 862 | pub async fn check_table_privileges( |
| 863 | client: &Client, |
| 864 | table_oids: &[Oid], |
| 865 | ) -> Result<(), PlanError> { |
| 866 | check_schema_privileges(client, table_oids).await?; |
| 867 | |
| 868 | let invalid_table_privileges_rows = query( |
| 869 | client, |
| 870 | sql!( |
| 871 | " |
| 872 | SELECT |
| 873 | format('%I.%I', n.nspname, c.relname) AS schema_qualified_table_name |
| 874 | FROM unnest($1::oid[]) AS oids (oid) |
| 875 | JOIN |
| 876 | pg_class c ON c.oid = oids.oid |
| 877 | JOIN |
| 878 | pg_namespace n ON c.relnamespace = n.oid |
| 879 | WHERE NOT has_table_privilege(CURRENT_USER::text, c.oid, 'select')" |
| 880 | ), |
| 881 | &[&table_oids], |
| 882 | ) |
| 883 | .await?; |
| 884 | |
| 885 | let mut invalid_table_privileges = invalid_table_privileges_rows |
| 886 | .into_iter() |
| 887 | .map(|row| row.get("schema_qualified_table_name")) |
| 888 | .collect::<Vec<String>>(); |
| 889 | |
| 890 | if invalid_table_privileges.is_empty() { |
| 891 | Ok(()) |
| 892 | } else { |
| 893 | invalid_table_privileges.sort(); |
| 894 | Err(PgSourcePurificationError::UserLacksSelectOnTables { |
| 895 | tables: invalid_table_privileges, |
| 896 | })? |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | /// Ensure that the user specified in `config` can read data from tables if row level security |
| 901 | /// (RLS) is enabled. If the user/role does not have the BYPASSRLS attribute set, there is |
no test coverage detected