aiteamutils 0.2.35__py3-none-any.whl → 0.2.36__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
aiteamutils/security.py
CHANGED
@@ -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),
|
aiteamutils/version.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
"""버전 정보"""
|
2
|
-
__version__ = "0.2.
|
2
|
+
__version__ = "0.2.36"
|
@@ -8,9 +8,9 @@ aiteamutils/database.py,sha256=CaH73g8PPNcmLCz4Xr0DBtNSrLcpRlyt0F1zO5Tigfo,33811
|
|
8
8
|
aiteamutils/dependencies.py,sha256=GgN8sFM7qGNmOfpLaFrhuHOgPlBVXWrEgxv29jxjEgI,4226
|
9
9
|
aiteamutils/enums.py,sha256=ipZi6k_QD5-3QV7Yzv7bnL0MjDz-vqfO9I5L77biMKs,632
|
10
10
|
aiteamutils/exceptions.py,sha256=YV-ISya4wQlHk4twvGo16I5r8h22-tXpn9wa-b3WwDM,15231
|
11
|
-
aiteamutils/security.py,sha256=
|
11
|
+
aiteamutils/security.py,sha256=U6EjpruMK6PB_gfUsX1kbrnv5pdkrg-vbJ266HDmelU,16563
|
12
12
|
aiteamutils/validators.py,sha256=3N245cZFjgwtW_KzjESkizx5BBUDaJLbbxfNO4WOFZ0,7764
|
13
|
-
aiteamutils/version.py,sha256=
|
14
|
-
aiteamutils-0.2.
|
15
|
-
aiteamutils-0.2.
|
16
|
-
aiteamutils-0.2.
|
13
|
+
aiteamutils/version.py,sha256=xIPwqXH-2Fd8zt8Gh1JwJx_ISWM3WKZzxCLLIcTS6JU,42
|
14
|
+
aiteamutils-0.2.36.dist-info/METADATA,sha256=0StxHP94IIzkjMUHtwHz2vJ-n9lFKhhMh3aSax2LZ3g,1718
|
15
|
+
aiteamutils-0.2.36.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
aiteamutils-0.2.36.dist-info/RECORD,,
|
File without changes
|