Перенос служебных методов настроек

This commit is contained in:
2026-07-19 20:45:46 +03:00
parent da3f3aa703
commit 9e71bb6e29
7 changed files with 14 additions and 14 deletions

View File

@@ -9,7 +9,6 @@
"""
from .account_manager import AccountManager
from .configuration_manager import ConfigurationManager
from .crypto_manager import CryptoManager
from .locale_manager import LocaleManager
from .request_manager import RequestManager

View File

@@ -1,66 +0,0 @@
# DRF Rack
# Библиотека классов расширений для Django REST Framework
#
# Автор: Николай В. Анохин <n.anokhin@xeaf.net>
# Все права защищены. Лицензия: MIT
"""
Описание класса ConfigurationManager
"""
from typing import Any
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
class ConfigurationManager:
"""
Прокси-менеджер для безопасного извлечения настроек из django.conf.settings
"""
@classmethod
def get_string(cls, key: str, default: str) -> str:
"""
Извлекает строковое значение, параметр default обязателен
"""
value = getattr(settings, key, default)
cls._assert_type(key, value, str)
return value
@classmethod
def get_int(cls, key: str, default: int) -> int:
"""
Извлекает целочисленное значение, параметр default обязателен
"""
value = getattr(settings, key, default)
cls._assert_type(key, value, int)
return value
@classmethod
def get_bool(cls, key: str, default: bool) -> bool:
"""
Извлекает логическое значение, параметр default обязателен.
"""
value = getattr(settings, key, default)
cls._assert_type(key, value, bool)
return value
@classmethod
def _assert_type(cls, key: str, value: Any, expected_type: type) -> None:
"""
Проверяет типы, защищая от bool/int полиморфизма
"""
if expected_type is int and isinstance(value, bool):
actual_type = bool
else:
actual_type = type(value)
if actual_type is not expected_type:
raise ImproperlyConfigured(
f"Configuration error: '{key}' must be of type {expected_type.__name__}, got {actual_type.__name__}."
)

View File

@@ -16,12 +16,12 @@ from django.contrib.auth import authenticate
from environ import ImproperlyConfigured
from net.xeaf.rack.enums import AuthRejectReason
from net.xeaf.rack.managers import ConfigurationManager
from net.xeaf.rack.managers import CryptoManager
from net.xeaf.rack.models import AccountModel
from net.xeaf.rack.models import SessionModel
from net.xeaf.rack.utils.exceptions import UnauthorizedException
from .account_manager import AccountManager
from ..utils.settings import Config
class SessionManager[T:SessionModel]:
@@ -116,7 +116,7 @@ class SessionManager[T:SessionModel]:
:param session: Модель данных сессии
"""
ttl = ConfigurationManager.get_int("SESSION_TTL", cls.DEFAULT_SESSION_TTL)
ttl = Config.get_int("SESSION_TTL", cls.DEFAULT_SESSION_TTL)
session.renew(ttl, save=True)
@classmethod
@@ -144,7 +144,7 @@ class SessionManager[T:SessionModel]:
"""
if cls.__model_class is None:
model_path = ConfigurationManager.get_string("AUTH_SESSION_MODEL", "net_xeaf_rack.SessionModel")
model_path = Config.get_str("AUTH_SESSION_MODEL", "net_xeaf_rack.SessionModel")
app_label, model_name = model_path.split(".")
try: