Commit 82dc77b4 authored by Volodymyr Kovalenko's avatar Volodymyr Kovalenko Committed by mashony
Browse files

refactored aiotask_context, logger

parent 7c99a3cb
......@@ -5,12 +5,12 @@ import os
from aiohttp import web
import yaml
import ipaddress
from prozorro_sale import tools
from prozorro_sale.tools import logger
from prozorro_sale.auth.encryption import hash_token
AUTH_IP_BLOCK_STRICT = os.environ.get('AUTH_IP_BLOCK_STRICT', '1').lower() not in ('false', '0', 'f')
LOG = tools.logging.get_custom_logger(__name__)
LOG = logger.get_custom_logger(__name__)
@dataclass
......
import asyncio
import os
from aiohttp import web
from aiotask_context import task_factory
from prozorro_sale import tools, auth
import prozorro_sale
from aiohttp_swagger import setup_swagger
from prozorro_sale.tools import middlewares
import prozorro_sale
from prozorro_sale import tools, auth
from prozorro_sale.auth import errors, utils
LOG = tools.logging.get_custom_logger(__name__)
LOG = tools.logger.get_custom_logger(__name__)
SWAGGER_DOC_AVAILABLE = os.getenv('SWAGGER_DOC', False)
AUTH_FILE = os.environ.get('AUTH_FILE', '/secrets/auth.yml')
AUTH_IP_BLOCK_STRICT = os.environ.get('AUTH_IP_BLOCK_STRICT', '1').lower() not in ('false', '0', 'f')
......@@ -108,11 +106,10 @@ def setup_routes(app):
def create_app():
loop = asyncio.get_event_loop()
loop.set_task_factory(task_factory)
tools.logging.configure_logging()
tools.logger.configure_logging()
auth.load_auth(AUTH_FILE)
app = web.Application(middlewares=[
tools.logging.request_id_middleware,
middlewares.request_id_middleware,
errors.request_errors_middleware,
auth.context_middleware,
], loop=loop)
......@@ -136,5 +133,5 @@ if __name__ == '__main__':
web.run_app(
app,
port=80,
access_log_class=tools.logging.CustomAccessLogger
access_log_class=tools.logger.CustomAccessLogger
)
......@@ -16,7 +16,7 @@ class UnverifiedTokenError(AuthException):
pass
LOG = tools.logging.get_custom_logger(__name__)
LOG = tools.logger.get_custom_logger(__name__)
ERROR_DICT = {
RequiredTokenError: (403, '{}'),
......
import pytest
import asyncio
from prozorro_sale.auth.api import create_app
from aiotask_context import task_factory
@pytest.fixture
......@@ -12,7 +11,6 @@ async def client(aiohttp_client):
@pytest.fixture
def loop():
loop = asyncio.get_event_loop()
loop.set_task_factory(task_factory)
return loop
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment