Allow rate limiting on a per env basis

- switched off on prod by default
This commit is contained in:
Martyn Inglis
2017-04-25 09:54:09 +01:00
parent 926b8a60f9
commit 803c21865b
3 changed files with 35 additions and 12 deletions

View File

@@ -10,17 +10,18 @@ from notifications_utils.clients import redis
def check_service_over_api_rate_limit(service, api_key):
cache_key = redis.rate_limit_cache_key(service.id, api_key.key_type)
rate_limit = current_app.config['API_KEY_LIMITS'][api_key.key_type]['limit']
interval = current_app.config['API_KEY_LIMITS'][api_key.key_type]['interval']
if redis_store.exceeded_rate_limit(
cache_key,
rate_limit,
interval):
raise RateLimitError(
rate_limit,
interval,
api_key.key_type)
if current_app.config['API_RATE_LIMIT_ENABLED']:
cache_key = redis.rate_limit_cache_key(service.id, api_key.key_type)
rate_limit = current_app.config['API_KEY_LIMITS'][api_key.key_type]['limit']
interval = current_app.config['API_KEY_LIMITS'][api_key.key_type]['interval']
if redis_store.exceeded_rate_limit(
cache_key,
rate_limit,
interval):
raise RateLimitError(
rate_limit,
interval,
api_key.key_type)
def check_service_over_daily_message_limit(key_type, service):