aiteamutils 0.2.36__py3-none-any.whl → 0.2.37__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
@@ -15,6 +15,9 @@ from .config import get_settings
|
|
15
15
|
|
16
16
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
17
17
|
|
18
|
+
# 전역 rate limit 상태 저장
|
19
|
+
_rate_limits: Dict[str, Dict[str, Any]] = {}
|
20
|
+
|
18
21
|
class RateLimitExceeded(CustomException):
|
19
22
|
"""Rate limit 초과 예외."""
|
20
23
|
|
@@ -200,14 +203,10 @@ def rate_limit(
|
|
200
203
|
key_func: Optional[Callable] = None
|
201
204
|
):
|
202
205
|
"""Rate limiting 데코레이터."""
|
203
|
-
rate_limits: Dict[str, Dict[str, Any]] = {}
|
204
|
-
|
205
206
|
def decorator(func: Callable) -> Callable:
|
206
207
|
@wraps(func)
|
207
208
|
async def wrapper(*args, **kwargs):
|
208
209
|
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
210
|
|
212
211
|
# Request 객체 찾기
|
213
212
|
request = None
|
@@ -240,16 +239,16 @@ def rate_limit(
|
|
240
239
|
now = datetime.now(UTC)
|
241
240
|
|
242
241
|
# 현재 rate limit 정보 가져오기
|
243
|
-
rate_info =
|
242
|
+
rate_info = _rate_limits.get(rate_limit_key)
|
244
243
|
logging.info(f"[rate_limit] Current rate info: {rate_info}")
|
245
244
|
|
246
245
|
if rate_info is None or (now - rate_info["start_time"]).total_seconds() >= window_seconds:
|
247
246
|
# 새로운 rate limit 설정
|
248
|
-
|
247
|
+
_rate_limits[rate_limit_key] = {
|
249
248
|
"count": 1,
|
250
249
|
"start_time": now
|
251
250
|
}
|
252
|
-
logging.info(f"[rate_limit] Created new rate limit: {
|
251
|
+
logging.info(f"[rate_limit] Created new rate limit: {_rate_limits[rate_limit_key]}")
|
253
252
|
else:
|
254
253
|
# 기존 rate limit 업데이트
|
255
254
|
if rate_info["count"] >= max_requests:
|
@@ -268,14 +267,6 @@ def rate_limit(
|
|
268
267
|
|
269
268
|
try:
|
270
269
|
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
270
|
result = await func(*args, **kwargs)
|
280
271
|
logging.info("[rate_limit] Function executed successfully")
|
281
272
|
return result
|
@@ -290,7 +281,7 @@ def rate_limit(
|
|
290
281
|
source_function=func.__name__,
|
291
282
|
original_error=e
|
292
283
|
)
|
293
|
-
|
284
|
+
|
294
285
|
return wrapper
|
295
286
|
return decorator
|
296
287
|
|
aiteamutils/version.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
"""버전 정보"""
|
2
|
-
__version__ = "0.2.
|
2
|
+
__version__ = "0.2.37"
|
@@ -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=9gvEqDtE3RJaoCWqELPCjkg-IsSqZVrpMP6XPZaodWU,16024
|
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=CmXYar-ylEXzX7J29Pftix8-ss-hnVGdG7rr9Oikfq0,42
|
14
|
+
aiteamutils-0.2.37.dist-info/METADATA,sha256=TBQe6PWAOtODst1zDCR506fxkYQv-V4nWEo4yhAon08,1718
|
15
|
+
aiteamutils-0.2.37.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
aiteamutils-0.2.37.dist-info/RECORD,,
|
File without changes
|