Fixed looped dependencies and updated logging

This commit is contained in:
2025-08-31 22:31:07 +03:00
parent 4d4fce186c
commit ccec4cdf27
6 changed files with 32 additions and 27 deletions

View File

@ -6,7 +6,8 @@ from psycopg2._psycopg import connection
import db.accounts as db import db.accounts as db
import settings.settings as settings import settings.settings as settings
from api.models import Account, User from api.models import Account, User
from api.utils import encode_str, get_current_user from api.string_tools import encode_str
from api.utils import get_current_user
from db.groups import check_group_author from db.groups import check_group_author
from db.internal import get_db_connection from db.internal import get_db_connection

View File

@ -2,7 +2,7 @@ from datetime import datetime
from pydantic import BaseModel from pydantic import BaseModel
from api.utils import decode_str from api.string_tools import decode_str
class Token(BaseModel): class Token(BaseModel):

22
src/api/string_tools.py Normal file
View File

@ -0,0 +1,22 @@
import settings.startup_settings as startup_settings
def encode_str(string) -> str:
key = startup_settings.secret_key
encoded_chars = []
for i in range(len(string)):
key_c = key[i % len(key)]
encoded_c = chr(ord(string[i]) + ord(key_c) % 256)
encoded_chars.append(encoded_c)
encoded_string = ''.join(encoded_chars)
return encoded_string
def decode_str(encoded_string) -> str:
key = startup_settings.secret_key
encoded_chars = []
for i in range(len(encoded_string)):
key_c = key[i % len(key)]
encoded_c = chr((ord(encoded_string[i]) - ord(key_c) + 256) % 256)
encoded_chars.append(encoded_c)
decoded_string = ''.join(encoded_chars)
return decoded_string

View File

@ -17,27 +17,6 @@ from db.internal import get_db_connection
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
def encode_str(string) -> str:
key = startup_settings.secret_key
encoded_chars = []
for i in range(len(string)):
key_c = key[i % len(key)]
encoded_c = chr(ord(string[i]) + ord(key_c) % 256)
encoded_chars.append(encoded_c)
encoded_string = ''.join(encoded_chars)
return encoded_string
def decode_str(encoded_string) -> str:
key = startup_settings.secret_key
encoded_chars = []
for i in range(len(encoded_string)):
key_c = key[i % len(key)]
encoded_c = chr((ord(encoded_string[i]) - ord(key_c) + 256) % 256)
encoded_chars.append(encoded_c)
decoded_string = ''.join(encoded_chars)
return decoded_string
def verify_password(plain_password: str, hashed_password: str): def verify_password(plain_password: str, hashed_password: str):
return bcrypt.checkpw(plain_password.encode("utf-8"), hashed_password.encode("utf-8")) return bcrypt.checkpw(plain_password.encode("utf-8"), hashed_password.encode("utf-8"))

View File

@ -16,6 +16,7 @@ from api.users import users_router
from db.internal import connect_db, disconnect_db from db.internal import connect_db, disconnect_db
from settings import startup_settings from settings import startup_settings
from settings.settings import settings_down, settings_up from settings.settings import settings_down, settings_up
from settings.startup_settings import setup_settings
docs_url = None docs_url = None
if startup_settings.swagger_enabled: if startup_settings.swagger_enabled:
@ -33,11 +34,12 @@ def create_app():
{ {
"sink": sys.stdout, "sink": sys.stdout,
"level": startup_settings.log_level, "level": startup_settings.log_level,
"format": "<level>{level}: {message}</level>", "format": "<level>{level}</level>: {message}",
} }
] ]
) )
app.add_event_handler("startup", setup_settings)
app.add_event_handler("startup", connect_db) app.add_event_handler("startup", connect_db)
app.add_event_handler("startup", settings_up) app.add_event_handler("startup", settings_up)

View File

@ -1,4 +1,5 @@
from decouple import Csv, config from decouple import Csv, config
from loguru import logger
from .consts import SUPPORTED_PLATFORMS from .consts import SUPPORTED_PLATFORMS
@ -29,7 +30,7 @@ def setup_settings():
for platform in platforms_enabled: for platform in platforms_enabled:
if platform.lower() in SUPPORTED_PLATFORMS: if platform.lower() in SUPPORTED_PLATFORMS:
platforms_supported_and_enabled.append(platform.lower()) platforms_supported_and_enabled.append(platform.lower())
else:
logger.warning(f"Platform {platform} is not supported by design. It will not be used.")
logger.info(f"Supported platforms list: {platforms_supported_and_enabled}")
platforms_enabled = platforms_supported_and_enabled platforms_enabled = platforms_supported_and_enabled
setup_settings()