check-deploy
Some checks failed
deploy / deploy (push) Failing after 1m27s

This commit is contained in:
Untone 2024-02-03 18:36:33 +03:00
parent 59a1f8c902
commit 15fd6ec765
5 changed files with 41 additions and 10 deletions

View File

@ -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

View File

@ -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

View File

@ -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 = [

17
server.py Normal file
View File

@ -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()

View File

@ -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