interloper-api 0.130.2__tar.gz → 0.132.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.
Files changed (38) hide show
  1. {interloper_api-0.130.2 → interloper_api-0.132.0}/PKG-INFO +1 -1
  2. {interloper_api-0.130.2 → interloper_api-0.132.0}/pyproject.toml +1 -1
  3. {interloper_api-0.130.2 → interloper_api-0.132.0}/pyproject.toml.orig +1 -1
  4. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/app.py +35 -3
  5. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/authorization.py +7 -10
  6. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/cli.py +6 -1
  7. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/dependencies/auth.py +3 -7
  8. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/login.py +2 -2
  9. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/admin.py +3 -5
  10. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/auth.py +1 -1
  11. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/catalog.py +7 -2
  12. {interloper_api-0.130.2 → interloper_api-0.132.0}/README.md +0 -0
  13. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/__init__.py +0 -0
  14. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/dependencies/__init__.py +0 -0
  15. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/dependencies/rbac.py +0 -0
  16. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/dependencies/state.py +0 -0
  17. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/notifications/__init__.py +0 -0
  18. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/notifications/base.py +0 -0
  19. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/notifications/invitations.py +0 -0
  20. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/notifications/super_admins.py +0 -0
  21. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/__init__.py +0 -0
  22. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/agent.py +0 -0
  23. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/apps.py +0 -0
  24. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/authorization.py +0 -0
  25. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/backfills.py +0 -0
  26. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/components.py +0 -0
  27. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/executions.py +0 -0
  28. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/health.py +0 -0
  29. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/oauth.py +0 -0
  30. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/organisations.py +0 -0
  31. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/overview.py +0 -0
  32. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/relations.py +0 -0
  33. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/runs.py +0 -0
  34. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/tokens.py +0 -0
  35. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/routes/websocket.py +0 -0
  36. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/server.py +0 -0
  37. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/utils/__init__.py +0 -0
  38. {interloper_api-0.130.2 → interloper_api-0.132.0}/src/interloper_api/utils/time.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: interloper-api
3
- Version: 0.130.2
3
+ Version: 0.132.0
4
4
  Summary: Interloper FastAPI routes
5
5
  Author: Guillaume Onfroy
6
6
  Author-email: Guillaume Onfroy <guillaume@digitlcloud.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "interloper-api"
3
- version = "0.130.2"
3
+ version = "0.132.0"
4
4
  description = "Interloper FastAPI routes"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -3,7 +3,7 @@
3
3
  # ###############
4
4
  [project]
5
5
  name = "interloper-api"
6
- version = "0.130.2"
6
+ version = "0.132.0"
7
7
  description = "Interloper FastAPI routes"
8
8
  readme = "README.md"
9
9
  authors = [{ name = "Guillaume Onfroy", email = "guillaume@digitlcloud.com" }]
@@ -3,6 +3,8 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import logging
6
+ from collections.abc import AsyncIterator
7
+ from contextlib import asynccontextmanager
6
8
  from typing import Any
7
9
 
8
10
  from fastapi import APIRouter, FastAPI, Request
@@ -19,6 +21,7 @@ from interloper_db import (
19
21
  QuotaExceededError,
20
22
  Store,
21
23
  )
24
+ from starlette.concurrency import run_in_threadpool
22
25
 
23
26
  from interloper_api.authorization import AuthorizationServer, CrossOriginMiddleware
24
27
  from interloper_api.dependencies import State
@@ -181,6 +184,9 @@ def create_app(
181
184
  ) -> FastAPI:
182
185
  """Create the FastAPI application with all routes.
183
186
 
187
+ On startup the application promotes the configured super-admins and
188
+ starts the realtime listener.
189
+
184
190
  Args:
185
191
  store: The ``Store`` instance for persistence.
186
192
  catalog: Catalog instance.
@@ -196,7 +202,7 @@ def create_app(
196
202
  Returns:
197
203
  The configured FastAPI application.
198
204
  """
199
- app = FastAPI(title="Interloper API", lifespan=websocket.realtime_lifespan, **kwargs)
205
+ app = FastAPI(title="Interloper API", lifespan=_lifespan, **kwargs)
200
206
 
201
207
  install_error_handlers(app)
202
208
 
