88import urllib .parse
99import warnings
1010from contextlib import asynccontextmanager
11- from functools import cache , partial
11+ from functools import partial
1212from pathlib import Path
1313from typing import Any , Optional
1414
@@ -288,7 +288,7 @@ async def unhandled_exception_handler(
288288 serialization_registry ,
289289 deserialization_registry ,
290290 validation_registry ,
291- authenticators ,
291+ server_settings . authenticators ,
292292 )
293293 app .include_router (router , prefix = "/api/v1" )
294294
@@ -299,7 +299,7 @@ async def unhandled_exception_handler(
299299 for custom_router in getattr (tree , "include_routers" , []):
300300 app .include_router (custom_router , prefix = "/api/v1" )
301301
302- if authentication . get ( "providers" , []) :
302+ if server_settings . authenticators :
303303 # Delay this imports to avoid delaying startup with the SQL and cryptography
304304 # imports if they are not needed.
305305 from .authentication import (
@@ -310,7 +310,7 @@ async def unhandled_exception_handler(
310310 )
311311
312312 # For the OpenAPI schema, inject a OAuth2PasswordBearer URL.
313- first_provider = authentication [ "providers" ][ 0 ][ "provider" ]
313+ first_provider = list ( server_settings . authenticators )[ 0 ]
314314 oauth2_scheme .model .flows .password .tokenUrl = (
315315 f"/api/v1/auth/provider/{ first_provider } /token"
316316 )
@@ -337,51 +337,6 @@ async def unhandled_exception_handler(
337337 else :
338338 app .state .authenticated = False
339339
340- @cache
341- def override_get_root_tree ():
342- return tree
343-
344- @cache
345- def override_get_settings ():
346- settings = get_settings ()
347- for item in [
348- "allow_anonymous_access" ,
349- "secret_keys" ,
350- "single_user_api_key" ,
351- "access_token_max_age" ,
352- "refresh_token_max_age" ,
353- "session_max_age" ,
354- ]:
355- if authentication .get (item ) is not None :
356- setattr (settings , item , authentication [item ])
357- for item in [
358- "allow_origins" ,
359- "response_bytesize_limit" ,
360- "reject_undeclared_specs" ,
361- "expose_raw_assets" ,
362- ]:
363- if server_settings .get (item ) is not None :
364- setattr (settings , item , server_settings [item ])
365- database = server_settings .get ("database" , {})
366- if uri := database .get ("uri" ):
367- settings .database_settings .uri = uri
368- if pool_size := database .get ("pool_size" ):
369- settings .database_settings .pool_size = pool_size
370- if pool_pre_ping := database .get ("pool_pre_ping" ):
371- settings .database_settings .pool_pre_ping = pool_pre_ping
372- if max_overflow := database .get ("max_overflow" ):
373- settings .database_settings .max_overflow = max_overflow
374- if init_if_not_exists := database .get ("init_if_not_exists" ):
375- settings .database_init_if_not_exists = init_if_not_exists
376- if authentication .get ("providers" ):
377- # If we support authentication providers, we need a database, so if one is
378- # not set, use a SQLite database in memory. Horizontally scaled deployments
379- # must specify a persistent database.
380- settings .database_settings .uri = (
381- settings .database_settings .uri or "sqlite://"
382- )
383- return settings
384-
385340 async def startup_event ():
386341 from .. import __version__
387342
@@ -522,17 +477,17 @@ async def startup_event():
522477 raise err from None
523478 else :
524479 logger .info (f"Connected to existing database at { redacted_url } ." )
525- for admin in authentication . get ( "tiled_admins" , []) :
480+ for admin in server_settings . admins :
526481 logger .info (
527- f"Ensuring that principal with identity { admin } has role 'admin'"
482+ f"Ensuring that principal with identity { admin . id } has role 'admin'"
528483 )
529484 async with AsyncSession (
530485 engine , autoflush = False , expire_on_commit = False
531486 ) as session :
532487 await make_admin_by_identity (
533488 session ,
534- identity_provider = admin [ " provider" ] ,
535- id = admin [ "id" ] ,
489+ identity_provider = admin . provider ,
490+ id = admin . id ,
536491 )
537492
538493 async def purge_expired_sessions_and_api_keys ():
@@ -664,8 +619,6 @@ async def set_cookies(request: Request, call_next):
664619 return response
665620
666621 app .openapi = partial (custom_openapi , app )
667- app .dependency_overrides [get_root_tree ] = override_get_root_tree
668- app .dependency_overrides [get_settings ] = override_get_settings
669622
670623 @app .middleware ("http" )
671624 async def capture_metrics (request : Request , call_next ):
0 commit comments