Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable throttling for priveleged users #763

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

@adamstankiewicz adamstankiewicz Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] Will settings.PRIVELEGED_USER_IDS be configured using license-manager's local User.id, or is the hope to configure the lms_user_id associated with these privileged users?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered in Slack: local User.id

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