-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat(securitycenter): Add Resource SCC Org Mgmt API SHA Custom Modules (GetEff, ListEff, ListDesc, Simulate) #13023
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
Conversation
…GetEff, ListEff, ListDesc, Simulate)
…GetEff, ListEff, ListDesc, Simulate)
|
Here is the summary of changes. You are about to add 4 region tags.
This comment is generated by snippet-bot.
|
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi team,
I'm currently reviewing this pull request and will post my detailed review in a few minutes. In the meantime, here's a quick summary to help you and other reviewers get up to speed:
This pull request adds several new Python samples for interacting with the Security Health Analytics Custom Modules API. The intent is to provide comprehensive examples for common operations, addressing issues b/347347705, b/347347992, b/347347268, and b/347348030.
Here's a breakdown of the changes:
-
New files added:
securitycenter/snippets_management_api/noxfile_config.py: This file configures the testing environment for the new samples, specifying environment variables and dependencies.securitycenter/snippets_management_api/requirements-test.txtandsecuritycenter/snippets_management_api/requirements.txt: These files list the necessary Python packages for testing and running the samples, respectively.securitycenter/snippets_management_api/security_health_analytics_custom_modules.py: This file contains the core Python code for the samples, implementing functions for:get_effective_security_health_analytics_custom_modulelist_descendant_security_health_analytics_custom_modulelist_effective_security_health_analytics_custom_modulesimulate_security_health_analytics_custom_module
securitycenter/snippets_management_api/security_health_analytics_custom_modules_test.py: This file contains unit tests to verify the functionality of the samples.
-
Key Changes: The samples cover four main functions: getting, listing descendants, listing effective modules, and simulating custom modules. The code uses the
google-cloud-securitycentermanagementlibrary. The tests are set up to use a specific organization ID (defined in environment variables), and include robust error handling and retry mechanisms usingbackoff.
I'll be checking the code for clarity, efficiency, and adherence to best practices in my full review. I'll also verify that the tests are comprehensive and cover all edge cases.
And now, a little haiku to lighten the mood:
Code flows like a stream,
Tests catch bugs before they swim,
Smooth merge, all is well.
Thanks,
Gemini
|
Gemini encountered an error creating the review. You can try again by commenting |
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi team,
I'm currently reviewing this pull request and will post my detailed review in a few minutes. In the meantime, here's a quick summary to help you and other reviewers get up to speed:
This pull request adds several new Python samples for interacting with the Security Health Analytics custom modules API. The intent is to provide comprehensive examples for common tasks, addressing several internal Google bugs (b/347347705, b/347347992, b/347347268, b/347348030).
Here's a breakdown of the changes:
-
New files added:
securitycenter/snippets_management_api/noxfile_config.py: This file configures the testing environment for the new samples, specifying required environment variables and dependencies.securitycenter/snippets_management_api/requirements-test.txtandsecuritycenter/snippets_management_api/requirements.txt: These files list the necessary Python packages for testing and running the samples, respectively. Noteworthy additions includegoogle-cloud-securitycentermanagementandpytest.securitycenter/snippets_management_api/security_health_analytics_custom_modules.py: This file contains the core sample code, implementing functions for:get_effective_security_health_analytics_custom_modulelist_descendant_security_health_analytics_custom_moduleslist_effective_security_health_analytics_custom_modulessimulate_security_health_analytics_custom_module
securitycenter/snippets_management_api/security_health_analytics_custom_modules_test.py: This file includes unit tests to verify the functionality of the samples.
-
Key changes: The samples demonstrate how to get, list, and simulate Security Health Analytics custom modules, covering various scenarios and use cases. The tests are designed to ensure the samples function correctly.
I'll provide a more detailed review shortly, focusing on code style, error handling, and test coverage. In the meantime, please take a look at this summary and let me know if you have any questions.
And now, a little haiku to lighten the mood:
Code flows like a stream,
Tests run, bugs swim far away,
Clarity's sweet reward.
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request adds Security Health Analytics custom module samples. The code is well-structured and easy to follow. The use of try-except blocks for error handling is good. A few minor improvements are suggested below.
I've referenced the following elements from the Google Python Style Guide:
- Function and method arguments should be documented using type annotations.
- Docstrings should follow the three-part "Arrange, Act, Assert" structure.
- Use descriptive names for functions and variables.
- Use commonly used acronyms, or define acronyms where appropriate.
|
|
||
| TEST_CONFIG_OVERRIDE = { | ||
| # You can opt out from the test for specific Python versions. | ||
| "ignored_versions": ["2.7", "3.7", "3.9", "3.10", "3.11"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
securitycenter/snippets_management_api/security_health_analytics_custom_modules.py
Show resolved
Hide resolved
| """ | ||
| Retrieves a Security Health Analytics custom module. | ||
| Args: | ||
| parent: Use any one of the following options: | ||
| - organizations/{organization_id}/locations/{location_id} | ||
| - folders/{folder_id}/locations/{location_id} | ||
| - projects/{project_id}/locations/{location_id} | ||
| Returns: | ||
| The retrieved Security Health Analytics custom module. | ||
| Raises: | ||
| NotFound: If the specified custom module does not exist. | ||
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| print(f"Retrieved Effective Security Health Analytics Custom Module: {response.name}") | ||
| return response | ||
| except NotFound as e: | ||
| print(f"Custom Module not found: {response.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
securitycenter/snippets_management_api/security_health_analytics_custom_modules.py
Show resolved
Hide resolved
securitycenter/snippets_management_api/security_health_analytics_custom_modules_test.py
Outdated
Show resolved
Hide resolved
securitycenter/snippets_management_api/security_health_analytics_custom_modules_test.py
Outdated
Show resolved
Hide resolved
| "title": "GCE Instance High Severity", | ||
| "description": "Custom module to detect high severity issues on GCE instances.", | ||
| }, | ||
| "recommendation": "Ensure proper security configurations on GCE instances.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recommendation should be more specific to Cloud KMS. Consider rephrasing it to something like: "Review and adjust the rotation period for Cloud KMS CryptoKeys."
| "recommendation": "Ensure proper security configurations on GCE instances.", | |
| "recommendation": "Review and adjust the rotation period for Cloud KMS CryptoKeys.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
securitycenter/snippets_management_api/security_health_analytics_custom_modules_test.py
Outdated
Show resolved
Hide resolved
securitycenter/snippets_management_api/security_health_analytics_custom_modules_test.py
Outdated
Show resolved
Hide resolved
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi team,
I'm currently reviewing this pull request and will post my detailed review in a few minutes. In the meantime, here's a quick summary to help you and other reviewers get up to speed:
This pull request, authored by vijaykanthm, adds several new Python samples for interacting with the Security Health Analytics Custom Modules API. The intent is to provide comprehensive examples for common operations, addressing several internal Google bugs (b/347347705, b/347347992, b/347347268, b/347348030).
Here's a breakdown of the changes:
- New files added:
securitycenter/snippets_management_api/noxfile_config.py: Configuration file for testing.securitycenter/snippets_management_api/requirements-test.txt: Test dependencies.securitycenter/snippets_management_api/requirements.txt: Project dependencies.securitycenter/snippets_management_api/security_health_analytics_custom_modules.py: Contains the core functions for interacting with the API (GetEffective, ListEffective, ListDescendant, Simulate).securitycenter/snippets_management_api/security_health_analytics_custom_modules_test.py: Unit tests for the functions.
- Key functionality: The new samples demonstrate how to:
- Retrieve a single Security Health Analytics custom module using
get_effective_security_health_analytics_custom_module. - List all descendant custom modules using
list_descendant_security_health_analytics_custom_module. - List all effective custom modules (resident and inherited) using
list_effective_security_health_analytics_custom_module. - Simulate the results of running a custom module against a resource using
simulate_security_health_analytics_custom_module.
- Retrieve a single Security Health Analytics custom module using
The changes include adding new functions, comprehensive docstrings, and unit tests to ensure code quality and functionality. The noxfile_config.py file includes specific environment variable configurations for the tests. The requirements.txt and requirements-test.txt files list the necessary dependencies.
I'll be checking for correctness, readability, and test coverage in my full review.
And now, a little haiku to brighten your day:
Code flows like a stream,
Tests ensure the path is clear,
A bug-free release.
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request adds Security Health Analytics custom module samples. The code is well-structured and easy to follow. The use of try-except blocks for error handling is good. A few minor improvements are suggested below.
I've referenced the following elements from the Google Python Style Guide:
- Function docstrings should follow the Google Python Style Guide format.
- Module level docstrings should be placed at the top of the file.
- Use descriptive variable and function names.
- Use commonly used variable names where appropriate (e.g. client for client objects).
|
|
||
| # Default TEST_CONFIG_OVERRIDE for python repos. | ||
|
|
||
| # You can copy this file into your directory, then it will be inported from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "inported" should be "imported".
| # You can copy this file into your directory, then it will be inported from | |
| # You can copy this file into your directory, then it will be imported from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| # [START securitycenter_get_effective_security_health_analytics_custom_module] | ||
|
|
||
|
|
||
| def get_effective_security_health_analytics_custom_module(parent: str, module_id: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring could be improved by following the Google Python Style Guide format. It should include an Args section and a Returns section. Consider adding a Raises section as well.
| def get_effective_security_health_analytics_custom_module(parent: str, module_id: str): | |
| def get_effective_security_health_analytics_custom_module(parent: str, module_id: str): | |
| """ | |
| Retrieves a Security Health Analytics custom module. | |
| Args: | |
| parent (str): Resource name of the parent to retrieve the effective custom module from. | |
| module_id (str): The unique identifier of the custom module. | |
| Returns: | |
| EffectiveSecurityHealthAnalyticsCustomModule: The retrieved effective custom module. | |
| Raises: | |
| google.api_core.exceptions.NotFound: If the custom module is not found. | |
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| Raises: | ||
| NotFound: If the specified custom module does not exist. | ||
| """ | ||
| client = securitycentermanagement_v1.SecurityCenterManagementClient() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the Google style guide, prefer using client as the variable name for client objects, where appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already doing it.
| print(f"Retrieved Effective Security Health Analytics Custom Module: {response.name}") | ||
| return response | ||
| except NotFound as e: | ||
| print(f"Custom Module not found: {response.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| # [START securitycenter_list_descendant_security_health_analytics_custom_module] | ||
|
|
||
|
|
||
| def list_descendant_security_health_analytics_custom_module(parent: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring could be improved by following the Google Python Style Guide format. It should include an Args section and a Returns section. Consider adding a Raises section as well.
| def list_descendant_security_health_analytics_custom_module(parent: str): | |
| def list_descendant_security_health_analytics_custom_module(parent: str): | |
| """ | |
| Retrieves a list of all descendant Security Health Analytics custom modules. | |
| Args: | |
| parent (str): Resource name of the parent to retrieve the descendant custom modules from. | |
| Returns: | |
| List[SecurityHealthAnalyticsCustomModule]: A list of descendant custom modules. | |
| Raises: | |
| google.api_core.exceptions.NotFound: If the parent resource is not found. | |
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| raise | ||
|
|
||
|
|
||
| def add_custom_module(org_id: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is missing a docstring explaining its purpose and parameters.
| def add_custom_module(org_id: str): | |
| def add_custom_module(org_id: str): | |
| """ | |
| Adds a new SHA custom module. | |
| Args: | |
| org_id (str): The organization ID. | |
| Returns: | |
| Tuple[str, str]: The name and ID of the created custom module. | |
| """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| @backoff.on_exception( | ||
| backoff.expo, (InternalServerError, ServiceUnavailable, NotFound), max_tries=3 | ||
| ) | ||
| def test_get_effective_security_health_analytics_custom_module(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| @backoff.on_exception( | ||
| backoff.expo, (InternalServerError, ServiceUnavailable, NotFound), max_tries=3 | ||
| ) | ||
| def test_list_descendant_security_health_analytics_custom_module(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| @backoff.on_exception( | ||
| backoff.expo, (InternalServerError, ServiceUnavailable, NotFound), max_tries=3 | ||
| ) | ||
| def test_list_effective_security_health_analytics_custom_module(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| @backoff.on_exception( | ||
| backoff.expo, (InternalServerError, ServiceUnavailable, NotFound), max_tries=3 | ||
| ) | ||
| def test_simulate_security_health_analytics_custom_module(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi team,
I'm currently reviewing this pull request and will post my detailed review in a few minutes. In the meantime, here's a quick summary to help you and other reviewers get up to speed:
This pull request adds several new Python samples for interacting with the Security Health Analytics Custom Modules API. The goal is to provide comprehensive examples for common operations, addressing issues b/347347705, b/347347992, b/347347268, and b/347348030.
Here's a breakdown of the changes:
-
New files:
securitycenter/snippets_management_api/noxfile_config.py: Added configuration for testing the samples. Lines 1-41 define the test configuration override, specifying ignored Python versions, environment variables, and project details.securitycenter/snippets_management_api/requirements-test.txtandsecuritycenter/snippets_management_api/requirements.txt: Added necessary dependencies for testing and running the samples. Lines 1-4 inrequirements-test.txtand lines 1-4 inrequirements.txtspecify the packages.securitycenter/snippets_management_api/security_health_analytics_custom_modules.py: Contains the core sample code. Lines 1-200 implement functions forget_effective,list_descendant,list_effective, andsimulateoperations on Security Health Analytics custom modules.securitycenter/snippets_management_api/security_health_analytics_custom_modules_test.py: Added comprehensive unit tests for the new samples. Lines 1-206 implement the test functions, including setup and cleanup, and usingbackofffor retry logic.
-
Key improvements: The samples cover a range of functionalities, including retrieving, listing, and simulating custom modules. They are well-documented and include comprehensive error handling.
Let me know if you have any questions.
And now, a little haiku to lighten the mood:
Code flows like a stream,
Tests run, bugs flee in the night,
Clean code, joy is found.
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request adds Security Health Analytics custom module samples. Overall, the code is well-structured and easy to understand. The addition of type hints and docstrings improves readability and maintainability. The inclusion of tests is also a good practice. Here are a few suggestions based on PEP 8 and Google Python Style Guide that could further enhance the code:
- In
noxfile_config.py, theGCLOUD_ORGANIZATIONshould not be hardcoded. It's better to retrieve it from the environment or use a placeholder value for testing. - The
try...exceptblocks in thelist_descendant_security_health_analytics_custom_moduleandlist_effective_security_health_analytics_custom_modulefunctions are too broad. It's better to catch specific exceptions and handle them accordingly. - The
resource_typein thesimulate_security_health_analytics_custom_modulefunction should be parameterized or retrieved from the custom module configuration. - The checklist in the pull request description is not fully completed. Please review and complete the checklist before merging.
- It is good practice to delete any resources created during testing in the teardown method of the test file. This can be done by calling the appropriate delete methods for each resource in the
cleanup_existing_custom_modulesfunction. This ensures that resources are not left behind after the tests are completed and helps to avoid unexpected charges.
|
|
||
| # Default TEST_CONFIG_OVERRIDE for python repos. | ||
|
|
||
| # You can copy this file into your directory, then it will be inported from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "inported" should be "imported".
| # You can copy this file into your directory, then it will be inported from | |
| # the noxfile.py. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| # A dictionary you want to inject into your test. Don't put any | ||
| # secrets here. These values will override predefined values. | ||
| "envs": { | ||
| "GCLOUD_ORGANIZATION": "1081635000895", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the Google Python Style Guide, it's recommended to not hardcode sensitive information like organization IDs directly in the code. Consider retrieving this value from the environment or using a placeholder for testing purposes. Refer to Secrets in AUTHORING_GUIDE.md for more details on how to handle secrets.
| "GCLOUD_ORGANIZATION": "1081635000895", | |
| "GCLOUD_ORGANIZATION": os.environ.get("GCLOUD_ORGANIZATION", "YOUR_ORGANIZATION_ID"), | |
| print(f"Retrieved Effective Security Health Analytics Custom Module: {response.name}") | ||
| return response | ||
| except NotFound as e: | ||
| print(f"Custom Module not found: {response.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable response might not be defined within this except block if the NotFound exception is raised before the API call. Consider using a more specific try...except block around the API call itself, or handling the exception differently. According to PEP 8, it's a good practice to handle exceptions as close to the source of the error as possible.
| print(f"Custom Module not found: {response.name}") | |
| print(f"Custom Module not found: {e.message}") | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed.
| except Exception as e: | ||
| print(f"An error occurred while listing custom modules: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching a generic Exception can mask unexpected errors. PEP 8 recommends catching specific exceptions whenever possible. Could you specify the type of exceptions you expect in this block, or provide more context? This will make debugging easier and improve the overall robustness of the code.
| except Exception as e: | |
| print(f"An error occurred while listing custom modules: {e}") | |
| print(f"An error occurred while listing custom modules: {e}") | |
| raise # Re-raise the exception after printing the message | |
| except Exception as e: | ||
| print(f"An error occurred while listing custom modules: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching a generic Exception can mask unexpected errors. PEP 8 recommends catching specific exceptions whenever possible. Could you specify the type of exceptions you expect in this block, or provide more context? This practice enhances code clarity and aids in debugging.
| except Exception as e: | |
| print(f"An error occurred while listing custom modules: {e}") | |
| print(f"An error occurred while listing custom modules: {e}") | |
| raise # Re-raise the exception after printing the message | |
|
|
||
| # Initialize request argument(s) | ||
| resource = securitycentermanagement_v1.types.SimulateSecurityHealthAnalyticsCustomModuleRequest.SimulatedResource() | ||
| resource.resource_type = "cloudkms.googleapis.com/CryptoKey" # Replace with the correct resource type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resource type is hardcoded here. Consider making this a parameter to the function or retrieving it from the custom_config. This would make the function more flexible and reusable. For example, you could add a resource_type field to the custom_config dictionary and retrieve it within the function.
| resource.resource_type = "cloudkms.googleapis.com/CryptoKey" # Replace with the correct resource type | |
| resource.resource_type = custom_config.get("resource_selector", {}).get("resource_types", ["YOUR_RESOURCE_TYPE"])[0] | |
| pytest.fail("GCLOUD_ORGANIZATION environment variable is not set.") | ||
|
|
||
| print(f"Cleaning up existing custom modules for organization: {ORGANIZATION_ID}") | ||
| cleanup_existing_custom_modules(ORGANIZATION_ID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good practice to clean up any resources created during testing. Consider adding a finalizer or using try...finally to ensure cleanup happens even if tests fail. This can prevent orphaned resources and reduce costs. You can delete the created custom module in the cleanup_existing_custom_modules function.
| cleanup_existing_custom_modules(ORGANIZATION_ID) | |
| cleanup_existing_custom_modules(ORGANIZATION_ID) | |
ghost
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi team,
I'm currently reviewing this pull request and will post my detailed review in a few minutes. In the meantime, here's a quick summary to help you and other reviewers get up to speed:
This pull request adds Security Health Analytics custom module samples for the Security Command Center (SCC) Management API. The intent is to provide code examples for four key operations:
GetEffective: Retrieve a specific Security Health Analytics custom module.ListEffective: List all Security Health Analytics custom modules (resident and inherited).ListDescendant: List all resident custom modules and their descendants.Simulate: Simulate the result of running a custom module against a resource.
The changes include:
- Addition of a new
securitycenter/snippets_management_apidirectory containing the sample code. - Updates to
noxfile_config.pyto configure the testing environment (lines 1-41). - Addition of necessary library dependencies in
requirements.txtandrequirements-test.txt(lines 1-4 and 1-4 respectively). - Creation of
security_health_analytics_custom_modules.pywith the core functions (lines 1-200). - Implementation of comprehensive unit tests in
security_health_analytics_custom_modules_test.pyto ensure functionality (lines 1-206).
The PR addresses several internal Google bugs (b/347347705, b/347347992, b/347347268, b/347348030).
I'll provide a more detailed review shortly, but this should give you a good overview in the meantime.
And now, a little haiku to brighten your day:
Code flows like a stream,
Tests run, bugs flee in the night,
Clean code, joy is found.
Best,
Gemini
|
Gemini encountered an error creating the review. You can try again by commenting |
|
Since #13004 has been merged, this PR will need to be rebased from main, and adjusted to only include the changes required to add these new regions (since a lot of the scaffolding was added in 13004) |
…stEff-listDesc-Simu Merge remote to local
Description
Fixes b/347347705, b/347347992, b/347347268, b/347348030
This PR adds SCC Managament API Org SHA Custom Module Samples for GetEffective, ListEffective, ListDescendant & Simulate.
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
nox -s py-3.9(see Test Environment Setup)nox -s lint(see Test Environment Setup)