From ed54c5b8b9b61b1fe05aab1937f71915354135af Mon Sep 17 00:00:00 2001 From: Sergio Garcia <38561120+sergargar@users.noreply.github.com> Date: Tue, 7 Feb 2023 09:51:46 +0100 Subject: [PATCH] feat(exit_code 3): add -z option (#1848) Co-authored-by: sergargar --- prowler/__main__.py | 4 ++++ prowler/lib/cli/parser.py | 6 ++++++ tests/lib/cli/parser_test.py | 10 ++++++++++ 3 files changed, 20 insertions(+) diff --git a/prowler/__main__.py b/prowler/__main__.py index 13793aed..c470128a 100644 --- a/prowler/__main__.py +++ b/prowler/__main__.py @@ -219,6 +219,10 @@ def prowler(): audit_output_options.output_directory, ) + # If there are failed findings exit code 3, except if -z is input + if not args.ignore_exit_code_3 and stats["total_fail"] > 0: + sys.exit(3) + if __name__ == "__main__": prowler() diff --git a/prowler/lib/cli/parser.py b/prowler/lib/cli/parser.py index 899d7661..d7ed7614 100644 --- a/prowler/lib/cli/parser.py +++ b/prowler/lib/cli/parser.py @@ -138,6 +138,12 @@ Detailed documentation at https://docs.prowler.cloud action="store_true", help="Display detailed information about findings", ) + common_outputs_parser.add_argument( + "-z", + "--ignore-exit-code-3", + action="store_true", + help="Failed checks do not trigger exit code 3", + ) common_outputs_parser.add_argument( "-b", "--no-banner", action="store_true", help="Hide Prowler banner" ) diff --git a/tests/lib/cli/parser_test.py b/tests/lib/cli/parser_test.py index 55962b1a..02ce398d 100644 --- a/tests/lib/cli/parser_test.py +++ b/tests/lib/cli/parser_test.py @@ -146,6 +146,16 @@ class Test_Parser: parsed = self.parser.parse(command) assert parsed.quiet + def test_root_parser_exit_code_3_short(self): + command = [prowler_command, "-z"] + parsed = self.parser.parse(command) + assert parsed.ignore_exit_code_3 + + def test_root_parser_exit_code_3_long(self): + command = [prowler_command, "--ignore-exit-code-3"] + parsed = self.parser.parse(command) + assert parsed.ignore_exit_code_3 + def test_root_parser_default_output_modes(self): command = [prowler_command] parsed = self.parser.parse(command)