Skip to content

Commit

Permalink
solve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCloudSec committed Aug 9, 2024
1 parent 40b465e commit efaad40
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions prowler/providers/gcp/gcp_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,20 @@ def setup_session(credentials_file: str, service_account: str) -> Credentials:

@staticmethod
def test_connection(
credentials_file: str, service_account: str, raise_on_exception: bool = True
credentials_file: str = None,
service_account: str = None,
raise_on_exception: bool = True,
) -> Connection:
"""
Test the connection with the provided credentials file or service account to impersonate
Test the connection to GCP with the provided credentials file or service account to impersonate.
If the connection is successful, return a Connection object with is_connected set to True. If the connection fails, return a Connection object with error set to the exception.
Raise an exception if raise_on_exception is set to True.
If the Cloud Resource Manager API has not been used before or it is disabled, log a critical message and return a Connection object with error set to the exception.
Args:
credentials_file: str
service_account: str
Returns:
Connection object
Connection object with is_connected set to True if the connection is successful, or error set to the exception if the connection fails
"""
try:
session = GcpProvider.setup_session(credentials_file, service_account)
Expand All @@ -266,9 +271,10 @@ def test_connection(
logger.critical(

Check warning on line 271 in prowler/providers/gcp/gcp_provider.py

View check run for this annotation

Codecov / codecov/patch

prowler/providers/gcp/gcp_provider.py#L263-L271

Added lines #L263 - L271 were not covered by tests
"Cloud Resource Manager API has not been used before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/ then retry."
)
raise Exception(
"Cloud Resource Manager API has not been used before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/ then retry."
)
if raise_on_exception:
raise Exception(

Check warning on line 275 in prowler/providers/gcp/gcp_provider.py

View check run for this annotation

Codecov / codecov/patch

prowler/providers/gcp/gcp_provider.py#L274-L275

Added lines #L274 - L275 were not covered by tests
"Cloud Resource Manager API has not been used before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/ then retry."
)
else:
logger.critical(

Check warning on line 279 in prowler/providers/gcp/gcp_provider.py

View check run for this annotation

Codecov / codecov/patch

prowler/providers/gcp/gcp_provider.py#L279

Added line #L279 was not covered by tests
f"{http_error.__class__.__name__}[{http_error.__traceback__.tb_lineno}]: {http_error}"
Expand Down

0 comments on commit efaad40

Please sign in to comment.