Files
zulip/zerver/management/commands/clear_auth_rate_limit_history.py
Mateusz Mandera 6ffbb6081b rate_limit: Add management command to reset auth rate limit.
The auth attempt rate limit is quite low (on purpose), so this can be a
common scenario where a user asks their admin to reset the limit instead
of waiting. We should provide a tool for administrators to handle such
requests without fiddling around with code in manage.py shell.

(cherry picked from commit fdbde59b07)
2021-08-23 11:54:02 -07:00

23 lines
841 B
Python

from argparse import ArgumentParser
from typing import Any
from django.core.management.base import CommandError
from zerver.lib.management import ZulipBaseCommand
from zproject.backends import RateLimitedAuthenticationByUsername
class Command(ZulipBaseCommand):
help = """Reset the rate limit for authentication attempts for username."""
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument("-u", "--username", help="Username to reset the rate limit for.")
def handle(self, *args: Any, **options: Any) -> None:
if not options["username"]:
self.print_help("./manage.py", "clear_auth_rate_limit_history")
raise CommandError("Please enter a username")
username = options["username"]
RateLimitedAuthenticationByUsername(username).clear_history()