aiteamutils 0.2.55__tar.gz → 0.2.57__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/PKG-INFO +1 -1
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/config.py +23 -13
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/dependencies.py +25 -1
- aiteamutils-0.2.57/aiteamutils/version.py +2 -0
- aiteamutils-0.2.55/aiteamutils/version.py +0 -2
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/.cursorrules +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/.gitignore +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/README.md +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/__init__.py +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/base_model.py +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/base_repository.py +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/base_service.py +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/cache.py +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/database.py +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/enums.py +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/exceptions.py +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/security.py +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/aiteamutils/validators.py +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/pyproject.toml +0 -0
- {aiteamutils-0.2.55 → aiteamutils-0.2.57}/setup.py +0 -0
@@ -1,6 +1,5 @@
|
|
1
1
|
"""설정 모듈."""
|
2
2
|
from typing import Union
|
3
|
-
from .database import DatabaseServiceManager
|
4
3
|
from .exceptions import CustomException, ErrorCode
|
5
4
|
|
6
5
|
class Settings:
|
@@ -11,13 +10,28 @@ class Settings:
|
|
11
10
|
jwt_algorithm: str = "HS256",
|
12
11
|
access_token_expire_minutes: int = 30,
|
13
12
|
token_issuer: str = "ai-team",
|
14
|
-
token_audience: str = "ai-team"
|
13
|
+
token_audience: str = "ai-team",
|
14
|
+
db_url: str = None,
|
15
|
+
db_echo: bool = False,
|
16
|
+
db_pool_size: int = 5,
|
17
|
+
db_max_overflow: int = 10,
|
18
|
+
db_pool_timeout: int = 30,
|
19
|
+
db_pool_recycle: int = 1800
|
15
20
|
):
|
21
|
+
# JWT 설정
|
16
22
|
self.JWT_SECRET = jwt_secret
|
17
23
|
self.JWT_ALGORITHM = jwt_algorithm
|
18
24
|
self.ACCESS_TOKEN_EXPIRE_MINUTES = access_token_expire_minutes
|
19
25
|
self.TOKEN_ISSUER = token_issuer
|
20
26
|
self.TOKEN_AUDIENCE = token_audience
|
27
|
+
|
28
|
+
# 데이터베이스 설정
|
29
|
+
self.DB_URL = db_url
|
30
|
+
self.DB_ECHO = db_echo
|
31
|
+
self.DB_POOL_SIZE = db_pool_size
|
32
|
+
self.DB_MAX_OVERFLOW = db_max_overflow
|
33
|
+
self.DB_POOL_TIMEOUT = db_pool_timeout
|
34
|
+
self.DB_POOL_RECYCLE = db_pool_recycle
|
21
35
|
|
22
36
|
_settings: Union[Settings, None] = None
|
23
37
|
|
@@ -55,18 +69,14 @@ async def init_settings(
|
|
55
69
|
jwt_algorithm=jwt_algorithm,
|
56
70
|
access_token_expire_minutes=access_token_expire_minutes,
|
57
71
|
token_issuer=token_issuer,
|
58
|
-
token_audience=token_audience
|
72
|
+
token_audience=token_audience,
|
73
|
+
db_url=db_url,
|
74
|
+
db_echo=db_echo,
|
75
|
+
db_pool_size=db_pool_size,
|
76
|
+
db_max_overflow=db_max_overflow,
|
77
|
+
db_pool_timeout=db_pool_timeout,
|
78
|
+
db_pool_recycle=db_pool_recycle
|
59
79
|
)
|
60
|
-
|
61
|
-
if db_url:
|
62
|
-
await DatabaseServiceManager.get_instance(
|
63
|
-
db_url=db_url,
|
64
|
-
db_echo=db_echo,
|
65
|
-
db_pool_size=db_pool_size,
|
66
|
-
db_max_overflow=db_max_overflow,
|
67
|
-
db_pool_timeout=db_pool_timeout,
|
68
|
-
db_pool_recycle=db_pool_recycle
|
69
|
-
)
|
70
80
|
|
71
81
|
def get_settings() -> Settings:
|
72
82
|
"""현재 설정을 반환하는 함수
|
@@ -15,6 +15,16 @@ T = TypeVar("T", bound=BaseService)
|
|
15
15
|
R = TypeVar("R", bound=BaseRepository)
|
16
16
|
|
17
17
|
_service_registry: Dict[str, Dict[str, Any]] = {}
|
18
|
+
_session_provider = None
|
19
|
+
|
20
|
+
def setup_dependencies(session_provider: Callable[[], AsyncGenerator[AsyncSession, None]]) -> None:
|
21
|
+
"""의존성 설정을 초기화합니다.
|
22
|
+
|
23
|
+
Args:
|
24
|
+
session_provider: 데이터베이스 세션을 제공하는 함수
|
25
|
+
"""
|
26
|
+
global _session_provider
|
27
|
+
_session_provider = session_provider
|
18
28
|
|
19
29
|
def register_service(
|
20
30
|
service_class: Type[T],
|
@@ -28,6 +38,13 @@ def register_service(
|
|
28
38
|
repository_class: 저장소 클래스 (선택)
|
29
39
|
**kwargs: 추가 의존성
|
30
40
|
"""
|
41
|
+
if _session_provider is None:
|
42
|
+
raise CustomException(
|
43
|
+
ErrorCode.INTERNAL_ERROR,
|
44
|
+
detail="Dependencies not initialized",
|
45
|
+
source_function="dependencies.register_service"
|
46
|
+
)
|
47
|
+
|
31
48
|
service_name = service_class.__name__
|
32
49
|
_service_registry[service_name] = {
|
33
50
|
"service_class": service_class,
|
@@ -103,9 +120,16 @@ def get_service(service_name: str) -> Callable:
|
|
103
120
|
Returns:
|
104
121
|
Callable: 서비스 의존성 함수
|
105
122
|
"""
|
123
|
+
if _session_provider is None:
|
124
|
+
raise CustomException(
|
125
|
+
ErrorCode.INTERNAL_ERROR,
|
126
|
+
detail="Dependencies not initialized",
|
127
|
+
source_function="dependencies.get_service"
|
128
|
+
)
|
129
|
+
|
106
130
|
async def _get_service_dependency(
|
107
131
|
request: Request,
|
108
|
-
session: AsyncSession
|
132
|
+
session: AsyncSession = Depends(_session_provider)
|
109
133
|
) -> BaseService:
|
110
134
|
return await _get_service(service_name, session, request)
|
111
135
|
return _get_service_dependency
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|