Skip to content

Commit

Permalink
[OPMONDEV_139]: parametrise anonymizer_module PostgreSQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
wisecrow committed Mar 1, 2023
1 parent d99e626 commit 65a1357
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions anonymizer_module/opmon_anonymizer/iio/postgresql_manager.py
Expand Up @@ -103,13 +103,13 @@ def _ensure_table(self, schema, index_columns):
raise

def _table_exists(self, cursor):
cursor.execute(f"""
cursor.execute("""
SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name = '{self._table_name}'
AND table_name = %s
);
""")
""", (cursor._table_name,))

return cursor.fetchone()[0]

Expand All @@ -130,13 +130,12 @@ def _ensure_privileges(self):

for readonly_user in self._readonly_users:
try:
cursor.execute("GRANT USAGE ON SCHEMA public TO {readonly_user};".format(**{
'readonly_user': readonly_user
}))
cursor.execute("GRANT SELECT ON {table_name} TO {readonly_user};".format(**{
'table_name': self._table_name,
'readonly_user': readonly_user
}))
cursor.execute(
"GRANT USAGE ON SCHEMA public TO %s;", (readonly_user,)
)
cursor.execute(
"GRANT SELECT ON %s TO %s;", (self._table_name, readonly_user)
)
except Exception:
pass # Privileges existed

Expand Down

0 comments on commit 65a1357

Please sign in to comment.