2017-11-16 00:55:49 +01:00
|
|
|
from argparse import ArgumentParser
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
|
|
|
|
2013-07-29 23:03:31 +02:00
|
|
|
from zerver.lib.initial_password import initial_password
|
2017-07-18 19:28:16 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2018-08-01 10:53:40 +02:00
|
|
|
from zerver.lib.users import get_api_key
|
2012-10-10 20:42:04 +02:00
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2017-07-18 19:28:16 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2012-10-12 17:10:59 +02:00
|
|
|
help = "Print the initial password and API key for accounts as created by populate_db"
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
fmt = "%-30s %-16s %-32s"
|
2012-10-10 20:42:04 +02:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2017-10-27 12:57:54 +02:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
2021-02-12 08:20:45 +01:00
|
|
|
"emails",
|
|
|
|
metavar="<email>",
|
|
|
|
nargs="*",
|
2021-02-12 08:19:30 +01:00
|
|
|
help="email of user to show password and API key for",
|
|
|
|
)
|
2017-07-18 19:28:16 +02:00
|
|
|
self.add_realm_args(parser)
|
2015-08-21 02:10:41 +02:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2017-10-27 12:57:54 +02:00
|
|
|
def handle(self, *args: Any, **options: str) -> None:
|
2017-07-18 19:28:16 +02:00
|
|
|
realm = self.get_realm(options)
|
2021-02-12 08:20:45 +01:00
|
|
|
print(self.fmt % ("email", "password", "API key"))
|
|
|
|
for email in options["emails"]:
|
|
|
|
if "@" not in email:
|
|
|
|
print(f"ERROR: {email} does not look like an email address")
|
2012-10-10 20:42:04 +02:00
|
|
|
continue
|
2018-08-01 10:53:40 +02:00
|
|
|
user = self.get_user(email, realm)
|
|
|
|
print(self.fmt % (email, initial_password(email), get_api_key(user)))
|