supabase / postgres-meta

A RESTful API for managing your Postgres. Fetch tables, add roles, and run queries
https://supabase.com
Apache License 2.0
941 stars 126 forks source link

feat: table privileges #588

Closed soedirgo closed 1 year ago

soedirgo commented 1 year ago

Add /table-privileges endpoint to list table (& views, matviews, etc.) privileges.

Example output:

Request:

GET /table-privileges

Response:

[
  {
    "relation_id": 12345,
    "schema": "public"
    "name": "users_audit",
    "kind": "table",
    "privileges": [
      {
        "grantee": "postgres",
        "grantor": "postgres",
        "is_grantable": false,
        "privilege_type": "INSERT",
      },
      {
        "grantee": "postgres",
        "grantor": "postgres",
        "is_grantable": false,
        "privilege_type": "SELECT",
      },
      ...
    ],
  },
  ...
]

Request:

POST /table-privileges
[
  {
    "relation_id": 11111,
    "grantee": "postgres",
    "privilege_type": "ALL"
  },
  {
    "relation_id": 22222,
    "grantee": "postgres",
    "privilege_type": "ALL"
  }
]

Response:

[
  {
    "relation_id": 11111,
    "schema": "public"
    "name": "t1",
    "kind": "table",
    "privileges": [...]
  },
  {
    "relation_id": 22222,
    "schema": "public",
    "name": "t2",
    "kind": "table",
    "privileges": [...]
  }
]

Request:

DELETE /table-privileges
[
  {
    "relation_id": 11111,
    "grantee": "postgres",
    "privilege_type": "ALL"
  },
  {
    "relation_id": 22222,
    "grantee": "postgres",
    "privilege_type": "ALL"
  }
]

Response:

[
  {
    "relation_id": 11111,
    "schema": "public"
    "name": "t1",
    "kind": "table",
    "privileges": []
  },
  {
    "relation_id": 22222,
    "schema": "public",
    "name": "t2",
    "kind": "table",
    "privileges": []
  }
]

TODO: