11# Copyright 2015, 2016 OpenMarket Ltd
22# Copyright 2018 New Vector
3+ # Copyright 2021 The Matrix.org Foundation C.I.C.
34#
45# Licensed under the Apache License, Version 2.0 (the "License");
56# you may not use this file except in compliance with the License.
1920import hmac
2021import logging
2122import sys
23+ from typing import Callable , Optional
2224
2325import requests as _requests
2426import yaml
2527
2628
2729def request_registration (
28- user ,
29- password ,
30- server_location ,
31- shared_secret ,
32- admin = False ,
33- user_type = None ,
30+ user : str ,
31+ password : str ,
32+ server_location : str ,
33+ shared_secret : str ,
34+ admin : bool = False ,
35+ user_type : Optional [ str ] = None ,
3436 requests = _requests ,
35- _print = print ,
36- exit = sys .exit ,
37- ):
37+ _print : Callable [[ str ], None ] = print ,
38+ exit : Callable [[ int ], None ] = sys .exit ,
39+ ) -> None :
3840
3941 url = "%s/_synapse/admin/v1/register" % (server_location .rstrip ("/" ),)
4042
@@ -65,13 +67,13 @@ def request_registration(
6567 mac .update (b"\x00 " )
6668 mac .update (user_type .encode ("utf8" ))
6769
68- mac = mac .hexdigest ()
70+ hex_mac = mac .hexdigest ()
6971
7072 data = {
7173 "nonce" : nonce ,
7274 "username" : user ,
7375 "password" : password ,
74- "mac" : mac ,
76+ "mac" : hex_mac ,
7577 "admin" : admin ,
7678 "user_type" : user_type ,
7779 }
@@ -91,10 +93,17 @@ def request_registration(
9193 _print ("Success!" )
9294
9395
94- def register_new_user (user , password , server_location , shared_secret , admin , user_type ):
96+ def register_new_user (
97+ user : str ,
98+ password : str ,
99+ server_location : str ,
100+ shared_secret : str ,
101+ admin : Optional [bool ],
102+ user_type : Optional [str ],
103+ ) -> None :
95104 if not user :
96105 try :
97- default_user = getpass .getuser ()
106+ default_user : Optional [ str ] = getpass .getuser ()
98107 except Exception :
99108 default_user = None
100109
@@ -123,8 +132,8 @@ def register_new_user(user, password, server_location, shared_secret, admin, use
123132 sys .exit (1 )
124133
125134 if admin is None :
126- admin = input ("Make admin [no]: " )
127- if admin in ("y" , "yes" , "true" ):
135+ admin_inp = input ("Make admin [no]: " )
136+ if admin_inp in ("y" , "yes" , "true" ):
128137 admin = True
129138 else :
130139 admin = False
@@ -134,7 +143,7 @@ def register_new_user(user, password, server_location, shared_secret, admin, use
134143 )
135144
136145
137- def main ():
146+ def main () -> None :
138147
139148 logging .captureWarnings (True )
140149
0 commit comments