aiteamutils 0.2.23__tar.gz → 0.2.25__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/PKG-INFO +1 -1
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/dependencies.py +16 -11
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/security.py +3 -4
- aiteamutils-0.2.25/aiteamutils/version.py +2 -0
- aiteamutils-0.2.23/aiteamutils/version.py +0 -2
- aiteamutils-0.2.23/app/app/auth/service.py +0 -57
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/.gitignore +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/README.md +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/__init__.py +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/base_model.py +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/base_repository.py +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/base_service.py +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/cache.py +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/config.py +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/database.py +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/enums.py +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/exceptions.py +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/aiteamutils/validators.py +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/pyproject.toml +0 -0
- {aiteamutils-0.2.23 → aiteamutils-0.2.25}/setup.py +0 -0
@@ -52,19 +52,24 @@ class ServiceRegistry:
|
|
52
52
|
service_registry = ServiceRegistry()
|
53
53
|
|
54
54
|
def get_service(name: str):
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
name (str): 서비스 이름
|
59
|
-
|
60
|
-
Returns:
|
61
|
-
Callable: 서비스 인스턴스를 반환하는 의존성 함수
|
62
|
-
"""
|
63
|
-
def _get_service(db: AsyncSession = Depends(get_db)):
|
64
|
-
db_service = DatabaseService(session=db)
|
55
|
+
def _get_service():
|
56
|
+
# 글로벌 DatabaseService 사용
|
57
|
+
db_service = get_database_service()
|
65
58
|
repository_class, service_class = service_registry.get(name)
|
59
|
+
|
60
|
+
# 이미 생성된 서비스가 있다면 재사용
|
61
|
+
if hasattr(service_registry, '_instances') and name in service_registry._instances:
|
62
|
+
return service_registry._instances[name]
|
63
|
+
|
66
64
|
repository = repository_class(db_service)
|
67
|
-
|
65
|
+
instance = service_class(repository, db_service)
|
66
|
+
|
67
|
+
# 생성된 인스턴스 캐싱
|
68
|
+
if not hasattr(service_registry, '_instances'):
|
69
|
+
service_registry._instances = {}
|
70
|
+
service_registry._instances[name] = instance
|
71
|
+
|
72
|
+
return instance
|
68
73
|
return _get_service
|
69
74
|
|
70
75
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/users/token")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""보안 관련 유틸리티."""
|
2
2
|
from datetime import datetime, timedelta, UTC
|
3
|
-
from typing import Dict, Any, Optional, Literal, Callable
|
3
|
+
from typing import Dict, Any, Optional, Literal, Callable, Type, Base
|
4
4
|
from fastapi import Request, HTTPException, status
|
5
5
|
from functools import wraps
|
6
6
|
from jose import jwt, JWTError
|
@@ -262,7 +262,7 @@ async def create_jwt_token(
|
|
262
262
|
user_data: Dict[str, Any],
|
263
263
|
token_type: Literal["access", "refresh"],
|
264
264
|
db_service: DatabaseService,
|
265
|
-
log_model:
|
265
|
+
log_model: Type[Base],
|
266
266
|
request: Optional[Request] = None
|
267
267
|
) -> str:
|
268
268
|
"""JWT 토큰을 생성하고 로그를 기록합니다.
|
@@ -271,7 +271,7 @@ async def create_jwt_token(
|
|
271
271
|
user_data: 사용자 데이터 딕셔너리 (username, ulid, name, role_ulid, status, organization 정보 등)
|
272
272
|
token_type: 토큰 타입 ("access" 또는 "refresh")
|
273
273
|
db_service: 데이터베이스 서비스
|
274
|
-
log_model: 로그 모델
|
274
|
+
log_model: 로그 모델 클래스
|
275
275
|
request: FastAPI 요청 객체
|
276
276
|
|
277
277
|
Returns:
|
@@ -293,7 +293,6 @@ async def create_jwt_token(
|
|
293
293
|
token_type=token_type
|
294
294
|
)
|
295
295
|
|
296
|
-
# 토큰 데이터 생성
|
297
296
|
if token_type == "access":
|
298
297
|
expires_at = datetime.now(UTC) + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
299
298
|
token_data = {
|
@@ -1,57 +0,0 @@
|
|
1
|
-
async def login(self, username: str, password: str, request: Request = None) -> Dict[str, str]:
|
2
|
-
"""사용자 로그인을 처리합니다.
|
3
|
-
|
4
|
-
Args:
|
5
|
-
username (str): 사용자명
|
6
|
-
password (str): 비밀번호
|
7
|
-
request (Request, optional): FastAPI 요청 객체
|
8
|
-
|
9
|
-
Returns:
|
10
|
-
Dict[str, str]: 액세스 토큰과 리프레시 토큰
|
11
|
-
|
12
|
-
Raises:
|
13
|
-
CustomException: 인증 실패 시 예외
|
14
|
-
"""
|
15
|
-
# 사용자 조회
|
16
|
-
user = await self.repository.get_user(username, by="username")
|
17
|
-
if not user:
|
18
|
-
raise CustomException(
|
19
|
-
ErrorCode.INVALID_CREDENTIALS,
|
20
|
-
source_function="AuthService.login"
|
21
|
-
)
|
22
|
-
|
23
|
-
# 비밀번호 검증
|
24
|
-
if not verify_password(password, user.password):
|
25
|
-
raise CustomException(
|
26
|
-
ErrorCode.INVALID_CREDENTIALS,
|
27
|
-
source_function="AuthService.login"
|
28
|
-
)
|
29
|
-
|
30
|
-
# 토큰 생성
|
31
|
-
user_data = {
|
32
|
-
"username": user.username,
|
33
|
-
"ulid": user.ulid,
|
34
|
-
"email": user.email
|
35
|
-
}
|
36
|
-
|
37
|
-
access_token = await create_jwt_token(
|
38
|
-
user_data=user_data,
|
39
|
-
token_type="access",
|
40
|
-
db_service=self.db_service,
|
41
|
-
log_model=self.log_model,
|
42
|
-
request=request
|
43
|
-
)
|
44
|
-
|
45
|
-
refresh_token = await create_jwt_token(
|
46
|
-
user_data=user_data,
|
47
|
-
token_type="refresh",
|
48
|
-
db_service=self.db_service,
|
49
|
-
log_model=self.log_model,
|
50
|
-
request=request
|
51
|
-
)
|
52
|
-
|
53
|
-
return {
|
54
|
-
"access_token": access_token,
|
55
|
-
"refresh_token": refresh_token,
|
56
|
-
"token_type": "bearer"
|
57
|
-
}
|
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
|