Skip to content

Commit

Permalink
Inspect function privileges
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbeaumont committed Feb 13, 2021
1 parent 8fe77e0 commit 9028a84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion schemainspect/pg/sql/privileges.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,15 @@ where grantee != (
)
-- SKIP_INTERNAL and table_schema not in ('pg_internal', 'pg_catalog', 'information_schema', 'pg_toast')
-- SKIP_INTERNAL and table_schema not like 'pg_temp_%' and table_schema not like 'pg_toast_temp_%'
order by schema, name, user;
union
select
routine_schema as schema,
routine_name as name,
'function' as object_type,
grantee as user,
privilege_type as privilege
from information_schema.role_routine_grants
where true
-- SKIP_INTERNAL and routine_schema not in ('pg_internal', 'pg_catalog', 'information_schema', 'pg_toast')
-- SKIP_INTERNAL and routine_schema not like 'pg_temp_%' and routine_schema not like 'pg_toast_temp_%'
order by schema, name, "user";
10 changes: 10 additions & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def setup_pg_schema(s):
)
as $$select 'a'::varchar, '2014-01-01'::date$$
language sql;
grant execute on function films_f(date, text, date) to postgres;
"""
)
s.execute("comment on function films_f(date, text, date) is 'films_f comment'")
Expand Down Expand Up @@ -454,6 +455,15 @@ def asserts_pg(i, has_timescale=False):
assert g.drop_statement == 'revoke select on table {} from "postgres";'.format(
t_films
)
f_films_f = n("films_f")
g = InspectedPrivilege("function", "public", "films_f", "execute", "postgres")
g = i.privileges[g.key]
assert g.create_statement == 'grant execute on function {} to "postgres";'.format(
f_films_f
)
assert g.drop_statement == 'revoke execute on function {} from "postgres";'.format(
f_films_f
)

# composite types
ct = i.composite_types[n("ttt")]
Expand Down

0 comments on commit 9028a84

Please sign in to comment.