-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix throttling for subscription service user (#32473)
* feat: add subscriptions_worker to ent access list * fix: add throttle for entitlement APIS
- Loading branch information
Showing
3 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
Throttle classes for the entitlements API. | ||
""" | ||
|
||
from django.conf import settings | ||
from rest_framework.throttling import UserRateThrottle | ||
|
||
|
||
class ServiceUserThrottle(UserRateThrottle): | ||
"""A throttle allowing service users to override rate limiting""" | ||
|
||
def allow_request(self, request, view): | ||
"""Returns True if the request is coming from one of the service users | ||
and defaults to UserRateThrottle's configured setting otherwise. | ||
""" | ||
service_users = [ | ||
settings.SUBSCRIPTIONS_SERVICE_WORKER_USERNAME | ||
] | ||
if request.user.username in service_users: | ||
return True | ||
return super().allow_request(request, view) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters