Skip to content

Commit

Permalink
feat: disable throttling for priveleged users
Browse files Browse the repository at this point in the history
Introduces a setting PRIVELEGED_USER_IDS, such that any user
id in the list is exempt from throttling limits.
  • Loading branch information
iloveagent57 committed Feb 11, 2025
1 parent f885f30 commit 3d880fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 18 additions & 3 deletions license_manager/apps/core/throttles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@
so that we can throttle both bursty and sustained
throughtput.
"""

from django.conf import settings
from rest_framework.throttling import UserRateThrottle


class UserBurstRateThrottle(UserRateThrottle):
class PrivelegedUserThrottle(UserRateThrottle):
"""
Skips throttling is the requesting authenticated user
is in the list of priveleged user ids.
is staff or superuser.
"""
def allow_request(self, request, view):
user = request.user

if user and user.is_authenticated and user.id in settings.PRIVELEGED_USER_IDS:
return True

return super().allow_request(request, view)


class UserBurstRateThrottle(PrivelegedUserThrottle):
scope = 'user_burst'


class UserSustainedRateThrottle(UserRateThrottle):
class UserSustainedRateThrottle(PrivelegedUserThrottle):
scope = 'user_sustained'
3 changes: 3 additions & 0 deletions license_manager/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
}
}

# Maintain a list of user ids to opt-out of API throttle limits
PRIVELEGED_USER_IDS = []

# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/

Expand Down

0 comments on commit 3d880fc

Please sign in to comment.