mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-14 17:02:56 +00:00
Adds endpoint to install extensions:
**POST** `/extensions`
```
{"extension":"pg_sessions_jwt","database":"neondb","version":"1.0.0"}
```
Will be used by `local-proxy`.
Example, for the JWT authentication to work the database needs to have
the pg_session_jwt extension and also to enable JWT to work in RLS
policies.
---------
Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import requests
|
|
from requests.adapters import HTTPAdapter
|
|
|
|
|
|
class EndpointHttpClient(requests.Session):
|
|
def __init__(
|
|
self,
|
|
port: int,
|
|
):
|
|
super().__init__()
|
|
self.port = port
|
|
|
|
self.mount("http://", HTTPAdapter())
|
|
|
|
def dbs_and_roles(self):
|
|
res = self.get(f"http://localhost:{self.port}/dbs_and_roles")
|
|
res.raise_for_status()
|
|
return res.json()
|
|
|
|
def database_schema(self, database: str):
|
|
res = self.get(f"http://localhost:{self.port}/database_schema?database={database}")
|
|
res.raise_for_status()
|
|
return res.text
|
|
|
|
def installed_extensions(self):
|
|
res = self.get(f"http://localhost:{self.port}/installed_extensions")
|
|
res.raise_for_status()
|
|
return res.json()
|
|
|
|
def extensions(self, extension: str, version: str, database: str):
|
|
body = {
|
|
"extension": extension,
|
|
"version": version,
|
|
"database": database,
|
|
}
|
|
res = self.post(f"http://localhost:{self.port}/extensions", json=body)
|
|
res.raise_for_status()
|
|
return res.json()
|
|
|
|
def set_role_grants(self, database: str, role: str, schema: str, privileges: list[str]):
|
|
res = self.post(
|
|
f"http://localhost:{self.port}/grants",
|
|
json={"database": database, "schema": schema, "role": role, "privileges": privileges},
|
|
)
|
|
res.raise_for_status()
|
|
return res.json()
|