Skip to content

Commit de0a45f

Browse files
authored
Merge pull request #8 from zubinqayam/copilot/fix-ci-and-python-workflows
Fix CI workflow action version and resolve module import errors
2 parents 6bf142c + c9e8267 commit de0a45f

File tree

8 files changed

+17
-3
lines changed

8 files changed

+17
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
cyclonedx-npm --output-format json --output-file sbom.json || true
3232
3333
- name: Setup osv-scanner
34-
uses: google/osv-scanner-action@v1
34+
uses: google/osv-scanner-action@v1.9.0
3535
with:
3636
args: -r . -o vuln_report.txt
3737

modules/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

ratelimit.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

22
import time
3+
import functools
4+
import inspect
35
from typing import Callable, Dict, Tuple
46
from fastapi import Request
57
from fastapi.responses import JSONResponse
@@ -13,6 +15,7 @@ def _key(request: Request) -> str:
1315

1416
def limiter(limit: int = 60, window_sec: int = 60):
1517
def decorator(func: Callable):
18+
@functools.wraps(func)
1619
async def wrapper(*args, **kwargs):
1720
req = None
1821
for a in args:
@@ -21,9 +24,15 @@ async def wrapper(*args, **kwargs):
2124
break
2225
if req is None:
2326
req = kwargs.get("request", None)
27+
28+
# If no request found (e.g., in tests or direct function calls), execute without rate limiting
2429
if req is None:
25-
return await func(*args, **kwargs)
30+
if inspect.iscoroutinefunction(func):
31+
return await func(*args, **kwargs)
32+
else:
33+
return func(*args, **kwargs)
2634

35+
# Apply rate limiting: check window, count requests, and enforce limits
2736
now = time.time()
2837
k = _key(req)
2938
window_start, count = _STORE.get(k, (now, 0))
@@ -37,6 +46,11 @@ async def wrapper(*args, **kwargs):
3746
headers={"Retry-After": str(retry_after)},
3847
)
3948
_STORE[k] = (window_start, count + 1)
40-
return await func(*args, **kwargs)
49+
50+
# Call the original function
51+
if inspect.iscoroutinefunction(func):
52+
return await func(*args, **kwargs)
53+
else:
54+
return func(*args, **kwargs)
4155
return wrapper
4256
return decorator

0 commit comments

Comments
 (0)