From 63c1d1b5d8520e31ef71a59e746397d613a53a5c Mon Sep 17 00:00:00 2001 From: Sergio Garcia <38561120+sergargar@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:15:16 +0100 Subject: [PATCH] fix(gcp): remove Default Project ID requirement (#3459) --- prowler/providers/common/audit_info.py | 10 +--------- prowler/providers/gcp/gcp_provider.py | 7 ++++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/prowler/providers/common/audit_info.py b/prowler/providers/common/audit_info.py index 8f7a45fc..1db1b4e6 100644 --- a/prowler/providers/common/audit_info.py +++ b/prowler/providers/common/audit_info.py @@ -44,15 +44,7 @@ class Audit_Info: def print_gcp_credentials(self, audit_info: GCP_Audit_Info): # Beautify audited profile, set "default" if there is no profile set - try: - getattr(audit_info.credentials, "_service_account_email") - profile = ( - audit_info.credentials._service_account_email - if audit_info.credentials._service_account_email is not None - else "default" - ) - except AttributeError: - profile = "default" + profile = getattr(audit_info.credentials, "_service_account_email", "default") report = f""" This report is being generated using credentials below: diff --git a/prowler/providers/gcp/gcp_provider.py b/prowler/providers/gcp/gcp_provider.py index 9c181d62..c75c599b 100644 --- a/prowler/providers/gcp/gcp_provider.py +++ b/prowler/providers/gcp/gcp_provider.py @@ -18,9 +18,6 @@ class GCP_Provider: self.credentials, self.default_project_id = self.__set_credentials__( credentials_file ) - if not self.default_project_id: - logger.critical("No Project ID associated to Google Credentials.") - sys.exit(1) self.project_ids = [] accessible_projects = self.get_project_ids() @@ -41,6 +38,10 @@ class GCP_Provider: # If not projects were input, all accessible projects are scanned by default self.project_ids = accessible_projects + # Set Default Project ID if not set in credentials + if not self.default_project_id: + self.default_project_id = self.project_ids[0] + def __set_credentials__(self, credentials_file): try: if credentials_file: