From 823f062fb9738398faec7b611d282485c8f5a426 Mon Sep 17 00:00:00 2001 From: DaveYesland Date: Tue, 4 Jun 2024 12:40:09 -0700 Subject: [PATCH 1/3] Adds a debug command to view error log --- pacu/main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pacu/main.py b/pacu/main.py index 0c038834..07867b39 100644 --- a/pacu/main.py +++ b/pacu/main.py @@ -143,6 +143,7 @@ def display_pacu_help(): to solve this problem console/open_console Generate a URL that will log the current user/role in to the AWS web console + debug Display the contents of the error log file """) @@ -179,7 +180,7 @@ class Main: 'assume_role', 'aws', 'console', 'data', 'delete_session', 'exec', 'exit', 'export_keys', 'help', 'import_keys', 'list', 'list_sessions', 'load_commands_file', 'ls', 'open_console', 'quit', 'regions', 'run', 'search', 'services', 'sessions', 'set_keys', 'set_regions', 'set_ua_suffix', 'swap_keys', - 'swap_session', 'unset_ua_suffix', 'update_regions', 'use', 'whoami' + 'swap_session', 'unset_ua_suffix', 'update_regions', 'use', 'whoami', 'debug' ] def __init__(self): @@ -211,7 +212,7 @@ def log_error(self, text, exception_info=None, session=None, local_data=None, gl log_file_path = '{}/global_error_log.txt'.format(session_dir()) print('\n[{}] Pacu encountered an error while running the previous command. Check {} for technical ' - 'details. [LOG LEVEL: {}]\n\n {}\n'.format(timestamp, log_file_path, + 'details, or use the debug command. [LOG LEVEL: {}]\n\n {}\n'.format(timestamp, log_file_path, settings.ERROR_LOG_VERBOSITY.upper(), exception_info)) log_file_directory = os.path.dirname(log_file_path) @@ -255,6 +256,14 @@ def log_error(self, text, exception_info=None, session=None, local_data=None, gl print('Error while saving exception information. This means the exception was not added to any error log ' 'and should most likely be provided to the developers.\n Exception raised: {}'.format(str(error))) raise + + def read_log_file(self): + log_file_path = '{}/error_log.txt'.format(session_dir()) + if os.path.exists(log_file_path): + with open(log_file_path, 'r') as log_file: + print(log_file.read()) + else: + print('No error log file found.') # @message: String - message to print and/or write to file # @output: String - where to output the message: both, file, or screen @@ -619,6 +628,8 @@ def parse_command(self, command): self.unset_user_agent_suffix() elif command[0] == 'whoami': self.print_key_info() + elif command[0] == 'debug': + self.read_log_file() elif command[0] == 'exit' or command[0] == 'quit': self.exit() else: From ed07914a246876e8c177032655de2da75c84a608 Mon Sep 17 00:00:00 2001 From: Dave Yesland <41924355+DaveYesland@users.noreply.github.com> Date: Wed, 5 Jun 2024 12:38:11 -0700 Subject: [PATCH 2/3] fix linting --- pacu/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pacu/main.py b/pacu/main.py index 07867b39..4b07c476 100644 --- a/pacu/main.py +++ b/pacu/main.py @@ -212,8 +212,8 @@ def log_error(self, text, exception_info=None, session=None, local_data=None, gl log_file_path = '{}/global_error_log.txt'.format(session_dir()) print('\n[{}] Pacu encountered an error while running the previous command. Check {} for technical ' - 'details, or use the debug command. [LOG LEVEL: {}]\n\n {}\n'.format(timestamp, log_file_path, - settings.ERROR_LOG_VERBOSITY.upper(), exception_info)) + 'details, or use the debug command. [LOG LEVEL: {}]\n\n {}\n'.format(timestamp, log_file_path, + settings.ERROR_LOG_VERBOSITY.upper(), exception_info)) log_file_directory = os.path.dirname(log_file_path) if log_file_directory and not os.path.exists(log_file_directory): @@ -256,7 +256,7 @@ def log_error(self, text, exception_info=None, session=None, local_data=None, gl print('Error while saving exception information. This means the exception was not added to any error log ' 'and should most likely be provided to the developers.\n Exception raised: {}'.format(str(error))) raise - + def read_log_file(self): log_file_path = '{}/error_log.txt'.format(session_dir()) if os.path.exists(log_file_path): From 039a90f1d5bcab19250b75d59d1a2408c86ef7e3 Mon Sep 17 00:00:00 2001 From: Dave Yesland <41924355+DaveYesland@users.noreply.github.com> Date: Wed, 5 Jun 2024 12:42:46 -0700 Subject: [PATCH 3/3] please fix linting --- pacu/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pacu/main.py b/pacu/main.py index e5ac1f66..e79c4be6 100644 --- a/pacu/main.py +++ b/pacu/main.py @@ -185,8 +185,8 @@ def get_data_from_traceback(tb) -> Tuple[Optional[PacuSession], List[str], List[ class Main: COMMANDS = [ 'assume_role', 'aws', 'console', 'data', 'delete_session', 'exec', 'exit', 'export_keys', 'help', - 'history', 'import_keys', 'list', 'list_sessions', 'load_commands_file', 'ls', 'open_console', 'quit', - 'regions', 'run', 'search', 'services', 'sessions', 'set_keys', 'set_regions', 'set_ua_suffix', + 'history', 'import_keys', 'list', 'list_sessions', 'load_commands_file', 'ls', 'open_console', 'quit', + 'regions', 'run', 'search', 'services', 'sessions', 'set_keys', 'set_regions', 'set_ua_suffix', 'swap_keys', 'swap_session', 'unset_ua_suffix', 'update_regions', 'use', 'whoami', 'debug' ] @@ -219,7 +219,7 @@ def log_error(self, text, exception_info=None, session=None, local_data=None, gl log_file_path = '{}/global_error_log.txt'.format(session_dir()) print('\n[{}] Pacu encountered an error while running the previous command. Check {} for technical ' - 'details, or use the debug command. [LOG LEVEL: {}]\n\n {}\n'.format(timestamp, log_file_path, + 'details, or use the debug command. [LOG LEVEL: {}]\n\n {}\n'.format(timestamp, log_file_path, settings.ERROR_LOG_VERBOSITY.upper(), exception_info)) log_file_directory = os.path.dirname(log_file_path)