Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gcp): add a test_connection method #4616

Merged
merged 8 commits into from
Aug 19, 2024

Conversation

MrCloudSec
Copy link
Member

@MrCloudSec MrCloudSec commented Aug 2, 2024

Context

We need to be able to test the connection to each provider using one of the available authentication methods, starting from the environment variables.

Description

Add a test_connection method for the GCP provider.
Create a test_connection abstract method in the Provider class but not enforced for now not to break anything.

Checklist

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@MrCloudSec MrCloudSec requested review from a team as code owners August 2, 2024 17:33
@github-actions github-actions bot added the provider/gcp Issues/PRs related with the Google Cloud Platform provider label Aug 2, 2024
@MrCloudSec MrCloudSec changed the title feat(gcp): add a test_connection method feat(gcp): add a test_connection method Aug 2, 2024
Copy link

codecov bot commented Aug 2, 2024

Codecov Report

Attention: Patch coverage is 28.57143% with 20 lines in your changes missing coverage. Please review.

Project coverage is 89.02%. Comparing base (761eeba) to head (efaad40).
Report is 598 commits behind head on master.

Files with missing lines Patch % Lines
prowler/providers/gcp/gcp_provider.py 28.57% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4616      +/-   ##
==========================================
- Coverage   89.12%   89.02%   -0.11%     
==========================================
  Files         913      913              
  Lines       27866    27890      +24     
==========================================
- Hits        24836    24828       -8     
- Misses       3030     3062      +32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = client_secrets_path
@staticmethod
def test_connection(
credentials_file: str, service_account: str, raise_on_exception: bool = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it mandatory to set the credentials_file or service_account? If not please set some default values.

credentials_file: str, service_account: str, raise_on_exception: bool = True
) -> Connection:
"""
Test the connection with the provided credentials file or service account to impersonate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve the docstring with the possible exceptions raised, what the method do and more about the args and returns please.

logger.critical(
"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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to add if raise_on_exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for the test_connection method.

@pedrooot pedrooot self-requested a review August 19, 2024 10:37
Copy link
Member

@pedrooot pedrooot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔝 Thanks for this amazing feature!!

@MrCloudSec MrCloudSec merged commit 84a76f4 into master Aug 19, 2024
9 of 11 checks passed
@MrCloudSec MrCloudSec deleted the PRWLR-4320-gcp-test-connection branch August 19, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
provider/gcp Issues/PRs related with the Google Cloud Platform provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants