mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
a0f1970fec
* Carrier object implementation #909 * API keys: disabling of user account by a PeeringDB admin does not disable access via a User API key. Also no disable mech, only revoke. #1140 * Ops: django needs lightweight healthcheck route that confirms database connectivity #1284 * Ops: various indexes are needed #1285 * API requests with invalid Authentication headers should notify users in some way. #1220 * Allow user to change account username #1130 * UX to remove carriers from facilities more inline the other similar UX * more UX fixes for removing carriers from facilities * Cache hints are needed for optimal CDN use #970 * fixes Commandline tool "Run command" button gone #1278 * RIR status gets deleted when changes are made to the network #1279 * Improve MTU field #658 * CSRF cookie not set error from email confirmation view #1296 * expose CSP_CONNECT_SRC * fix confirm email path checking in session middleware * Ops: Emails to OPERATIONS_EMAIL need to be rate-limited #1282 * add website field to carrier ux * website field on carrier optional with org fallback * linting * add *.google-analytics.com to CSP_CONNECT_SRC * poetry relock * fix issues with confirm-email reverse during session creation validation * fix tests * fix tests * pin django-peeringdb to support_202211 * linting * django ratelimit to <4 * regen docs * fix automated net stats to only include networks with status `ok` #1283 * linting * poetry lock Co-authored-by: Matt Griswold <grizz@20c.com>
37 lines
921 B
Python
37 lines
921 B
Python
from django.conf import settings
|
|
from django.core.cache import caches
|
|
from django.utils.log import AdminEmailHandler
|
|
|
|
|
|
class ThrottledAdminEmailHandler(AdminEmailHandler):
|
|
|
|
"""
|
|
Throttled admin email handler
|
|
"""
|
|
|
|
CACHE_KEY = "THROTTLE_ERROR_EMAILS"
|
|
|
|
@property
|
|
def cache(self):
|
|
"""
|
|
returns the specific cache handler set up for this purpose
|
|
"""
|
|
return caches["error_emails"]
|
|
|
|
def increment_counter(self):
|
|
try:
|
|
self.cache.incr(self.CACHE_KEY)
|
|
except ValueError:
|
|
self.cache.set(self.CACHE_KEY, 1, settings.ERROR_EMAILS_PERIOD)
|
|
return self.cache.get(self.CACHE_KEY)
|
|
|
|
def emit(self, record):
|
|
try:
|
|
counter = self.increment_counter()
|
|
except Exception:
|
|
pass
|
|
else:
|
|
if counter > settings.ERROR_EMAILS_LIMIT:
|
|
return
|
|
super().emit(record)
|