Skip to content

Commit 8e0d32e

Browse files
authored
Merge pull request #52 from onaio/add-throttling
Add throttling configurations
2 parents 66ef5e9 + 1258e89 commit 8e0d32e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,8 @@ onadata_crf_cookie_secure: True
326326
onadata_crf_use_sessions: True
327327
onadata_session_cookie_secure: True
328328
onadata_session_cookie_samesite: "Strict"
329+
330+
# throttling
331+
onadata_enable_requests_throttling: False
332+
onadata_throttling_rate: 50
333+
onadata_throttling_user_agents: []

templates/onadata_checkout_path/onadata/preset/local_settings.py.j2

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,27 @@ REST_FRAMEWORK = {
9090
'rest_framework.renderers.BrowsableAPIRenderer',
9191
'rest_framework_csv.renderers.CSVRenderer',
9292
),
93+
{% if onadata_enable_requests_throttling|default(false) %}
94+
'DEFAULT_THROTTLE_CLASSES': (
95+
'onadata.libs.throttle.RequestHeaderThrottle',
96+
),
97+
'DEFAULT_THROTTLE_RATES': {
98+
'header': '{{ onadata_throttling_rate }}/minute'
99+
}
100+
{% endif %}
93101
}
102+
{% if onadata_enable_requests_throttling|default(false) %}
103+
THROTTLE_HEADERS = {
104+
"HTTP_USER_AGENT": [
105+
{% for user_agent in onadata_throttling_user_agents %}
106+
'{{ user_agent }}',
107+
{% endfor %}
108+
],
109+
{% if onadata_throttling_remote_user is defined %}
110+
"REMOTE_USER": '{{ onadata_throttling_remote_user }}'
111+
{% endif %}
112+
}
113+
{% endif %}
94114
OAUTH2_PROVIDER['AUTHORIZATION_CODE_EXPIRE_SECONDS'] = 600
95115
OAUTH2_PROVIDER['PKCE_REQUIRED'] = {{ onadata_oauth2_pkce_required }}
96116
BROKER_TRANSPORT = 'librabbitmq'

0 commit comments

Comments
 (0)