From 8266fd0c6facff8a775aa15b8ba7f6ded4f0cf6b Mon Sep 17 00:00:00 2001 From: Sergio Garcia <38561120+sergargar@users.noreply.github.com> Date: Thu, 10 Aug 2023 12:08:07 +0200 Subject: [PATCH] chore(print): prettify prints of listings and logs (#2699) --- README.md | 2 +- prowler/lib/check/check.py | 25 +++++++++++++------------ prowler/lib/logger.py | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index deda8a97..f7ee6316 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ It contains hundreds of controls covering CIS, NIST 800, NIST CSF, CISA, RBI, Fe | Provider | Checks | Services | [Compliance Frameworks](https://docs.prowler.cloud/en/latest/tutorials/compliance/) | [Categories](https://docs.prowler.cloud/en/latest/tutorials/misc/#categories) | |---|---|---|---|---| -| AWS | 285 | 55 -> `prowler aws --list-services` | 25 -> `prowler aws --list-compliance` | 5 -> `prowler aws --list-categories` | +| AWS | 287 | 56 -> `prowler aws --list-services` | 25 -> `prowler aws --list-compliance` | 5 -> `prowler aws --list-categories` | | GCP | 73 | 11 -> `prowler gcp --list-services` | 1 -> `prowler gcp --list-compliance` | 2 -> `prowler gcp --list-categories`| | Azure | 23 | 4 -> `prowler azure --list-services` | CIS soon | 1 -> `prowler azure --list-categories` | | Kubernetes | Planned | - | - | - | diff --git a/prowler/lib/check/check.py b/prowler/lib/check/check.py index 4ce0d35c..27e685c9 100644 --- a/prowler/lib/check/check.py +++ b/prowler/lib/check/check.py @@ -207,42 +207,43 @@ def list_categories(bulk_checks_metadata: dict) -> set(): def print_categories(categories: set): categories_num = len(categories) - plural_string = f"There are {Fore.YELLOW}{categories_num}{Style.RESET_ALL} available categories: \n" - singular_string = f"There is {Fore.YELLOW}{categories_num}{Style.RESET_ALL} available category: \n" + plural_string = f"\nThere are {Fore.YELLOW}{categories_num}{Style.RESET_ALL} available categories.\n" + singular_string = f"\nThere is {Fore.YELLOW}{categories_num}{Style.RESET_ALL} available category.\n" message = plural_string if categories_num > 1 else singular_string - print(message) for category in categories: print(f"- {category}") + print(message) + def print_services(service_list: set): services_num = len(service_list) - plural_string = ( - f"There are {Fore.YELLOW}{services_num}{Style.RESET_ALL} available services: \n" - ) + plural_string = f"\nThere are {Fore.YELLOW}{services_num}{Style.RESET_ALL} available services.\n" singular_string = ( - f"There is {Fore.YELLOW}{services_num}{Style.RESET_ALL} available service: \n" + f"\nThere is {Fore.YELLOW}{services_num}{Style.RESET_ALL} available service.\n" ) message = plural_string if services_num > 1 else singular_string - print(message) for service in service_list: print(f"- {service}") + print(message) + def print_compliance_frameworks( bulk_compliance_frameworks: dict, ): frameworks_num = len(bulk_compliance_frameworks.keys()) - plural_string = f"There are {Fore.YELLOW}{frameworks_num}{Style.RESET_ALL} available Compliance Frameworks: \n" - singular_string = f"There is {Fore.YELLOW}{frameworks_num}{Style.RESET_ALL} available Compliance Framework: \n" + plural_string = f"\nThere are {Fore.YELLOW}{frameworks_num}{Style.RESET_ALL} available Compliance Frameworks.\n" + singular_string = f"\nThere is {Fore.YELLOW}{frameworks_num}{Style.RESET_ALL} available Compliance Framework.\n" message = plural_string if frameworks_num > 1 else singular_string - print(message) for framework in bulk_compliance_frameworks.keys(): - print(f"\t- {Fore.YELLOW}{framework}{Style.RESET_ALL}") + print(f"- {framework}") + + print(message) def print_compliance_requirements( diff --git a/prowler/lib/logger.py b/prowler/lib/logger.py index b0f0935a..6d00ac8d 100644 --- a/prowler/lib/logger.py +++ b/prowler/lib/logger.py @@ -14,7 +14,7 @@ logging_levels = { def set_logging_config(log_level: str, log_file: str = None, only_logs: bool = False): # Logs formatter stream_formatter = logging.Formatter( - "%(asctime)s [File: %(filename)s:%(lineno)d] \t[Module: %(module)s]\t %(levelname)s: %(message)s" + "\n%(asctime)s [File: %(filename)s:%(lineno)d] \t[Module: %(module)s]\t %(levelname)s: %(message)s" ) log_file_formatter = logging.Formatter( '{"timestamp": "%(asctime)s", "filename": "%(filename)s:%(lineno)d", "level": "%(levelname)s", "module": "%(module)s", "message": "%(message)s"}'