From b8e6f7bb5aba81cccd177f7399a8f2dcc0ccabf1 Mon Sep 17 00:00:00 2001 From: Tony Rewin Date: Thu, 5 Oct 2023 22:18:05 +0300 Subject: [PATCH] requests-removed+fixes --- .pre-commit-config.yaml | 2 +- Dockerfile | 2 +- auth/email.py | 33 +++++++++++------------ auth/identity.py | 2 +- auth/jwtcodec.py | 2 +- auth/tokenstorage.py | 2 +- validations/auth.py => auth/validators.py | 0 requirements.txt | 9 ++----- validations/inbox.py | 28 ------------------- 9 files changed, 23 insertions(+), 57 deletions(-) rename validations/auth.py => auth/validators.py (100%) delete mode 100644 validations/inbox.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fc2116ab..16d17721 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ exclude: | ) default_language_version: - python: python3.8 + python: python3.12 repos: - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/Dockerfile b/Dockerfile index 40da0f05..800ab2a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,6 @@ WORKDIR /app EXPOSE 8080 ADD nginx.conf.sigil ./ COPY requirements.txt . -RUN apt update && apt install -y git gcc +RUN apt update && apt install -y build-essentials RUN pip install -r requirements.txt COPY . . diff --git a/auth/email.py b/auth/email.py index 7ca5d9bf..7290c518 100644 --- a/auth/email.py +++ b/auth/email.py @@ -1,20 +1,17 @@ -import requests +from httpx import AsyncClient from settings import MAILGUN_API_KEY, MAILGUN_DOMAIN -api_url = "https://api.mailgun.net/v3/%s/messages" % (MAILGUN_DOMAIN or 'discours.io') -noreply = "discours.io " % (MAILGUN_DOMAIN or 'discours.io') -lang_subject = { - "ru": "Подтверждение почты", - "en": "Confirm email" -} +api_url = "https://api.mailgun.net/v3/%s/messages" % (MAILGUN_DOMAIN or "discours.io") +noreply = "discours.io " % (MAILGUN_DOMAIN or "discours.io") +lang_subject = {"ru": "Подтверждение почты", "en": "Confirm email"} async def send_auth_email(user, token, lang="ru", template="email_confirmation"): try: to = "%s <%s>" % (user.name, user.email) - if lang not in ['ru', 'en']: - lang = 'ru' + if lang not in ["ru", "en"]: + lang = "ru" subject = lang_subject.get(lang, lang_subject["en"]) template = template + "_" + lang payload = { @@ -22,16 +19,18 @@ async def send_auth_email(user, token, lang="ru", template="email_confirmation") "to": to, "subject": subject, "template": template, - "h:X-Mailgun-Variables": "{ \"token\": \"%s\" }" % token + "h:X-Mailgun-Variables": '{ "token": "%s" }' % token, } - print('[auth.email] payload: %r' % payload) + print("[auth.email] payload: %r" % payload) # debug # print('http://localhost:3000/?modal=auth&mode=confirm-email&token=%s' % token) - response = requests.post( - api_url, - auth=("api", MAILGUN_API_KEY), - data=payload - ) - response.raise_for_status() + async with AsyncClient() as client: + response = await client.post(api_url, headers=headers, data=gql) + if response.status_code != 200: + return False, None + r = response.json() + api_url, auth=("api", MAILGUN_API_KEY), data=payload + ) + response.raise_for_status() except Exception as e: print(e) diff --git a/auth/identity.py b/auth/identity.py index 0fff8c96..2c5ddb47 100644 --- a/auth/identity.py +++ b/auth/identity.py @@ -11,7 +11,7 @@ from auth.tokenstorage import TokenStorage # from base.exceptions import InvalidPassword, InvalidToken from services.db import local_session from orm import User -from validations.auth import AuthInput +from auth.validators import AuthInput class Password: diff --git a/auth/jwtcodec.py b/auth/jwtcodec.py index fb15b5f7..c0943bf9 100644 --- a/auth/jwtcodec.py +++ b/auth/jwtcodec.py @@ -1,7 +1,7 @@ from datetime import datetime, timezone import jwt from services.exceptions import ExpiredToken, InvalidToken -from validations.auth import TokenPayload, AuthInput +from auth.validators import TokenPayload, AuthInput from settings import JWT_ALGORITHM, JWT_SECRET_KEY diff --git a/auth/tokenstorage.py b/auth/tokenstorage.py index 4c28ffa3..1416baa2 100644 --- a/auth/tokenstorage.py +++ b/auth/tokenstorage.py @@ -1,7 +1,7 @@ from datetime import datetime, timedelta, timezone from auth.jwtcodec import JWTCodec -from validations.auth import AuthInput +from auth.validators import AuthInput from services.redis import redis from settings import SESSION_TOKEN_LIFE_SPAN, ONETIME_TOKEN_LIFE_SPAN diff --git a/validations/auth.py b/auth/validators.py similarity index 100% rename from validations/auth.py rename to auth/validators.py diff --git a/requirements.txt b/requirements.txt index c252b7b6..7d58a3f2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ python-frontmatter~=1.0.0 -aredis -aiohttp +aredis~=1.1.8 ariadne>=0.17.0 PyYAML>=5.4 pyjwt>=2.6.0 @@ -16,22 +15,18 @@ authlib>=1.1.0 httpx>=0.23.0 psycopg2-binary transliterate~=1.10.2 -requests bcrypt>=4.0.0 websockets bson~=0.5.10 flake8 DateTime~=4.7 -asyncio~=3.4.3 python-dateutil~=2.8.2 beautifulsoup4~=4.11.1 lxml sentry-sdk>=1.14.0 -# sse_starlette -graphql-ws nltk~=3.8.1 pymystem3~=0.2.0 -transformers~=4.28.1 +transformers boto3~=1.28.2 botocore~=1.31.2 python-multipart~=0.0.6 diff --git a/validations/inbox.py b/validations/inbox.py deleted file mode 100644 index d03cca05..00000000 --- a/validations/inbox.py +++ /dev/null @@ -1,28 +0,0 @@ -from typing import Optional, Text, List -from pydantic import BaseModel - - -class Message(BaseModel): - id: int - body: Text - author: int - chatId: Text - createdAt: int - updatedAt: Optional[int] - replyTo: Optional[int] - - -class Member(BaseModel): - id: int - name: Text - pic: Optional[Text] - # TODO: extend chat member model - - -class Chat(BaseModel): - createdAt: int - createdBy: int - users: List[int] - updatedAt: Optional[int] - title: Optional[Text] - description: Optional[Text]