refactor(api): source API_KEY_RATE_LIMIT from settings, drop service token throttle#9161
Conversation
…token throttle - Define API_KEY_RATE_LIMIT in plane/settings/common.py and read it via django.conf.settings in ApiKeyRateThrottle instead of os.environ. - Remove ServiceTokenRateThrottle and the service-token branch in BaseAPIView.get_throttles; all API key requests now go through ApiKeyRateThrottle.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis pull request consolidates API rate limiting configuration by centralizing the ChangesAPI Rate Limiting Consolidation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Refactors the API throttling layer by sourcing the API key rate limit from Django settings instead of reading the env var directly, and removes the now-unused ServiceTokenRateThrottle class along with its per-request DB lookup in BaseAPIView.get_throttles.
Changes:
- Add
API_KEY_RATE_LIMITsetting (default60/minute, env-overridable) inplane/settings/common.py. ApiKeyRateThrottle.ratenow reads fromsettings.API_KEY_RATE_LIMITinstead ofos.environ.get;ServiceTokenRateThrottleclass deleted.BaseAPIView.get_throttlessimplified to always return[ApiKeyRateThrottle()], removing the per-requestAPIToken(is_service=True)query.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apps/api/plane/settings/common.py | Adds API_KEY_RATE_LIMIT setting sourced from env with 60/minute default. |
| apps/api/plane/api/rate_limit.py | Switches throttle rate to settings.API_KEY_RATE_LIMIT and removes ServiceTokenRateThrottle. |
| apps/api/plane/api/views/base.py | Drops APIToken/ServiceTokenRateThrottle imports and the service-token branch in get_throttles. |
|
Actionable comments posted: 0 |
Description
Two small cleanups in the API throttling layer:
API_KEY_RATE_LIMITnow flows through Django settings. AddedAPI_KEY_RATE_LIMITtoplane/settings/common.py(defaults to60/minute, overridable via env).ApiKeyRateThrottlereadssettings.API_KEY_RATE_LIMITviadjango.conf.settingsinstead of callingos.environ.getdirectly. Behavior is unchanged — the same env var and default still apply, but the read path is now consistent with the rest of the project.ServiceTokenRateThrottle. Service tokens are no longer used, so the dedicated300/minutethrottle class and the conditional branch inBaseAPIView.get_throttlesthat looked upAPIToken(is_service=True)per request are gone. All API key requests now go throughApiKeyRateThrottle. This also removes an extra DB query on every API request.The existing env wiring in
deployments/aio/community/*anddeployments/cli/community/*already exportsAPI_KEY_RATE_LIMIT— no deployment changes needed.Type of Change
Screenshots and Media (if applicable)
Test Scenarios
/api/v1/...endpoint withX-Api-Keyset to a regular API token; verify theX-RateLimit-Remaining/X-RateLimit-Resetresponse headers appear and counters tick down with each request.API_KEY_RATE_LIMIT=10/minutein the API container env and confirm the throttle picks up the new limit after restart.is_service=True) are now subject to the same60/minute(or env-configured) limit as regular API keys — no separate 300/minute bucket.References
ServiceTokenRateThrottleandis_service-based throttle dispatch inapps/api/plane/api/views/base.py.🤖 Generated with Claude Code
Summary by CodeRabbit