
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
A tool to monitor the number of HTTP requests through an _apiKey_ in the HTTP Header.
A tool to monitor the number of HTTP requests.
It uses a key as extra parameter in the HTTP header, and optionally can filter the HTTP request per source (like origin).
Scenario: A Company that sell a Service that is limited by a max amount of requests and/or filtered by source HTTP request parameter.
Install redis or run a docker container as below
$> docker run --name test-redis -p6379:6379 -ti redis redis-server --appendonly yes
$> pip install requests-counter
from fastapi import Depends, FastAPI, HTTPException, Header
# 1. Import the library
from requests_counter.reqcounter import ReqCounter
import asyncio
app = FastAPI()
# 2. Create an ReqCounter object with the url to redis instance as parameter
cl = ReqCounter("redis://localhost")
# 3. populate the Object with a list of tuple (key, max_value)
asyncio.create_task(cl.setup_api_key([("my-api-key-test", 100)]))
asyncio.create_task(cl.setup_source(["source1", "source2"]))
# 4. Declare a function to be injected into Depends module.
# It will decrease the max_value for each request. It will raise a 429 HTTPException when max_value is 0.
# It will raise a 403 HTTPException when source is not in the list.
async def check_key(apiKey: str = Header(None), source: str = Header(None)):
res = await cl.decrease(apiKey)
if res is False:
raise HTTPException(400, "User Requests Limit Exceeded")
if await cl.check_source(source) is False:
raise HTTPException(403, "Forbidden")
return apiKey
# 5. Inject the check_key function to endpoint
@app.get("/consume")
async def consume_key(apiKey=Depends(check_key)):
return {"job": "done", "apiKey": apiKey}
To run this example
$> uvicorn requests_counter.example:app --reload --port 8080
Command below run the server to interact with your redis instance for
$> uvicorn requests_counter.api:app --reload --port 8080
Run http://locahost:8080/docs
for documentation.
FAQs
A tool to monitor the number of HTTP requests through an _apiKey_ in the HTTP Header.
We found that requests-counter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.