@@ -233,6 +239,32 @@ def create_app(
233
239
  # -- Internals -----------------------------------------------------------------
234
240
 
235
241
 
242
+ @asynccontextmanager
243
+ async def _lifespan(app: FastAPI) -> AsyncIterator[None]:
244
+ """Promote the configured super-admins, then serve with the realtime listener running.
245
+
246
+ ``auth.super_admin_emails`` is applied here as well as at login, so a
247
+ deployment shipping a new list promotes the profiles that already exist
248
+ without waiting for them to sign in again.
249
+
250
+ Args:
251
+ app: The application being started; its state carries the store and
252
+ the settings, and an app built without either promotes no one.
253
+
254
+ Yields:
255
+ None, while the application serves.
256
+ """
257
+ state: State = app.state.interloper
258
+ if state.store is not None and state.settings is not None:
259
+ promoted = await run_in_threadpool(
260
+ state.store.profiles.promote_super_admins, state.settings.auth.super_admin_emails
261
+ )
262
+ for profile in promoted:
263
+ logger.info("Promoted profile %s to super-admin.", profile.id)
264
+ async with websocket.realtime_lifespan(app):
265
+ yield
266
+
267
+
236
268
  def _mount_agent(api: APIRouter, settings: Any | None) -> bool:
237
269
  """Mount the optional agent routes, reporting whether they are available.
238
270
 
@@ -322,7 +354,7 @@ def _google_login(settings: Any | None) -> GoogleLogin | None:
322
354
  if settings is None:
323
355
  return None
324
356
  google_login = GoogleLogin.from_settings(settings)
325
- if google_login is None and settings.auth.google_client_id and not settings.secrets.encryption_key:
357
+ if google_login is None and settings.auth.google_client_id and not settings.encryption.key:
326
358
  logger.warning("Google login unavailable: INTERLOPER_ENCRYPTION_KEY is not configured.")
327
359
  return google_login
328
360
 
@@ -341,7 +373,7 @@ def _authorization_server(store: Store | None, settings: Any) -> AuthorizationSe
341
373
  """
342
374
  if store is None:
343
375
  return None
344
- if not settings.secrets.encryption_key:
376
+ if not settings.encryption.key:
345
377
  logger.warning("OAuth authorization server not mounted: INTERLOPER_ENCRYPTION_KEY is not configured.")
346
378
  return None
347
379
  try:
@@ -878,7 +878,6 @@ class AuthorizationServer(rfc6749.AuthorizationServer):
878
878
  store: Store,
879
879
  *,
880
880
  issuer: str,
881
- mcp_url: str,
882
881
  encryption_key: str,
883
882
  access_token_expiry: timedelta,
884
883
  ) -> None:
@@ -886,8 +885,8 @@ class AuthorizationServer(rfc6749.AuthorizationServer):
886
885
 
887
886
  Args:
888
887
  store: The store every hook reads and writes through.
889
- issuer: The public base URL of the app, the server's identifier.
890
- mcp_url: The MCP endpoint's public URL, the resource naming it.
888
+ issuer: The public base URL of the app: the server's identifier,
889
+ and the base of the API and MCP resources it issues tokens for.
891
890
  encryption_key: The instance's encryption secret, which seals the
892
891
  authorization request while the user decides.
893
892
  access_token_expiry: How long an access token stays valid.
@@ -895,7 +894,7 @@ class AuthorizationServer(rfc6749.AuthorizationServer):
895
894
  super().__init__()
896
895
  self.store = store
897
896
  self.issuer = issuer.rstrip("/")
898
- self.resources = {f"{self.issuer}/api": Audience.API, mcp_url.rstrip("/"): Audience.MCP}
897
+ self.resources = {audience.resource_url(self.issuer): audience for audience in (Audience.API, Audience.MCP)}
899
898
  self.access_token_expires_in = int(access_token_expiry.total_seconds())
900
899
  self._fernet = Fernet(derive_fernet_key(encryption_key))
901
900
  self.metadata = self._build_metadata()
@@ -910,7 +909,7 @@ class AuthorizationServer(rfc6749.AuthorizationServer):
910
909
  """Build the server from the application settings.
911
910
 
912
911
  The issuer is the app's public URL (``server.public_url``); the MCP
913
- resource is the one the MCP server advertises (``mcp.public_url``).
912
+ server derives the resource it advertises from the same setting.
914
913
 
915
914
  Args:
916
915
  store: The store every hook reads and writes through.
@@ -919,13 +918,11 @@ class AuthorizationServer(rfc6749.AuthorizationServer):
919
918
  Returns:
920
919
  The server.
921
920
  """
