Fixed formatting
All checks were successful
Build on push / prepare (push) Successful in 9s
Build on push / core (push) Successful in 17s
Build on push / query (push) Successful in 17s
Build on push / dependency (push) Successful in 17s
Build on push / translation (push) Successful in 14s
Build on push / application (push) Successful in 18s
Build on push / database (push) Successful in 17s
Build on push / mail (push) Successful in 18s
Build on push / auth (push) Successful in 13s
Build on push / api (push) Successful in 17s
Test before pr merge / test-lint (pull_request) Successful in 5s
All checks were successful
Build on push / prepare (push) Successful in 9s
Build on push / core (push) Successful in 17s
Build on push / query (push) Successful in 17s
Build on push / dependency (push) Successful in 17s
Build on push / translation (push) Successful in 14s
Build on push / application (push) Successful in 18s
Build on push / database (push) Successful in 17s
Build on push / mail (push) Successful in 18s
Build on push / auth (push) Successful in 13s
Build on push / api (push) Successful in 17s
Test before pr merge / test-lint (pull_request) Successful in 5s
This commit is contained in:
@@ -1,20 +1,26 @@
|
|||||||
from cpl.dependency.service_collection import ServiceCollection as _ServiceCollection
|
from cpl.dependency.service_collection import ServiceCollection as _ServiceCollection
|
||||||
|
|
||||||
|
|
||||||
def add_api(collection: _ServiceCollection):
|
def add_api(collection: _ServiceCollection):
|
||||||
try:
|
try:
|
||||||
from cpl.database import mysql
|
from cpl.database import mysql
|
||||||
|
|
||||||
collection.add_module(mysql)
|
collection.add_module(mysql)
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
from cpl.core.errors import dependency_error
|
from cpl.core.errors import dependency_error
|
||||||
|
|
||||||
dependency_error("cpl-database", e)
|
dependency_error("cpl-database", e)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from cpl import auth
|
from cpl import auth
|
||||||
from cpl.auth import permission
|
from cpl.auth import permission
|
||||||
|
|
||||||
collection.add_module(auth)
|
collection.add_module(auth)
|
||||||
collection.add_module(permission)
|
collection.add_module(permission)
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
from cpl.core.errors import dependency_error
|
from cpl.core.errors import dependency_error
|
||||||
|
|
||||||
dependency_error("cpl-auth", e)
|
dependency_error("cpl-auth", e)
|
||||||
|
|
||||||
_ServiceCollection.with_module(add_api, __name__)
|
|
||||||
|
_ServiceCollection.with_module(add_api, __name__)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from cpl.api.middleware.request import get_request
|
|||||||
|
|
||||||
_logger = APILogger(__name__)
|
_logger = APILogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LoggingMiddleware(ASGIMiddleware):
|
class LoggingMiddleware(ASGIMiddleware):
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
@@ -83,4 +84,4 @@ class LoggingMiddleware(ASGIMiddleware):
|
|||||||
async def _log_after_request(request: Request, status_code: int, duration: float):
|
async def _log_after_request(request: Request, status_code: int, duration: float):
|
||||||
_logger.info(
|
_logger.info(
|
||||||
f"Request finished {getattr(request.state, 'request_id', '-')}: {status_code}-{request.method}@{request.url.path} from {request.client.host} in {duration:.2f}ms"
|
f"Request finished {getattr(request.state, 'request_id', '-')}: {status_code}-{request.method}@{request.url.path} from {request.client.host} in {duration:.2f}ms"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -51,4 +51,4 @@ class RequestMiddleware(ASGIMiddleware):
|
|||||||
|
|
||||||
|
|
||||||
def get_request() -> Optional[Union[TRequest, WebSocket]]:
|
def get_request() -> Optional[Union[TRequest, WebSocket]]:
|
||||||
return _request_context.get()
|
return _request_context.get()
|
||||||
|
|||||||
@@ -175,11 +175,7 @@ class WebApp(ApplicationABC):
|
|||||||
# )
|
# )
|
||||||
|
|
||||||
config = uvicorn.Config(
|
config = uvicorn.Config(
|
||||||
app,
|
app, host=self._api_settings.host, port=self._api_settings.port, log_config=None, loop="asyncio"
|
||||||
host=self._api_settings.host,
|
|
||||||
port=self._api_settings.port,
|
|
||||||
log_config=None,
|
|
||||||
loop="asyncio"
|
|
||||||
)
|
)
|
||||||
server = uvicorn.Server(config)
|
server = uvicorn.Server(config)
|
||||||
await server.serve()
|
await server.serve()
|
||||||
|
|||||||
@@ -24,10 +24,9 @@ class ApplicationABC(ABC):
|
|||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self, services: ServiceProviderABC, required_modules: list[str | object] = None):
|
def __init__(self, services: ServiceProviderABC, required_modules: list[str | object] = None):
|
||||||
self._services = services
|
self._services = services
|
||||||
self._required_modules = [
|
self._required_modules = (
|
||||||
x.__name__ if not isinstance(x, str) else x
|
[x.__name__ if not isinstance(x, str) else x for x in required_modules] if required_modules else []
|
||||||
for x in required_modules
|
)
|
||||||
] if required_modules else []
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def required_modules(self) -> list[str]:
|
def required_modules(self) -> list[str]:
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ def add_auth(collection: _ServiceCollection):
|
|||||||
migration_service.with_directory(os.path.join(os.path.dirname(os.path.realpath(__file__)), "scripts/mysql"))
|
migration_service.with_directory(os.path.join(os.path.dirname(os.path.realpath(__file__)), "scripts/mysql"))
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
from cpl.core.console import Console
|
from cpl.core.console import Console
|
||||||
|
|
||||||
Console.error("cpl-database is not installed", str(e))
|
Console.error("cpl-database is not installed", str(e))
|
||||||
|
|
||||||
|
|
||||||
@@ -69,6 +70,7 @@ def add_permission(collection: _ServiceCollection):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from cpl.database.abc.data_seeder_abc import DataSeederABC
|
from cpl.database.abc.data_seeder_abc import DataSeederABC
|
||||||
|
|
||||||
collection.add_singleton(DataSeederABC, PermissionSeeder)
|
collection.add_singleton(DataSeederABC, PermissionSeeder)
|
||||||
PermissionsRegistry.with_enum(Permissions)
|
PermissionsRegistry.with_enum(Permissions)
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
|
|||||||
@@ -22,4 +22,4 @@ class KeycloakClient(KeycloakOpenID):
|
|||||||
|
|
||||||
def get_user_id(self, token: str) -> Optional[str]:
|
def get_user_id(self, token: str) -> Optional[str]:
|
||||||
info = self.introspect(token)
|
info = self.introspect(token)
|
||||||
return info.get("sub", None)
|
return info.get("sub", None)
|
||||||
|
|||||||
@@ -12,4 +12,4 @@ def dependency_error(package_name: str, e: ImportError) -> None:
|
|||||||
elif e is not None:
|
elif e is not None:
|
||||||
Console.write_line("->", str(e))
|
Console.write_line("->", str(e))
|
||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from cpl.database.model import DatabaseSettings
|
|||||||
|
|
||||||
_logger = DBLogger(__name__)
|
_logger = DBLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MySQLPool:
|
class MySQLPool:
|
||||||
|
|
||||||
def __init__(self, database_settings: DatabaseSettings):
|
def __init__(self, database_settings: DatabaseSettings):
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ class ServiceProviderABC(ABC):
|
|||||||
return functools.partial(cls.inject)
|
return functools.partial(cls.inject)
|
||||||
|
|
||||||
if iscoroutinefunction(f):
|
if iscoroutinefunction(f):
|
||||||
|
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
async def async_inner(*args, **kwargs):
|
async def async_inner(*args, **kwargs):
|
||||||
if cls._provider is None:
|
if cls._provider is None:
|
||||||
@@ -132,4 +133,5 @@ class ServiceProviderABC(ABC):
|
|||||||
|
|
||||||
injection = [x for x in cls._provider._build_by_signature(signature(f)) if x is not None]
|
injection = [x for x in cls._provider._build_by_signature(signature(f)) if x is not None]
|
||||||
return f(*args, *injection, **kwargs)
|
return f(*args, *injection, **kwargs)
|
||||||
|
|
||||||
return inner
|
return inner
|
||||||
|
|||||||
Reference in New Issue
Block a user