Add rate limiting for any API calls

Review Request #8839 — Created March 24, 2017 and discarded

Information

Djblets
master

Reviewers

There's been a request to create a rate-limit for API calls. I have updated the ratelimit.py file that will allow rate limiting of API calls by either an authenticated user or an IP address.

None at the moment.

Description From Last Updated

local variable 'DEFAULT_RATE' is assigned to but never used

reviewbotreviewbot

'django.test.utils.override_settings' imported but unused

reviewbotreviewbot

'django.conf.settings' imported but unused

reviewbotreviewbot

This should not be ALLCAPS. Only class-level and top-level constants are all-caps.

brenniebrennie

This can be simplified to: if not api_limit: #... else: # ...

brenniebrennie

Shouldnt the default param be self.DEFAULT_RATE ?

brenniebrennie

local variable 'DEFAULT_RATE' is assigned to but never used

reviewbotreviewbot

This should be the default_rate

brenniebrennie

'django.conf.settings' imported but unused

reviewbotreviewbot

Re-flow this to 79ch wide.

brenniebrennie

This should use a constant instead of repeating 5/m everywhere.

brenniebrennie

undefined name 'WebAPIResourceRateLimitMixin'

reviewbotreviewbot

undefined name 'increment'

reviewbotreviewbot

undefined name '_'

reviewbotreviewbot

'djblets.webapi.resources.mixins.api_ratelimit.WebAPIResourceMixin' imported but unused

reviewbotreviewbot

undefined name 'increment'

reviewbotreviewbot

undefined name '_'

reviewbotreviewbot

'djblets.auth.ratelimit.Rate' imported but unused

reviewbotreviewbot

'djblets.auth.ratelimit.is_ratelimited' imported but unused

reviewbotreviewbot

'warnings' imported but unused

reviewbotreviewbot

'django.db.models.Model' imported but unused

reviewbotreviewbot

'django.utils.six' imported but unused

reviewbotreviewbot

'django.utils.translation.ugettext_lazy as _' imported but unused

reviewbotreviewbot

'djblets.auth.ratelimit.Rate' imported but unused

reviewbotreviewbot

'djblets.webapi.resources.registry.unregister_resource_for_model' imported but unused

reviewbotreviewbot

'djblets.webapi.resources.registry.register_resource_for_model' imported but unused

reviewbotreviewbot

local variable 'result' is assigned to but never used

reviewbotreviewbot

'djblets.auth.ratelimit.Rate' imported but unused

reviewbotreviewbot

'djblets.webapi.resources.registry.unregister_resource' imported but unused

reviewbotreviewbot
Checks run (1 failed, 1 succeeded, 1 failed with error)
JSHint passed.
PEP8 Style Checker internal error.
Pyflakes failed.

Pyflakes

RK
RK
RK
Review request changed
Change Summary:

Accidentally uploaded both patches to same review request - fixed.

Checks run (1 failed, 1 succeeded, 1 failed with error)

JSHint passed.
PEP8 Style Checker internal error.
Pyflakes failed.

Pyflakes

brennie
  1. 
      
  2. djblets/auth/ratelimit.py (Diff revision 2)
     
     
     
     
     
    Show all issues

    This should not be ALLCAPS. Only class-level and top-level constants are all-caps.

  3. djblets/auth/ratelimit.py (Diff revision 2)
     
     
     
     
    Show all issues

    This can be simplified to:

    if not api_limit:
        #...
    else:
        # ...
    
  4. djblets/auth/ratelimit.py (Diff revision 2)
     
     
    Show all issues

    Shouldnt the default param be self.DEFAULT_RATE ?

  5. djblets/auth/ratelimit.py (Diff revision 2)
     
     
    Show all issues

    This should be the default_rate

  6. djblets/webapi/resources/mixins/api_ratelimit.py (Diff revision 2)
     
     
     
     
     
    Show all issues

    Re-flow this to 79ch wide.

  7. Show all issues

    This should use a constant instead of repeating 5/m everywhere.

  8. 
      
RK
Review request changed
Commit:
18936d77b24c18efdb1f351a58436d2edf8c0458
dc795ba46ebe4549d55a7c057963e299597c0e35

Checks run (1 failed, 1 succeeded, 1 failed with error)

JSHint passed.
PEP8 Style Checker internal error.
Pyflakes failed.

Pyflakes

RK
Review request changed

Checks run (1 failed, 1 succeeded, 1 failed with error)

JSHint passed.
PEP8 Style Checker internal error.
Pyflakes failed.

Pyflakes

RK
Review request changed
Change Summary:

Added test for new mixin, along with documentation.

Checks run (1 failed, 1 succeeded, 1 failed with error)

JSHint passed.
PEP8 Style Checker internal error.
Pyflakes failed.

Pyflakes

RK
Review request changed

Checks run (1 failed, 1 succeeded, 1 failed with error)

JSHint passed.
PEP8 Style Checker internal error.
Pyflakes failed.

Pyflakes

RK
RK
RK
RK
Review request changed

Checks run (1 failed, 1 succeeded, 1 failed with error)

JSHint passed.
PEP8 Style Checker internal error.
Pyflakes failed.

Pyflakes

RK
RK
david
Review request changed
Status:
Discarded
Change Summary:

Discarding in favor of https://reviews.reviewboard.org/r/9114/