diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43fa826..757f660 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,8 +14,7 @@ repos: - id: check-merge-conflict - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.13 + rev: v0.1.15 hooks: - id: ruff args: [--fix] - - id: ruff-format diff --git a/Dockerfile b/Dockerfile index 6401033..350acd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM python:slim WORKDIR /app # Add metadata to the image to describe that the container is listening on port 80 -EXPOSE 80 +EXPOSE 8000 # Copy the current directory contents into the container at /app COPY . /app @@ -19,4 +19,4 @@ RUN apt-get update && apt-get install -y gcc curl && \ poetry install --no-dev # Run server.py when the container launches -CMD granian --no-ws --host 0.0.0.0 --port 80 --interface asgi main:app +CMD python server.py diff --git a/pyproject.toml b/pyproject.toml index 1af9476..33420bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,7 @@ + [tool.poetry] name = "discoursio-notifier" -version = "0.2.22" +version = "0.3.0" description = "notifier server for discours.io" authors = ["discours.io devteam"] @@ -15,19 +16,24 @@ sentry-sdk = "^1.39.2" aiohttp = "^3.9.1" pre-commit = "^3.6.0" granian = "^1.0.1" +discoursio-core = { git = "https://dev.discours.io/discours.io/core.git", branch = "feature/core" } [tool.poetry.group.dev.dependencies] setuptools = "^69.0.2" pyright = "^1.1.341" pytest = "^7.4.2" black = { version = "^23.12.0", python = ">=3.12" } -ruff = { version = "^0.1.8", python = ">=3.12" } +ruff = { version = "^0.1.15", python = ">=3.12" } isort = "^5.13.2" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" +[tool.setuptools.dynamic] +version = {attr = "notifier.__version__"} +readme = {file = "README.md"} + [tool.ruff] line-length = 120 extend-select = [ diff --git a/server.py b/server.py new file mode 100644 index 0000000..1301ba5 --- /dev/null +++ b/server.py @@ -0,0 +1,17 @@ +from granian.constants import Interfaces +from granian.server import Granian + + +if __name__ == '__main__': + print('[server] started') + + granian_instance = Granian( + 'main:app', + address='0.0.0.0', # noqa S104 + port=8000, + workers=2, + threads=2, + websockets=False, + interface=Interfaces.ASGI, + ) + granian_instance.serve() diff --git a/services/auth.py b/services/auth.py index b84a9bd..f26b37a 100644 --- a/services/auth.py +++ b/services/auth.py @@ -37,15 +37,24 @@ async def check_auth(req) -> str | None: try: # Asynchronous HTTP request to the authentication server async with ClientSession() as session: - async with session.post(AUTH_URL, json=gql, headers=headers) as response: - print(f'[services.auth] HTTP Response {response.status} {await response.text()}') + async with session.post( + AUTH_URL, json=gql, headers=headers + ) as response: + print( + f'[services.auth] HTTP Response {response.status} {await response.text()}' + ) if response.status == 200: data = await response.json() errors = data.get('errors') if errors: - print(f'[services.auth] errors: {errors}') + print(f'errors: {errors}') else: - user_id = data.get('data', {}).get(query_name, {}).get('claims', {}).get('sub') + user_id = ( + data.get('data', {}) + .get(query_name, {}) + .get('claims', {}) + .get('sub') + ) if user_id: print(f'[services.auth] got user_id: {user_id}') return user_id