Skip to content

Commit

Permalink
Added usage on schema statements to apply grants script
Browse files Browse the repository at this point in the history
  • Loading branch information
smunthik committed Nov 20, 2024
1 parent 50e2971 commit a2b657c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion shared/bcts_access_management/bcts_acces_apply_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ def apply_grants():
all_statements = []
for _, row in df.iterrows():
all_statements.extend(generate_grant_statements(row))
# Execute the grant statements in PostgreSQL

# Execute the grant statements in PostgreSQL
schema_roles_list = list(set([(x.split(' ON ')[1].split('.')[0], x.split(' TO ')[1].split(';')[0]) for x in all_statements]))
usage_statements = []
for (schema, role) in schema_roles_list:
usage_statement = f"GRANT USAGE ON SCHEMA {schema} TO {role};"
usage_statements.append(usage_statement)
all_statements.extend(usage_statements)
with engine.begin() as connection:
for statement in all_statements:
logging.info(statement)
Expand Down

0 comments on commit a2b657c

Please sign in to comment.