interloper-api 0.133.0__tar.gz → 0.134.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {interloper_api-0.133.0 → interloper_api-0.134.0}/PKG-INFO +1 -1
- {interloper_api-0.133.0 → interloper_api-0.134.0}/pyproject.toml +1 -1
- {interloper_api-0.133.0 → interloper_api-0.134.0}/pyproject.toml.orig +1 -1
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/app.py +26 -7
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/admin.py +30 -1
- interloper_api-0.134.0/src/interloper_api/routes/extensions.py +112 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/README.md +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/__init__.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/authorization.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/cli.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/dependencies/__init__.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/dependencies/auth.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/dependencies/rbac.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/dependencies/state.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/extension.yaml +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/login.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/notifications/__init__.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/notifications/base.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/notifications/invitations.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/notifications/super_admins.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/__init__.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/agent.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/apps.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/auth.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/authorization.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/backfills.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/catalog.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/components.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/executions.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/health.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/oauth.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/organisations.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/overview.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/relations.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/runs.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/tokens.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/websocket.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/server.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/settings.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/utils/__init__.py +0 -0
- {interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/utils/time.py +0 -0
|
@@ -7,7 +7,7 @@ from collections.abc import AsyncGenerator
|
|
|
7
7
|
from contextlib import asynccontextmanager
|
|
8
8
|
from typing import Any
|
|
9
9
|
|
|
10
|
-
from fastapi import APIRouter, FastAPI, Request
|
|
10
|
+
from fastapi import APIRouter, Depends, FastAPI, Request
|
|
11
11
|
from fastapi.middleware.cors import CORSMiddleware
|
|
12
12
|
from fastapi.responses import JSONResponse
|
|
13
13
|
from interloper.catalog import Catalog
|
|
@@ -24,7 +24,7 @@ from interloper_db import (
|
|
|
24
24
|
from starlette.concurrency import run_in_threadpool
|
|
25
25
|
|
|
26
26
|
from interloper_api.authorization import AuthorizationServer, CrossOriginMiddleware
|
|
27
|
-
from interloper_api.dependencies import State
|
|
27
|
+
from interloper_api.dependencies import State, require_viewer
|
|
28
28
|
from interloper_api.login import GoogleLogin
|
|
29
29
|
from interloper_api.routes import (
|
|
30
30
|
admin,
|
|
@@ -34,6 +34,7 @@ from interloper_api.routes import (
|
|
|
34
34
|
backfills,
|
|
35
35
|
components,
|
|
36
36
|
executions,
|
|
37
|
+
extensions,
|
|
37
38
|
health,
|
|
38
39
|
oauth,
|
|
39
40
|
organisations,
|
|
@@ -49,7 +50,8 @@ from interloper_api.settings import ApiSettings
|
|
|
49
50
|
logger = logging.getLogger(__name__)
|
|
50
51
|
|
|
51
52
|
#: Routers mounted under ``/api`` for every deployment: the caller's own, the
|
|
52
|
-
#: organisation management and super-admin ones,
|
|
53
|
+
#: organisation management and super-admin ones, the installed extensions, a
|
|
54
|
+
#: run's ingest, and the probes.
|
|
53
55
|
_ROUTERS: tuple[APIRouter, ...] = (
|
|
54
56
|
auth.router,
|
|
55
57
|
authorization.router,
|
|
@@ -58,13 +60,14 @@ _ROUTERS: tuple[APIRouter, ...] = (
|
|
|
58
60
|
oauth.router,
|
|
59
61
|
tokens.router,
|
|
60
62
|
apps.router,
|
|
63
|
+
extensions.router,
|
|
61
64
|
runs.router,
|
|
62
65
|
health.router,
|
|
63
66
|
)
|
|
64
67
|
|
|
65
68
|
#: Routers acting in one organisation, mounted under ``/api/organisations/{org_id}``.
|
|
66
|
-
#: The agent
|
|
67
|
-
#: :func:`_mount_agent`.
|
|
69
|
+
#: The agent's and the extensions' are absent by design: they are optional and
|
|
70
|
+
#: mounted by :func:`_mount_agent` and :func:`_mount_extensions`.
|
|
68
71
|
_ORG_ROUTERS: tuple[APIRouter, ...] = (
|
|
69
72
|
organisations.org_router,
|
|
70
73
|
catalog_routes.org_router,
|
|
@@ -185,8 +188,9 @@ def create_app(
|
|
|
185
188
|
) -> FastAPI:
|
|
186
189
|
"""Create the FastAPI application with all routes.
|
|
187
190
|
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
The routes the installed packages declare mount under
|
|
192
|
+
``/api/organisations/{org_id}/ext/<name>``. On startup the application
|
|
193
|
+
promotes the configured super-admins and starts the realtime listener.
|
|
190
194
|
|
|
191
195
|
Args:
|
|
192
196
|
store: The ``Store`` instance for persistence.
|
|
@@ -227,6 +231,7 @@ def create_app(
|
|
|
227
231
|
for org_router in _ORG_ROUTERS:
|
|
228
232
|
api.include_router(org_router, prefix=ORG_PREFIX)
|
|
229
233
|
agent_model = _mount_agent(api, settings)
|
|
234
|
+
_mount_extensions(api)
|
|
230
235
|
app.include_router(api)
|
|
231
236
|
app.include_router(authorization.well_known_router)
|
|
232
237
|
|
|
@@ -294,6 +299,20 @@ def _mount_agent(api: APIRouter, settings: ApiSettings) -> str | None:
|
|
|
294
299
|
return settings.agent.model
|
|
295
300
|
|
|
296
301
|
|
|
302
|
+
def _mount_extensions(api: APIRouter) -> None:
|
|
303
|
+
"""Mount every router the installed packages declare, the viewer role its floor.
|
|
304
|
+
|
|
305
|
+
A router that fails to load is skipped and recorded, so the listing and
|
|
306
|
+
the configuration page name it while every other one serves.
|
|
307
|
+
|
|
308
|
+
Args:
|
|
309
|
+
api: The ``/api`` router to mount onto.
|
|
310
|
+
"""
|
|
311
|
+
for name, router in extensions.EXTENSION_ROUTERS.items():
|
|
312
|
+
api.include_router(router, prefix=f"{ORG_PREFIX}/ext/{name}", dependencies=[Depends(require_viewer)])
|
|
313
|
+
logger.info("Extension routes '%s' mounted at /api%s/ext/%s.", name, ORG_PREFIX, name)
|
|
314
|
+
|
|
315
|
+
|
|
297
316
|
def _state(
|
|
298
317
|
store: Store,
|
|
299
318
|
catalog: Catalog,
|
|
@@ -13,6 +13,7 @@ from __future__ import annotations
|
|
|
13
13
|
|
|
14
14
|
import datetime as dt
|
|
15
15
|
import inspect
|
|
16
|
+
from collections.abc import Iterable
|
|
16
17
|
from datetime import datetime
|
|
17
18
|
from importlib import metadata
|
|
18
19
|
from typing import Annotated, Any
|
|
@@ -21,6 +22,7 @@ from uuid import UUID
|
|
|
21
22
|
from authlib.oauth2.rfc7591 import InvalidRedirectURIError
|
|
22
23
|
from fastapi import APIRouter, HTTPException, Query, Request, Response
|
|
23
24
|
from interloper.catalog import Catalog
|
|
25
|
+
from interloper.extension import MANIFESTS, Extension, ExtensionFailure
|
|
24
26
|
from interloper.settings import SETTINGS, Settings
|
|
25
27
|
from interloper_db import Organisation, OrganisationQuery, Page, PageQuery, Profile, ProfileQuery, UsageQuery
|
|
26
28
|
from interloper_db.models import OAuthClient
|
|
@@ -32,6 +34,7 @@ from interloper_api.authorization import CLIENT_NAME_MAX_LENGTH, Client
|
|
|
32
34
|
from interloper_api.dependencies import SettingsDep, StateDep, StoreDep, SuperAdminDep
|
|
33
35
|
from interloper_api.notifications import SuperAdminPromotionEmail
|
|
34
36
|
from interloper_api.routes.apps import AppResponse
|
|
37
|
+
from interloper_api.routes.extensions import ExtensionResponse
|
|
35
38
|
from interloper_api.routes.organisations import CreateOrganisationRequest
|
|
36
39
|
|
|
37
40
|
router = APIRouter(prefix="/admin", tags=["admin"])
|
|
@@ -246,6 +249,26 @@ class AdminSettingsSection(BaseModel):
|
|
|
246
249
|
return True, value
|
|
247
250
|
|
|
248
251
|
|
|
252
|
+
class AdminExtension(ExtensionResponse):
|
|
253
|
+
"""One installed package that ships a manifest, with everything skipped of it and why."""
|
|
254
|
+
|
|
255
|
+
failures: list[ExtensionFailure]
|
|
256
|
+
|
|
257
|
+
@classmethod
|
|
258
|
+
def from_extension(cls, extension: Extension, failures: Iterable[ExtensionFailure]) -> AdminExtension:
|
|
259
|
+
"""Describe an installed package with its own failures.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
extension: The package, as its manifest says what it is.
|
|
263
|
+
failures: Everything skipped so far, every package's.
|
|
264
|
+
|
|
265
|
+
Returns:
|
|
266
|
+
The package and the failures that are its own, in the order they happened.
|
|
267
|
+
"""
|
|
268
|
+
own = [failure for failure in failures if failure.package == extension.package]
|
|
269
|
+
return cls(**ExtensionResponse.from_extension(extension, own).model_dump(), failures=own)
|
|
270
|
+
|
|
271
|
+
|
|
249
272
|
# One set of quota limits, keyed by quota key; null means unlimited (or unset,
|
|
250
273
|
# for overrides). Derived from the ``QUOTAS`` registry rather than declared
|
|
251
274
|
# field-by-field, so registering a quota surfaces it here — and in the frontend,
|
|
@@ -364,6 +387,7 @@ class AdminConfigResponse(BaseModel):
|
|
|
364
387
|
features: dict[str, bool]
|
|
365
388
|
catalog: dict[str, list[str]]
|
|
366
389
|
sections: list[AdminSettingsSection]
|
|
390
|
+
extensions: list[AdminExtension]
|
|
367
391
|
|
|
368
392
|
@classmethod
|
|
369
393
|
def from_declared(cls, features: dict[str, bool], catalog: Catalog) -> AdminConfigResponse:
|
|
@@ -375,7 +399,10 @@ class AdminConfigResponse(BaseModel):
|
|
|
375
399
|
cannot be imported is left out. The catalog is reported from the
|
|
376
400
|
hydrated ``Catalog`` (the enabled components, their dependencies and
|
|
377
401
|
the framework's own), not the ``catalog.include`` setting, which only
|
|
378
|
-
holds the explicitly configured import paths.
|
|
402
|
+
holds the explicitly configured import paths. The extensions are the
|
|
403
|
+
installed packages with what was skipped of them by the time the
|
|
404
|
+
snapshot is built, which ``create_app`` does once the catalog is
|
|
405
|
+
hydrated and the extension routes are mounted.
|
|
379
406
|
|
|
380
407
|
Args:
|
|
381
408
|
features: Optional-feature flags keyed by feature name.
|
|
@@ -393,11 +420,13 @@ class AdminConfigResponse(BaseModel):
|
|
|
393
420
|
settings_class = SETTINGS.get(name)
|
|
394
421
|
if settings_class is not None:
|
|
395
422
|
sections.append(AdminSettingsSection.from_settings(name, entry.extension, settings_class.get()))
|
|
423
|
+
failures = MANIFESTS.failures
|
|
396
424
|
return cls(
|
|
397
425
|
version=version,
|
|
398
426
|
features=features,
|
|
399
427
|
catalog=_catalog_by_kind(catalog),
|
|
400
428
|
sections=sections,
|
|
429
|
+
extensions=[AdminExtension.from_extension(extension, failures) for extension in MANIFESTS.extensions()],
|
|
401
430
|
)
|
|
402
431
|
|
|
403
432
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Extension routes: the HTTP routes installed packages declare, and the listing of those packages.
|
|
2
|
+
|
|
3
|
+
A package adds routes by naming an ``APIRouter`` in the ``routes`` section of
|
|
4
|
+
its manifest:
|
|
5
|
+
|
|
6
|
+
```yaml
|
|
7
|
+
routes: acme_interloper.routes:router
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
The router answers under ``/api/organisations/{org_id}/ext/<name>``, where
|
|
11
|
+
``<name>`` is the entry's name: the extension's key for a single import
|
|
12
|
+
string. The viewer role in the organisation the path names is the floor of
|
|
13
|
+
every route; a route that writes raises it with ``EditorDep``. The routes
|
|
14
|
+
reuse the API's dependencies (``StoreDep``, ``ViewerDep``, ``EditorDep``,
|
|
15
|
+
``load_authorized``), and the contract that keeps one organisation's data
|
|
16
|
+
from another is the author's: every row carries ``org_id``, and a fetch by id
|
|
17
|
+
goes through ``load_authorized``.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import re
|
|
23
|
+
from collections.abc import Iterable
|
|
24
|
+
from typing import Any, Literal
|
|
25
|
+
|
|
26
|
+
from fastapi import APIRouter
|
|
27
|
+
from interloper.extension import MANIFESTS, Extension, ExtensionFailure
|
|
28
|
+
from interloper.registry import Registry
|
|
29
|
+
from pydantic import BaseModel
|
|
30
|
+
|
|
31
|
+
from interloper_api.dependencies import CurrentUserDep
|
|
32
|
+
|
|
33
|
+
_NAME_PATTERN = re.compile(r"[a-z][a-z0-9_]*")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _adopt_router(name: str, loaded: Any) -> tuple[str, APIRouter]:
|
|
37
|
+
"""Accept a declared router, its name the path segment it answers under.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
name: The entry's name.
|
|
41
|
+
loaded: What the entry's import string names.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
The name and the router.
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
ValueError: If the name is not a lowercase identifier.
|
|
48
|
+
TypeError: If the entry names something other than an ``APIRouter``.
|
|
49
|
+
"""
|
|
50
|
+
if not _NAME_PATTERN.fullmatch(name):
|
|
51
|
+
raise ValueError(f"'{name}' is not a lowercase identifier, which the path segment must be")
|
|
52
|
+
if not isinstance(loaded, APIRouter):
|
|
53
|
+
raise TypeError(f"'{name}' names a {type(loaded).__name__}, not an APIRouter")
|
|
54
|
+
return name, loaded
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
EXTENSION_ROUTERS: Registry[APIRouter] = Registry("routes", adopt=_adopt_router)
|
|
58
|
+
|
|
59
|
+
router = APIRouter(tags=["extensions"])
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ExtensionResponse(BaseModel):
|
|
63
|
+
"""One installed package that ships a manifest, and whether everything it declares loaded.
|
|
64
|
+
|
|
65
|
+
``status`` is ``failed`` when anything the package declares was skipped:
|
|
66
|
+
its manifest, a section or an entry. The failures themselves are shown
|
|
67
|
+
to super-admins only, on the configuration page.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
package: str
|
|
71
|
+
key: str | None
|
|
72
|
+
name: str
|
|
73
|
+
description: str
|
|
74
|
+
icon: str
|
|
75
|
+
version: str | None
|
|
76
|
+
status: Literal["ok", "failed"]
|
|
77
|
+
|
|
78
|
+
@classmethod
|
|
79
|
+
def from_extension(cls, extension: Extension, failures: Iterable[ExtensionFailure]) -> ExtensionResponse:
|
|
80
|
+
"""Describe an installed package from its manifest and what was skipped of it.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
extension: The package, as its manifest says what it is.
|
|
84
|
+
failures: Everything skipped so far, every package's.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
The package, ``failed`` when one of the failures is its own.
|
|
88
|
+
"""
|
|
89
|
+
failed = any(failure.package == extension.package for failure in failures)
|
|
90
|
+
return cls(
|
|
91
|
+
package=extension.package,
|
|
92
|
+
key=extension.key,
|
|
93
|
+
name=extension.name,
|
|
94
|
+
description=extension.description,
|
|
95
|
+
icon=extension.icon,
|
|
96
|
+
version=extension.version,
|
|
97
|
+
status="failed" if failed else "ok",
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@router.get("/extensions")
|
|
102
|
+
def list_extensions(user: CurrentUserDep) -> list[ExtensionResponse]:
|
|
103
|
+
"""List the installed packages that ship a manifest, the platform's own included.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
user: The authenticated caller; any signed-in user may read the listing.
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
The packages, sorted by package.
|
|
110
|
+
"""
|
|
111
|
+
failures = MANIFESTS.failures
|
|
112
|
+
return [ExtensionResponse.from_extension(extension, failures) for extension in MANIFESTS.extensions()]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/dependencies/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/notifications/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/notifications/invitations.py
RENAMED
|
File without changes
|
{interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/notifications/super_admins.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/authorization.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{interloper_api-0.133.0 → interloper_api-0.134.0}/src/interloper_api/routes/organisations.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|