1
0
Fork 0
forked from sr2/cloud-api

minor: ruff format

Tabs -> spaces
This commit is contained in:
Chris Milne 2026-06-22 15:04:11 +01:00
parent b2921b73b8
commit fab228bf8f
56 changed files with 3629 additions and 3630 deletions

View file

@ -1,6 +1,7 @@
""" """
Database connection and session utilities Database connection and session utilities
""" """
from contextlib import contextmanager from contextlib import contextmanager
from typing import Annotated, Generator from typing import Annotated, Generator
from sqlalchemy import create_engine, StaticPool, Connection from sqlalchemy import create_engine, StaticPool, Connection
@ -29,6 +30,7 @@ else:
sm = sessionmaker(autocommit=False, expire_on_commit=False, bind=engine) sm = sessionmaker(autocommit=False, expire_on_commit=False, bind=engine)
@contextmanager @contextmanager
def get_db_connection() -> Generator[Connection, None, None]: def get_db_connection() -> Generator[Connection, None, None]:
with engine.connect() as connection: with engine.connect() as connection:
@ -38,12 +40,15 @@ def get_db_connection() -> Generator[Connection, None, None]:
connection.rollback() connection.rollback()
raise raise
def _get_db_connection() -> Generator[Connection, None]: def _get_db_connection() -> Generator[Connection, None]:
with get_db_connection() as connection: with get_db_connection() as connection:
yield connection yield connection
DbConnection = Annotated[Connection, Depends(_get_db_connection)] DbConnection = Annotated[Connection, Depends(_get_db_connection)]
@contextmanager @contextmanager
def get_db_session() -> Generator[Session, None, None]: def get_db_session() -> Generator[Session, None, None]:
session = sm() session = sm()
@ -60,4 +65,5 @@ def _get_db_session() -> Generator[Session, None]:
with get_db_session() as session: with get_db_session() as session:
yield session yield session
DbSession = Annotated[Session, Depends(_get_db_session)] DbSession = Annotated[Session, Depends(_get_db_session)]

View file

@ -18,9 +18,7 @@ from src.iam.exceptions import GroupNotFoundException, PermNotFoundException
from src.iam.schemas import GroupIDMixin, PermIDMixin from src.iam.schemas import GroupIDMixin, PermIDMixin
def get_group_model_query( def get_group_model_query(db: DbSession, group_id: Annotated[int, Query(gt=0)]) -> Group:
db: DbSession, group_id: Annotated[int, Query(gt=0)]
) -> Group:
group_model = db.get(Group, group_id) group_model = db.get(Group, group_id)
if group_model is None: if group_model is None:
raise GroupNotFoundException(group_id) raise GroupNotFoundException(group_id)
@ -63,9 +61,7 @@ def get_perm_model_body(
perm_model_body_dependency = Annotated[Permission, Depends(get_perm_model_body)] perm_model_body_dependency = Annotated[Permission, Depends(get_perm_model_body)]
def get_perm_model_query( def get_perm_model_query(db: DbSession, perm_id: Annotated[int, Query(gt=0)]) -> Permission:
db: DbSession, perm_id: Annotated[int, Query(gt=0)]
) -> Permission:
perm_model = db.get(Permission, perm_id) perm_model = db.get(Permission, perm_id)
if perm_model is None: if perm_model is None:
raise PermNotFoundException(perm_id) raise PermNotFoundException(perm_id)

View file

@ -468,9 +468,7 @@ async def remove_group_user(
}, },
}, },
) )
async def get_permissions( async def get_permissions(db: DbSession, org_model: org_model_root_claim_query_dependency):
db: DbSession, org_model: org_model_root_claim_query_dependency
):
""" """
Returns a full list of permissions. Returns a full list of permissions.
""" """

View file

@ -1,6 +1,7 @@
""" """
Application root file: Inits the FastAPI application Application root file: Inits the FastAPI application
""" """
import os.path import os.path
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from typing import AsyncGenerator from typing import AsyncGenerator

View file

@ -97,9 +97,7 @@ router = APIRouter(
}, },
}, },
) )
async def get_org_by_id( async def get_org_by_id(db: DbSession, org_model: org_model_root_claim_query_dependency):
db: DbSession, org_model: org_model_root_claim_query_dependency
):
""" """
Returns organisation details including key member email addresses Returns organisation details including key member email addresses
""" """

View file

@ -16,9 +16,7 @@ from src.service.models import Service
from src.service.schemas import ServiceIDMixin from src.service.schemas import ServiceIDMixin
async def get_service_model_query( async def get_service_model_query(db: DbSession, service_id: Annotated[int, Query(gt=0)]):
db: DbSession, service_id: Annotated[int, Query(gt=0)]
):
service_model = db.get(Service, service_id) service_model = db.get(Service, service_id)
if service_model is None: if service_model is None:
raise ServiceNotFoundException(service_id=service_id) raise ServiceNotFoundException(service_id=service_id)

View file

@ -76,9 +76,7 @@ router = APIRouter(
}, },
}, },
) )
async def get_all_services( async def get_all_services(db: DbSession, org_model: org_model_root_claim_query_dependency):
db: DbSession, org_model: org_model_root_claim_query_dependency
):
""" """
Returns the ID and name of all services registered to the hub. Returns the ID and name of all services registered to the hub.
""" """

View file

@ -57,6 +57,10 @@ async def send_email(recipient: str, subject: str, body: str):
.text(body) .text(body)
.send() .send()
) )
logging.info("Email sent to {} with subject {} (Status: {})".format(recipient, subject, response.status_code)) logging.info(
"Email sent to {} with subject {} (Status: {})".format(
recipient, subject, response.status_code
)
)
except ValidationError as e: except ValidationError as e:
logging.exception(e) logging.exception(e)