Added setting to disable throttling the API
This commit is contained in:
Родитель
446df110fc
Коммит
9d62357c69
|
@ -1567,3 +1567,6 @@ ALLOW_TASTYPIE_SERVICES = False
|
|||
# The version we append to the app feature profile. Bump when we add new app
|
||||
# features to the `AppFeatures` model.
|
||||
APP_FEATURES_VERSION = 1
|
||||
|
||||
# Whether to throttle API requests. Default is True. Disable where appropriate.
|
||||
API_THROTTLE = True
|
||||
|
|
|
@ -4,6 +4,7 @@ import logging
|
|||
import sys
|
||||
import traceback
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf.urls.defaults import url
|
||||
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
||||
from django.http import HttpResponseNotFound
|
||||
|
@ -188,7 +189,8 @@ class Marketplace(object):
|
|||
``Resource._meta``.
|
||||
"""
|
||||
# Never throttle users with Apps:APIUnthrottled.
|
||||
if not acl.action_allowed(request, 'Apps', 'APIUnthrottled'):
|
||||
if (settings.API_THROTTLE and
|
||||
not acl.action_allowed(request, 'Apps', 'APIUnthrottled')):
|
||||
identifiers = [a.get_identifier(request) for a in self._auths()]
|
||||
|
||||
# Check to see if they should be throttled.
|
||||
|
|
|
@ -146,6 +146,20 @@ class TestThrottling(TestCase):
|
|||
sbt.return_value = True
|
||||
self.no_throttle_expected()
|
||||
|
||||
def test_throttled_user_setting_enabled(self):
|
||||
with self.settings(API_THROTTLE=True):
|
||||
ACLMiddleware().process_request(self.request)
|
||||
with self.mocked_sbt as sbt:
|
||||
sbt.return_value = True
|
||||
self.throttle_expected()
|
||||
|
||||
def test_throttled_user_setting_disabled(self):
|
||||
with self.settings(API_THROTTLE=False):
|
||||
ACLMiddleware().process_request(self.request)
|
||||
with self.mocked_sbt as sbt:
|
||||
sbt.return_value = True
|
||||
self.no_throttle_expected()
|
||||
|
||||
|
||||
class FilteredCORS(CORSResource, MarketplaceResource):
|
||||
|
||||
|
|
|
@ -207,3 +207,5 @@ LESS_PREPROCESS = True
|
|||
XSENDFILE_HEADER = 'X-Accel-Redirect'
|
||||
|
||||
ALLOW_SELF_REVIEWS = True
|
||||
|
||||
API_THROTTLE = False
|
||||
|
|
|
@ -197,3 +197,5 @@ AWS_SECRET_ACCESS_KEY = private.AWS_SECRET_ACCESS_KEY
|
|||
AWS_STORAGE_BUCKET_NAME = private.AWS_STORAGE_BUCKET_NAME
|
||||
|
||||
RAISE_ON_SIGNAL_ERROR = True
|
||||
|
||||
API_THROTTLE = False
|
||||
|
|
Загрузка…
Ссылка в новой задаче