922
- issuer = settings.server.public_url
923
921
  return cls(
924
922
  store,
925
- issuer=issuer,
926
- mcp_url=settings.mcp.public_url(settings.server),
927
- encryption_key=settings.secrets.encryption_key,
928
- access_token_expiry=timedelta(minutes=settings.auth.access_token_expiry_minutes),
923
+ issuer=settings.server.public_url,
924
+ encryption_key=settings.encryption.key,
925
+ access_token_expiry=settings.auth.access_token_expiry,
929
926
  )
930
927
 
931
928
  # -- Framework -------------------------------------------------------------
@@ -59,7 +59,12 @@ def _cmd_api(args: argparse.Namespace) -> None:
59
59
  create_tables=not args.no_create_tables,
60
60
  )
61
61
  catalog = Catalog.from_settings()
62
- store = Store.from_settings(catalog=catalog)
62
+ store = Store.from_settings(
63
+ catalog=catalog,
64
+ session_expiry=settings.auth.session_expiry,
65
+ access_token_expiry=settings.auth.access_token_expiry,
66
+ refresh_token_expiry=settings.auth.refresh_token_expiry,
67
+ )
63
68
  port = settings.server.port if args.port is None else args.port
64
69
  Supervisor({"api": ApiServer.from_settings(settings, store=store, catalog=catalog, port=port)}).run()
65
70
 
@@ -11,14 +11,13 @@ run's pod authenticates as its run, with the run token, and nothing else.
11
11
  from __future__ import annotations
12
12
 
13
13
  from dataclasses import dataclass
14
- from datetime import timedelta
15
14
  from typing import Annotated
16
15
  from uuid import UUID
17
16
 
18
17
  from fastapi import Cookie, Depends, Header, HTTPException
19
18
  from interloper_db import Audience, NotFoundError, Organisation, Profile, Role, Run, Store, Token
20
19
 
21
- from interloper_api.dependencies.state import SettingsDep, StoreDep
20
+ from interloper_api.dependencies.state import StoreDep
22
21
 
23
22
 
24
23
  def bearer(authorization: str | None) -> str | None:
@@ -221,7 +220,6 @@ OrgDep = Annotated[OrgScope, Depends(get_org_scope)]
221
220
  def require_run(
222
221
  run_id: UUID,
223
222
  store: StoreDep,
224
- settings: SettingsDep,
225
223
  authorization: str | None = Header(default=None),
226
224
  ) -> Run:
227
225
  """Resolve the run a bearer run token stands for, and check it is the run the path names.
@@ -232,12 +230,10 @@ def require_run(
232
230
  Args:
233
231
  run_id: The run the path names.
234
232
  store: The Store instance.
235
- settings: The settings, whose run liveness a token outlives its run by:
236
- the heartbeat timeout, for a pod still delivering after its reaping.
237
233
  authorization: The ``Authorization`` header.
238
234
 
239
235
  Returns:
240
- The run, dispatched, running, or ended within the grace.
236
+ The run, dispatched, running, or ended within the grace its token carries.
241
237
 
242
238
  Raises:
243
239
  HTTPException: 401 without a live run token; 404 when the token's run
@@ -246,7 +242,7 @@ def require_run(
246
242
  token = bearer(authorization)
247
243
  if not token:
248
244
  raise HTTPException(status_code=401, detail="Run token required")
249
- run = store.runs.resolve_token(token, grace=timedelta(seconds=settings.reaper.heartbeat_timeout))
245
+ run = store.runs.resolve_token(token)
250
246
  if run is None:
251
247
  raise HTTPException(status_code=401, detail="Unknown or expired run token")
252
248
  if run.id != run_id:
@@ -155,13 +155,13 @@ class GoogleLogin:
155
155
  is configured.
156
156
  """
157
157
  auth = settings.auth
158
- if not auth.google_client_id or not auth.google_client_secret or not settings.secrets.encryption_key:
158
+ if not auth.google_client_id or not auth.google_client_secret or not settings.encryption.key:
159
159
  return None
