-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update sqlalchemy to use standard api instead of async one, sta…
- Loading branch information
1 parent
344e0a7
commit c30117c
Showing
16 changed files
with
316 additions
and
420 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
from http import HTTPStatus | ||
from typing import Annotated | ||
from fastapi import Depends, Request | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from sqlalchemy.orm import Session | ||
|
||
from regtech_user_fi_management.entities.engine.engine import get_session | ||
import regtech_user_fi_management.entities.repos.institutions_repo as repo | ||
from regtech_api_commons.api.exceptions import RegTechHttpException | ||
from regtech_api_commons.api.dependencies import get_email_domain | ||
|
||
|
||
async def check_domain(request: Request, session: Annotated[AsyncSession, Depends(get_session)]) -> None: | ||
def check_domain(request: Request, session: Annotated[Session, Depends(get_session)]) -> None: | ||
if not request.user.is_authenticated: | ||
raise RegTechHttpException( | ||
status_code=HTTPStatus.FORBIDDEN, name="Request Forbidden", detail="unauthenticated user" | ||
) | ||
if await email_domain_denied(session, get_email_domain(request.user.email)): | ||
if email_domain_denied(session, get_email_domain(request.user.email)): | ||
raise RegTechHttpException( | ||
status_code=HTTPStatus.FORBIDDEN, name="Request Forbidden", detail="email domain denied" | ||
) | ||
|
||
|
||
async def email_domain_denied(session: AsyncSession, email: str) -> bool: | ||
return not await repo.is_domain_allowed(session, email) | ||
def email_domain_denied(session: Session, email: str) -> bool: | ||
return not repo.is_domain_allowed(session, email) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
from sqlalchemy.ext.asyncio import ( | ||
create_async_engine, | ||
async_sessionmaker, | ||
async_scoped_session, | ||
) | ||
from asyncio import current_task | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import scoped_session, sessionmaker | ||
from regtech_user_fi_management.config import settings | ||
|
||
engine = create_async_engine(str(settings.inst_conn), echo=settings.db_logging).execution_options( | ||
engine = create_engine(str(settings.inst_conn), echo=settings.db_logging).execution_options( | ||
schema_translate_map={None: settings.inst_db_schema} | ||
) | ||
SessionLocal = async_scoped_session(async_sessionmaker(engine, expire_on_commit=False), current_task) | ||
SessionLocal = scoped_session(sessionmaker(engine, expire_on_commit=False)) | ||
|
||
|
||
async def get_session(): | ||
def get_session(): | ||
session = SessionLocal() | ||
try: | ||
yield session | ||
finally: | ||
await session.close() | ||
session.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 1 addition & 10 deletions
11
src/regtech_user_fi_management/entities/repos/repo_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.