From e1d906e8a83a76be421d76d972d22e0e225669f6 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:15:12 +0530 Subject: [PATCH 1/2] Add support for alternate token paths for debugging --- api/auth.py | 25 ++++++++++++++++--------- api/runtimeconfig.json | 1 + 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/api/auth.py b/api/auth.py index 8f1e9d7e..ccca5608 100644 --- a/api/auth.py +++ b/api/auth.py @@ -11,16 +11,23 @@ # Commands def get_token(): - """Returns the token in `runtimeconfig.json`, if it exists.\nIf there is no token provided in the config, it will manually ask the user for input and it will autosave it.""" + """Returns the token in `runtimeconfig.json`, if it exists.\n\nIf there is no token provided in the config, it will try accessing the alternate token location.\n\nIf no alternate token exists, it will manually ask the user for input and it will autosave it to `runtimeconfig.json`.""" if config["token"] == "": - print("[!] Looks like you didn't input a token. Would you like to import one?") - arg1 = input("[Yes/No/y/n] > ") - if arg1.lower() == "y": - arg2 = input("Enter your custom token: ") - config["token"] = str(arg2) - with open(f'{wdir}/api/runtimeconfig.json', 'w+') as f: json.dump(config, f, indent=4) - print("[✅] Setup successful!") - elif arg1.lower() == "n": return + if config["alt_token_path"] != "": + tkn = str() + with open(config["alt_token_path"], 'r', encoding="utf-8") as f: + tkn = f + f.close() + return str(tkn) + else: + print("[!] Looks like you didn't input a token. Would you like to import one?") + arg1 = input("[Yes/No/y/n] > ") + if arg1.lower() == "y" or arg1.lower() == "yes": + arg2 = input("Enter your custom token: ") + config["token"] = str(arg2) + with open(f'{wdir}/api/runtimeconfig.json', 'w+') as f: json.dump(config, f, indent=4) + print("[✅] Setup successful!") + elif arg1.lower() == "n" or arg1.lower() == "no": return return str(config["token"]) def get_secret(): diff --git a/api/runtimeconfig.json b/api/runtimeconfig.json index 1ad0f84d..4da3b05c 100644 --- a/api/runtimeconfig.json +++ b/api/runtimeconfig.json @@ -1,5 +1,6 @@ { "token": "", + "alt_token_path": "", "secret": "", "public_key": "", "runtime_options": { From 0746bfd6d7b0c539f63f4c24656340453e8f25b9 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sat, 30 Mar 2024 14:55:39 +0530 Subject: [PATCH 2/2] Call `read()` function on fetching token from `alt_token_path` --- api/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/auth.py b/api/auth.py index ccca5608..78d7e2fa 100644 --- a/api/auth.py +++ b/api/auth.py @@ -16,7 +16,7 @@ def get_token(): if config["alt_token_path"] != "": tkn = str() with open(config["alt_token_path"], 'r', encoding="utf-8") as f: - tkn = f + tkn = f.read() f.close() return str(tkn) else: