[+] Reordered generic_executor.py

This commit is contained in:
Charles Le Maux 2024-09-10 13:26:12 +02:00
parent 1b1df35a14
commit 315acec4a2

View File

@ -139,9 +139,29 @@ def account_create(user: UserRecord) -> tuple[HTTPStatus, Union[str, None]]:
return HTTPStatus.INTERNAL_SERVER_ERROR, "Error creating account." return HTTPStatus.INTERNAL_SERVER_ERROR, "Error creating account."
allowed_frameworks: list[str] = ["paper", "spigot", "bukkit"] def account_delete(user: UserRecord) -> tuple[HTTPStatus, Union[str, None]]:
user_id = user.uid
try:
dns_record_id = firebase_manager.get_user_field(user_id, "cloudflare_entry")
if dns_record_id is None:
return HTTPStatus.IM_A_TEAPOT, "Cloudflare 'dns_record_id' not found in Firestore."
cloudflare_manager.delete_cloudflare_dns(dns_record_id)
except Exception as e:
return HTTPStatus.NOT_MODIFIED, f"Account deletion failed. {str(e)}"
try:
firebase_manager.delete_user(user_id)
except Exception as e:
return HTTPStatus.EXPECTATION_FAILED, f"Database deletion failed | {e}"
try:
file_manager.delete_non_empty_folder("users/" + user_id)
return HTTPStatus.OK, f"Successfully deleted user '{user_id}'."
except Exception as e:
file_manager.log_error(type(e).__name__, str(e))
return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error deleting user '{user_id}' on the server."
allowed_frameworks: list[str] = ["paper", "spigot", "bukkit"]
def server_create(user: UserRecord, name: str, version: str, framework: str = "paper") -> ( def server_create(user: UserRecord, name: str, version: str, framework: str = "paper") -> (
tuple)[HTTPStatus, Union[str, None]]: tuple)[HTTPStatus, Union[str, None]]:
if framework not in allowed_frameworks: if framework not in allowed_frameworks:
@ -191,27 +211,6 @@ def server_delete(name: str, user: UserRecord) -> tuple[HTTPStatus, Union[str, N
return HTTPStatus.INTERNAL_SERVER_ERROR, None return HTTPStatus.INTERNAL_SERVER_ERROR, None
def account_delete(user: UserRecord) -> tuple[HTTPStatus, Union[str, None]]:
user_id = user.uid
try:
dns_record_id = firebase_manager.get_user_field(user_id, "cloudflare_entry")
if dns_record_id is None:
return HTTPStatus.IM_A_TEAPOT, "Cloudflare 'dns_record_id' not found in Firestore."
cloudflare_manager.delete_cloudflare_dns(dns_record_id)
except Exception as e:
return HTTPStatus.NOT_MODIFIED, f"Account deletion failed. {str(e)}"
try:
firebase_manager.delete_user(user_id)
except Exception as e:
return HTTPStatus.EXPECTATION_FAILED, f"Database deletion failed | {e}"
try:
file_manager.delete_non_empty_folder("users/" + user_id)
return HTTPStatus.OK, f"Successfully deleted user '{user_id}'."
except Exception as e:
file_manager.log_error(type(e).__name__, str(e))
return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error deleting user '{user_id}' on the server."
def server_run(user: UserRecord, name: str) -> tuple[HTTPStatus, Union[str, None]]: def server_run(user: UserRecord, name: str) -> tuple[HTTPStatus, Union[str, None]]:
user_id = user.uid user_id = user.uid
mc_manager.set_cooldown(user_id=user_id) mc_manager.set_cooldown(user_id=user_id)