Skip to content

Commit

Permalink
Add optional external rate limit file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Mar 15, 2024
1 parent 43abf6f commit ddaa49e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mapit/ratelimitcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
}
_sentinel = object()

CONFIG_FILE = getattr(settings, 'MAPIT_RATE_LIMIT_FILE', {})
if isinstance(CONFIG_FILE, dict) and CONFIG_FILE.get('internal_ips'):
CONFIG['ips'] += CONFIG_FILE['internal_ips']['ipv4']
CONFIG['ips'] += CONFIG_FILE['internal_ips']['ipv6']

Check warning on line 20 in mapit/ratelimitcache.py

View check run for this annotation

Codecov / codecov/patch

mapit/ratelimitcache.py#L19-L20

Added lines #L19 - L20 were not covered by tests


def ratelimit(_f=_sentinel, **kwargs):
if _f is _sentinel:
Expand Down
8 changes: 8 additions & 0 deletions project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
# excluded from rate limiting. Optional.
MAPIT_RATE_LIMIT = config.get('RATE_LIMIT', {})

MAPIT_RATE_LIMIT_FILE = config.get('RATE_LIMIT_FILE')
if MAPIT_RATE_LIMIT_FILE:
try:
with open(MAPIT_RATE_LIMIT_FILE, 'r') as fp:
MAPIT_RATE_LIMIT_FILE = yaml.load(fp, Loader=yaml.SafeLoader)
except:
MAPIT_RATE_LIMIT_FILE = None

# A GA code for analytics
GOOGLE_ANALYTICS = config.get('GOOGLE_ANALYTICS', '')

Expand Down

0 comments on commit ddaa49e

Please sign in to comment.