py-scopes/scopes/api/deps.py

37 lines
881 B
Python

# scopes.api.deps
"""Common dependencies and other definitions for Web API"""
from fastapi import Depends
from typing import Annotated
from scopes import config
from scopes.api.auth import config as auth_config
from scopes.storage import common
from scopes.storage import user as st_user
type Storage = Annotated[common.Storage, Depends(storage)]
type Users = Annotated[st_user.Users, Depends(users)]
type AuthUser = Annotated[str, Depends(auth_user)]
type AuthToken = Annotated[str, Depends(auth_token)]
# storage
def storage():
stf = config.StorageFactory(config.settings)
return stf(config.settings.dbschema)
def users(storage: Storage):
return storage.create(st_user.Users)
# auth
def auth_user():
auth = auth_config.auth_methods.get(auth_config.settings.auth_method)
if auth is not None:
return auth()
def auth_token():
return None