Skip to content

Commit e2d2f1a

Browse files
committed
comments
Former-commit-id: 0ea70fb
1 parent 37941dc commit e2d2f1a

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

grant_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// grant_test.go
21
package main
32

43
import (
@@ -26,13 +25,15 @@ func Test_parseGrants(t *testing.T) {
2625
, pg_catalog.array_to_string(a.attacl, E'\n') AS column_acl
2726
*/
2827

28+
// Note that these must be sorted for this to work
2929
var test1a = []map[string]string{
3030
{"schema": "public", "relationship_name": "table1", "type": "TABLE", "relationship_acl": "c42=rwa/postgres", "column_name": "", "column_acl": ""},
3131
{"schema": "public", "relationship_name": "table1", "type": "TABLE", "relationship_acl": "", "column_name": "column1", "column_acl": "c42ro=rwa/postgres"},
3232
{"schema": "public", "relationship_name": "table1", "type": "TABLE", "relationship_acl": "", "column_name": "column2", "column_acl": "c42ro=r/postgres\nc42=rwad/postgres"},
3333
{"schema": "public", "relationship_name": "table2", "type": "TABLE", "relationship_acl": "c42=rwa/postgres", "column_name": "", "column_acl": ""},
3434
}
3535

36+
// Note that these must be sorted for this to work
3637
var test1b = []map[string]string{
3738
{"schema": "public", "relationship_name": "table1", "type": "TABLE", "relationship_acl": "", "column_name": "column2", "column_acl": "c42ro=r/postgres\nc42=rwad/postgres"},
3839
{"schema": "public", "relationship_name": "table2", "type": "TABLE", "relationship_acl": "c42=rwad/postgres", "column_name": "t1c1", "column_acl": ""},

privilege.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,51 @@ SELECT table_name
22
FROM information_schema.tables
33
WHERE table_schema = 'information_schema';
44

5-
SELECT grantee, table_name, privilege_type, is_grantable, with_hierarchy
5+
SELECT grantee, table_name, privilege_type, is_grantable, with_hierarchy,
66
FROM information_schema.table_privileges
77
WHERE table_schema = 'public'
88
ORDER BY table_name, privilege_type;
99

1010
SELECT grantee, table_name, column_name, privilege_type, is_grantable
1111
FROM information_schema.column_privileges
1212
WHERE table_schema = 'public';
13+
14+
15+
--
16+
-- GRANT SQL
17+
--
18+
GRANT SELECT (service_type) ON t_computer TO c42ro;
19+
20+
-- selects grants for tables, views, and sequences
21+
SELECT relname
22+
, relacl
23+
, CASE WHEN relkind = 'S' THEN 'SEQUENCE'
24+
WHEN relkind = 'r' THEN 'TABLE'
25+
WHEN relkind = 'v' THEN 'VIEW'
26+
ELSE relkind::varchar END AS type
27+
FROM pg_class
28+
WHERE true --relkind = 'S'
29+
AND relacl IS NOT NULL
30+
AND relnamespace IN (
31+
SELECT oid FROM pg_namespace
32+
WHERE nspname NOT LIKE 'pg_%' AND nspname != 'information_schema'
33+
);
34+
35+
36+
crashplan=# \dp
37+
********* QUERY **********
38+
SELECT n.nspname as "Schema",
39+
c.relname as "Name",
40+
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'S' THEN 'sequence' WHEN 'f' THEN 'foreign table' END as "Type",
41+
pg_catalog.array_to_string(c.relacl, E'\n') AS "Access privileges",
42+
pg_catalog.array_to_string(ARRAY(
43+
SELECT attname || E':\n ' || pg_catalog.array_to_string(attacl, E'\n ')
44+
FROM pg_catalog.pg_attribute a
45+
WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL
46+
), E'\n') AS "Column access privileges"
47+
FROM pg_catalog.pg_class c
48+
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
49+
WHERE c.relkind IN ('r', 'v', 'S', 'f')
50+
AND n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)
51+
ORDER BY 1, 2;
52+
**************************

0 commit comments

Comments
 (0)