1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/docs/dev/modules/rest_throttles.py.md
Matt Griswold 505760aa8d Support 202203 (#1144)
* Do not show objects in status "pending" on the UI #784

* Fix peeringdb.js bug introduced in #784

* 500 Error during login for 2FA enabled accounts with unverified email address #996

* Django-Admin: adding a network with existing asn fails with internal error #1035

* Some command-line-tool executions are not logged #1119

* Ops: API throttling of repeated requests #1126

* Ops: response header X-Auth-ID to augment logging #1120

* Allow rate-limiting of melissa enabled api functionality. #1124

* State / Province normalization #1079

* Log melissa requests #1122

* remove debug messages

* bump django-handleref to 1.0.2

* Need consolidated app logs #845

* pin django peeringdb to 2.13 and relock poetry

* pin django-restframework-apikey to 2.1.0

* linting

* migrations

* docs regenerate

* docs

* linting

Co-authored-by: David Poarch <dpoarch@20c.com>
Co-authored-by: Stefan Pratter <stefan@20c.com>
2022-04-12 15:39:19 -05:00

3.7 KiB

Generated from rest_throttles.py on 2022-04-12 16:41:02.631987

peeringdb_server.rest_throttles

Custom rate limit handlers for the REST API.

Classes


APIAnonUserThrottle

APIAnonUserThrottle(peeringdb_server.rest_throttles.TargetedRateThrottle)

General rate limiting for anonymous users via the request ip-address

APIUserThrottle

APIUserThrottle(peeringdb_server.rest_throttles.TargetedRateThrottle)

General rate limiting for authenticated requests (users or orgs)

FilterDistanceThrottle

FilterDistanceThrottle(peeringdb_server.rest_throttles.FilterThrottle)

Rate limiting for ?distance= queries.

FilterThrottle

FilterThrottle(rest_framework.throttling.SimpleRateThrottle)

Base class for API throttling targeted at specific query filters.

Scope name will be 'filter_{self.filter_name}'

Methods

_init_

def __init__(self)

Initialize self. See help(type(self)) for accurate signature.


allow_request

def allow_request(self, request, view)

Implement the check to see if the request should be throttled.

On success calls throttle_success. On failure calls throttle_failure.


get_cache_key

def get_cache_key(self, request, view)

Should return a unique cache-key which can be used for throttling. Must be overridden.

May return None if the request should not be throttled.


IXFImportThrottle

IXFImportThrottle(rest_framework.throttling.UserRateThrottle)

Limits the rate of API calls that may be made by a given user.

The user id will be used as a unique cache key if the user is authenticated. For anonymous requests, the IP address of the request will be used.

Methods

get_cache_key

def get_cache_key(self, request, view)

Should return a unique cache-key which can be used for throttling. Must be overridden.

May return None if the request should not be throttled.


MelissaThrottle

MelissaThrottle(peeringdb_server.rest_throttles.TargetedRateThrottle)

Rate limits requests that do a melissa lookup (#1124)

ResponseSizeThrottle

ResponseSizeThrottle(peeringdb_server.rest_throttles.TargetedRateThrottle)

Rate limit repeated requests based request content-size

See #1126 for rationale

Class Methods

cache_response_size

def cache_response_size(cls, request, size)

Caches the response size for the request

The api renderer (renderers.py) calls this automatically when it renders the response


expected_response_size

def expected_response_size(cls, request)

Returns the expected response size (number of bytes) for the request as int

It will return None if there is no cached response size for the request.


size_cache_key

def size_cache_key(cls, request)

Returns the cache key to use for storing response size cache


TargetedRateThrottle

TargetedRateThrottle(rest_framework.throttling.SimpleRateThrottle)

Base class for targeted rate throttling depending on authentication status

Rate throttle by - user (sess-auth, basic-auth, key), - org (key), - anonymous (inet, cdir)

Methods

_init_

def __init__(self)

Initialize self. See help(type(self)) for accurate signature.


allow_request

def allow_request(self, request, view)

Implement the check to see if the request should be throttled.

On success calls throttle_success. On failure calls throttle_failure.


get_cache_key

def get_cache_key(self, request, view)

Should return a unique cache-key which can be used for throttling. Must be overridden.

May return None if the request should not be throttled.


get_rate

def get_rate(self)

Determine the string representation of the allowed request rate.