aiteamutils 0.2.34__tar.gz → 0.2.36__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/PKG-INFO +1 -1
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/security.py +26 -4
- aiteamutils-0.2.36/aiteamutils/version.py +2 -0
- aiteamutils-0.2.34/aiteamutils/version.py +0 -2
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/.cursorrules +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/.gitignore +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/README.md +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/__init__.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/base_model.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/base_repository.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/base_service.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/cache.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/config.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/database.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/dependencies.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/enums.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/exceptions.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/aiteamutils/validators.py +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/pyproject.toml +0 -0
- {aiteamutils-0.2.34 → aiteamutils-0.2.36}/setup.py +0 -0
@@ -6,6 +6,7 @@ from fastapi import Request, HTTPException, status
|
|
6
6
|
from functools import wraps
|
7
7
|
from jose import jwt, JWTError
|
8
8
|
from passlib.context import CryptContext
|
9
|
+
import logging
|
9
10
|
|
10
11
|
from .exceptions import CustomException, ErrorCode
|
11
12
|
from .database import DatabaseService
|
@@ -204,6 +205,10 @@ def rate_limit(
|
|
204
205
|
def decorator(func: Callable) -> Callable:
|
205
206
|
@wraps(func)
|
206
207
|
async def wrapper(*args, **kwargs):
|
208
|
+
logging.info(f"[rate_limit] Starting rate limit check for {func.__name__}")
|
209
|
+
logging.info(f"[rate_limit] Args: {args}")
|
210
|
+
logging.info(f"[rate_limit] Kwargs: {kwargs}")
|
211
|
+
|
207
212
|
# Request 객체 찾기
|
208
213
|
request = None
|
209
214
|
for arg in args:
|
@@ -216,6 +221,7 @@ def rate_limit(
|
|
216
221
|
request = arg
|
217
222
|
break
|
218
223
|
if not request:
|
224
|
+
logging.error("[rate_limit] Request object not found in args or kwargs")
|
219
225
|
raise CustomException(
|
220
226
|
ErrorCode.INTERNAL_ERROR,
|
221
227
|
detail="Request object not found",
|
@@ -229,10 +235,13 @@ def rate_limit(
|
|
229
235
|
client_ip = request.client.host
|
230
236
|
rate_limit_key = f"rate_limit:{client_ip}:{func.__name__}"
|
231
237
|
|
238
|
+
logging.info(f"[rate_limit] Rate limit key: {rate_limit_key}")
|
239
|
+
|
232
240
|
now = datetime.now(UTC)
|
233
241
|
|
234
242
|
# 현재 rate limit 정보 가져오기
|
235
243
|
rate_info = rate_limits.get(rate_limit_key)
|
244
|
+
logging.info(f"[rate_limit] Current rate info: {rate_info}")
|
236
245
|
|
237
246
|
if rate_info is None or (now - rate_info["start_time"]).total_seconds() >= window_seconds:
|
238
247
|
# 새로운 rate limit 설정
|
@@ -240,11 +249,13 @@ def rate_limit(
|
|
240
249
|
"count": 1,
|
241
250
|
"start_time": now
|
242
251
|
}
|
252
|
+
logging.info(f"[rate_limit] Created new rate limit: {rate_limits[rate_limit_key]}")
|
243
253
|
else:
|
244
254
|
# 기존 rate limit 업데이트
|
245
255
|
if rate_info["count"] >= max_requests:
|
246
256
|
# rate limit 초과
|
247
257
|
remaining_seconds = window_seconds - (now - rate_info["start_time"]).total_seconds()
|
258
|
+
logging.warning(f"[rate_limit] Rate limit exceeded. Remaining seconds: {remaining_seconds}")
|
248
259
|
raise RateLimitExceeded(
|
249
260
|
detail=rate_limit_key,
|
250
261
|
source_function=func.__name__,
|
@@ -253,15 +264,26 @@ def rate_limit(
|
|
253
264
|
window_seconds=window_seconds
|
254
265
|
)
|
255
266
|
rate_info["count"] += 1
|
267
|
+
logging.info(f"[rate_limit] Updated rate info: {rate_info}")
|
256
268
|
|
257
269
|
try:
|
258
|
-
|
259
|
-
|
270
|
+
logging.info(f"[rate_limit] Executing original function: {func.__name__}")
|
271
|
+
# db_service가 있는지 확인
|
272
|
+
for arg in args:
|
273
|
+
if hasattr(arg, 'db_service'):
|
274
|
+
logging.info(f"[rate_limit] Found db_service in args: {arg.db_service}")
|
275
|
+
for value in kwargs.values():
|
276
|
+
if hasattr(value, 'db_service'):
|
277
|
+
logging.info(f"[rate_limit] Found db_service in kwargs: {value.db_service}")
|
278
|
+
|
279
|
+
result = await func(*args, **kwargs)
|
280
|
+
logging.info("[rate_limit] Function executed successfully")
|
281
|
+
return result
|
260
282
|
except CustomException as e:
|
261
|
-
|
283
|
+
logging.error(f"[rate_limit] CustomException occurred: {str(e)}")
|
262
284
|
raise e
|
263
285
|
except Exception as e:
|
264
|
-
|
286
|
+
logging.error(f"[rate_limit] Unexpected error occurred: {str(e)}")
|
265
287
|
raise CustomException(
|
266
288
|
ErrorCode.INTERNAL_ERROR,
|
267
289
|
detail=str(e),
|
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
|
File without changes
|