1111import traceback
1212from enum import Enum
1313from os import path , remove
14- from typing import Dict , List , NamedTuple , Optional , Tuple
14+ from typing import Any , Dict , List , NamedTuple , Optional , Tuple
1515
1616import requests
1717from urwid import display_common , set_encoding
@@ -206,10 +206,9 @@ def styled_input(label: str) -> str:
206206 return input (in_color ("blue" , label ))
207207
208208
209- def get_login_id (realm_url : str ) -> str :
210- res_json = requests .get (url = f"{ realm_url } /api/v1/server_settings" ).json ()
211- require_email_format_usernames = res_json ["require_email_format_usernames" ]
212- email_auth_enabled = res_json ["email_auth_enabled" ]
209+ def get_login_id (server_properties : Dict [str , Any ]) -> str :
210+ require_email_format_usernames = server_properties ["require_email_format_usernames" ]
211+ email_auth_enabled = server_properties ["email_auth_enabled" ]
213212
214213 if not require_email_format_usernames and email_auth_enabled :
215214 label = "Email or Username: "
@@ -225,8 +224,11 @@ def get_login_id(realm_url: str) -> str:
225224def get_api_key (realm_url : str ) -> Optional [Tuple [str , str ]]:
226225 from getpass import getpass
227226
228- login_id = get_login_id (realm_url )
227+ server_properties = requests .get (url = f"{ realm_url } /api/v1/server_settings" ).json ()
228+
229+ login_id = get_login_id (server_properties )
229230 password = getpass (in_color ("blue" , "Password: " ))
231+
230232 response = requests .post (
231233 url = f"{ realm_url } /api/v1/fetch_api_key" ,
232234 data = {
0 commit comments