Skip to content

Commit

Permalink
Setting default throttle class to ServiceUserThrottle
Browse files Browse the repository at this point in the history
  • Loading branch information
madnihamza1841 authored Jan 25, 2022
1 parent c3a6d37 commit 75c5278
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ecommerce/extensions/api/throttles.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ 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.ECOMMERCE_SERVICE_WORKER_USERNAME, settings.PROSPECTUS_WORKER_USERNAME]
service_users = [
settings.ECOMMERCE_SERVICE_WORKER_USERNAME,
settings.PROSPECTUS_WORKER_USERNAME,
settings.DISCOVERY_SERVICE_WORKER_USERNAME,
]
if request.user.username in service_users:
return True
return super(ServiceUserThrottle, self).allow_request(request, view)
5 changes: 4 additions & 1 deletion ecommerce/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@
# Service user for worker processes.
ECOMMERCE_SERVICE_WORKER_USERNAME = 'ecommerce_worker'

# Service user for Discovery worker processes.
DISCOVERY_SERVICE_WORKER_USERNAME = 'discovery_worker'

# Worker user used by prospectus to query ecommerce
PROSPECTUS_WORKER_USERNAME = 'prospectus_worker'

Expand Down Expand Up @@ -588,7 +591,7 @@
'DEFAULT_PAGINATION_CLASS': 'ecommerce.extensions.api.pagination.PageNumberPagination',
'PAGE_SIZE': 20,
'DEFAULT_THROTTLE_CLASSES': (
'rest_framework.throttling.UserRateThrottle',
'ecommerce.extensions.api.throttles.ServiceUserThrottle',
),
'DEFAULT_THROTTLE_RATES': {
'user': '75/minute',
Expand Down
3 changes: 3 additions & 0 deletions ecommerce/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,6 @@ def get_env_setting(setting):

DCS_SESSION_COOKIE_SAMESITE = config_from_yaml.get('DCS_SESSION_COOKIE_SAMESITE', DCS_SESSION_COOKIE_SAMESITE)
DCS_SESSION_COOKIE_SAMESITE_FORCE_ALL = config_from_yaml.get('DCS_SESSION_COOKIE_SAMESITE_FORCE_ALL', DCS_SESSION_COOKIE_SAMESITE_FORCE_ALL)

# Service user for Discovery worker processes.
DISCOVERY_SERVICE_WORKER_USERNAME = config_from_yaml.get('DISCOVERY_SERVICE_WORKER_USERNAME', DISCOVERY_SERVICE_WORKER_USERNAME)

0 comments on commit 75c5278

Please sign in to comment.