160
160
  return cls(
161
161
  client_id=auth.google_client_id,
162
162
  client_secret=auth.google_client_secret,
163
163
  redirect_uri=auth.google_redirect_uri,
164
- encryption_key=settings.secrets.encryption_key,
164
+ encryption_key=settings.encryption.key,
165
165
  cookie_secure=auth.cookie_secure,
166
166
  )
167
167
 
@@ -269,7 +269,6 @@ class AdminServicesConfig(BaseModel):
269
269
  smtp: AdminSmtpConfig
270
270
  telemetry: AdminTelemetryConfig
271
271
  app_external_url: str
272
- mcp_external_url: str
273
272
 
274
273
 
275
274
  class AdminDataConfig(BaseModel):
@@ -407,7 +406,7 @@ class AdminConfigResponse(BaseModel):
407
406
  settings fields default to *not exposed* and secrets only ever surface as
408
407
  "configured" booleans. The catalog is reported from the hydrated ``Catalog``
409
408
  (the enabled components, their dependencies and the framework's own), not
410
- ``settings.catalog``, which only holds the explicitly configured import paths.
409
+ ``settings.catalog.include``, which only holds the explicitly configured import paths.
411
410
 
412
411
  Args:
413
412
  settings: The instance settings the snapshot reads from.
@@ -497,10 +496,9 @@ class AdminConfigResponse(BaseModel):
497
496
  sample_ratio=settings.otel.sample_ratio,
498
497
  ),
499
498
  app_external_url=settings.server.external_url,
500
- mcp_external_url=settings.mcp.external_url,
501
499
  ),
502
500
  data=AdminDataConfig(
503
- encryption_configured=bool(settings.secrets.encryption_key),
501
+ encryption_configured=bool(settings.encryption.key),
504
502
  catalog=_catalog_by_kind(catalog) if catalog is not None else {},
505
503
  ),
506
504
  quotas=_quota_limits(settings.quota),
@@ -874,7 +872,7 @@ def update_user(
874
872
 
875
873
  A promotion emails every super-admin, the new one included, so a grant
876
874
  never goes unnoticed. A revocation is refused for an email listed in
877
- ``auth.super_admin_emails``: the next login or ``db init`` would promote
875
+ ``auth.super_admin_emails``: the next login or API start would promote
878
876
  it straight back.
879
877
 
880
878
  Args:
@@ -223,7 +223,7 @@ def _sign_in(account: GoogleAccount, destination: str, store: Store, auth_config
223
223
  httponly=True,
224
224
  samesite="lax",
225
225
  secure=auth_config.cookie_secure,
226
- max_age=auth_config.session_expiry_days * 86400,
226
+ max_age=int(auth_config.session_expiry.total_seconds()),
227
227
  path="/",
228
228
  )
229
229
  return response
@@ -16,7 +16,7 @@ import httpx2
16
16
  import interloper as il
17
17
  from fastapi import APIRouter, Depends, HTTPException
18
18
  from interloper.connection import CheckResult, Connection
19
- from interloper.errors import format_exception
19
+ from interloper.errors import ConnectionCheckError, format_exception
20
20
  from interloper.resource import is_fetch_field_provider
21
21
  from interloper.utils import import_from_path, invoke
22
22
  from pydantic import BaseModel, Field, ValidationError
@@ -77,7 +77,9 @@ def handle_error(error: Exception, context: str) -> NoReturn:
77
77
 
78
78
  Raises:
79
79
  HTTPException: Always — *error* re-raised as-is when it already is
80
- one, otherwise the status mapped from it, or 500 by default.
80
+ one, otherwise the status mapped from it, or 500 by default. A
81
+ `ConnectionCheckError` keeps its curated message as the detail;
82
+ any other error's own message never reaches the response.
81
83
  """
82
84
  logger.error("Error %s: %s", context, error)
83
85
 
@@ -91,6 +93,9 @@ def handle_error(error: Exception, context: str) -> NoReturn:
91
93
  if isinstance(error, HTTPException):
92
94
  raise error
93
95
 
96
+ if isinstance(error, ConnectionCheckError):
97
+ raise HTTPException(status_code=500, detail=str(error))
98
+
94
99
  raise HTTPException(status_code=500, detail=f"Failed {context}.")
95
100
 
96
101