Skip to content

Commit fedcc26

Browse files
committed
Address comments by code review bot
1 parent 5b8d9a6 commit fedcc26

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

securitycenter/snippets_management_api/noxfile_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Default TEST_CONFIG_OVERRIDE for python repos.
1616

17-
# You can copy this file into your directory, then it will be inported from
17+
# You can copy this file into your directory, then it will be imported from
1818
# the noxfile.py.
1919

2020
# The source of truth:

securitycenter/snippets_management_api/security_health_analytics_custom_modules.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222

2323
def get_effective_security_health_analytics_custom_module(parent: str, module_id: str):
2424
"""
25-
Retrieves a Security Health Analytics custom module.
25+
Retrieves a Security Health Analytics custom module using parent and module id as parameters.
2626
Args:
2727
parent: Use any one of the following options:
2828
- organizations/{organization_id}/locations/{location_id}
2929
- folders/{folder_id}/locations/{location_id}
3030
- projects/{project_id}/locations/{location_id}
31+
module_id: The unique identifier of the custom module.
3132
Returns:
3233
The retrieved Security Health Analytics custom module.
3334
Raises:
@@ -44,7 +45,7 @@ def get_effective_security_health_analytics_custom_module(parent: str, module_id
4445
print(f"Retrieved Effective Security Health Analytics Custom Module: {response.name}")
4546
return response
4647
except NotFound as e:
47-
print(f"Custom Module not found: {response.name}")
48+
print(f"Custom Module not found: {e}")
4849
raise e
4950
# [END securitycenter_get_effective_security_health_analytics_custom_module]
5051

@@ -60,9 +61,9 @@ def list_descendant_security_health_analytics_custom_module(parent: str):
6061
- folders/{folder_id}/locations/{location_id}
6162
- projects/{project_id}/locations/{location_id}
6263
Returns:
63-
List of retrieved all resident Security Health Analytics custom modules and all of its descendants.
64+
A list of all resident Security Health Analytics custom modules and all of its descendants.
6465
Raises:
65-
NotFound: If the specified custom module does not exist.
66+
NotFound: If the parent resource is not found.
6667
"""
6768

6869
client = securitycentermanagement_v1.SecurityCenterManagementClient()
@@ -104,7 +105,7 @@ def list_effective_security_health_analytics_custom_module(parent: str):
104105
Returns:
105106
List of retrieved all Security Health Analytics custom modules.
106107
Raises:
107-
NotFound: If the specified custom module does not exist.
108+
NotFound: If the parent resource is not found.
108109
"""
109110

110111
client = securitycentermanagement_v1.SecurityCenterManagementClient()
@@ -142,7 +143,7 @@ def simulate_security_health_analytics_custom_module(parent: str):
142143
- folders/{folder_id}/locations/{location_id}
143144
- projects/{project_id}/locations/{location_id}
144145
Returns:
145-
Simulated Security Health Analytics custom module.
146+
The simulation response of Security Health Analytics custom module.
146147
"""
147148

148149
client = securitycentermanagement_v1.SecurityCenterManagementClient()

securitycenter/snippets_management_api/security_health_analytics_custom_modules_test.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@
3838

3939
@pytest.fixture(scope="session", autouse=True)
4040
def setup_environment():
41-
"""Fixture to ensure a clean environment by removing test modules before running tests."""
41+
"""
42+
Fixture to ensure a clean environment by removing test modules before running tests.
43+
44+
This fixture lists all SHA custom modules in the organization and deletes any
45+
that were created by previous test runs, identified by the PREFIX.
46+
"""
4247
if not ORGANIZATION_ID:
4348
pytest.fail("GCLOUD_ORGANIZATION environment variable is not set.")
4449

@@ -73,7 +78,13 @@ def cleanup_existing_custom_modules(org_id: str):
7378

7479

7580
def add_custom_module(org_id: str):
76-
81+
"""
82+
Adds a new SHA custom module.
83+
Args:
84+
org_id (str): The organization ID.
85+
Returns:
86+
Tuple[str, str]: The name and ID of the created custom module.
87+
"""
7788
parent = f"organizations/{org_id}/locations/global"
7889
client = securitycentermanagement_v1.SecurityCenterManagementClient()
7990

@@ -86,24 +97,24 @@ def add_custom_module(org_id: str):
8697
"display_name": display_name,
8798
"enablement_state": "ENABLED",
8899
"custom_config": {
89-
"description": "Sample custom module for testing purpose. Please do not delete.",
100+
"description": "Sample custom module for testing purposes. Please do not delete.",
90101
"predicate": {
91102
"expression": "has(resource.rotationPeriod) && (resource.rotationPeriod > duration('2592000s'))",
92-
"title": "GCE Instance High Severity",
93-
"description": "Custom module to detect high severity issues on GCE instances.",
103+
"title": "Cloud KMS CryptoKey Rotation Period",
104+
"description": "Custom module to detect CryptoKeys with rotation period greater than 30 days.",
94105
},
95-
"recommendation": "Ensure proper security configurations on GCE instances.",
106+
"recommendation": "Review and adjust the rotation period for Cloud KMS CryptoKeys.",
96107
"resource_selector": {"resource_types": ["cloudkms.googleapis.com/CryptoKey"]},
97108
"severity": "CRITICAL",
98109
"custom_output": {
99110
"properties": [
100111
{
101112
"name": "example_property",
102113
"value_expression": {
103-
"description": "The name of the instance",
114+
"description": "The resource name of the CryptoKey",
104115
"expression": "resource.name",
105116
"location": "global",
106-
"title": "Instance Name",
117+
"title": "CryptoKey Resource Name",
107118
},
108119
}
109120
]
@@ -126,7 +137,7 @@ def add_custom_module(org_id: str):
126137
backoff.expo, (InternalServerError, ServiceUnavailable, NotFound), max_tries=3
127138
)
128139
def test_get_effective_security_health_analytics_custom_module():
129-
140+
"""Tests getting an effective SHA custom module."""
130141
module_name, module_id = add_custom_module(ORGANIZATION_ID)
131142
parent = f"organizations/{ORGANIZATION_ID}/locations/{LOCATION}"
132143

@@ -144,7 +155,7 @@ def test_get_effective_security_health_analytics_custom_module():
144155
backoff.expo, (InternalServerError, ServiceUnavailable, NotFound), max_tries=3
145156
)
146157
def test_list_descendant_security_health_analytics_custom_module():
147-
158+
"""Tests listing descendant SHA custom modules."""
148159
module_name, module_id = add_custom_module(ORGANIZATION_ID)
149160
parent = f"organizations/{ORGANIZATION_ID}/locations/{LOCATION}"
150161
# Retrieve the list descendant custom modules
@@ -169,7 +180,7 @@ def test_list_descendant_security_health_analytics_custom_module():
169180
backoff.expo, (InternalServerError, ServiceUnavailable, NotFound), max_tries=3
170181
)
171182
def test_list_effective_security_health_analytics_custom_module():
172-
183+
"""Tests listing effective SHA custom modules."""
173184
module_name, module_id = add_custom_module(ORGANIZATION_ID)
174185
parent = f"organizations/{ORGANIZATION_ID}/locations/{LOCATION}"
175186
# Retrieve the list of custom modules
@@ -194,7 +205,7 @@ def test_list_effective_security_health_analytics_custom_module():
194205
backoff.expo, (InternalServerError, ServiceUnavailable, NotFound), max_tries=3
195206
)
196207
def test_simulate_security_health_analytics_custom_module():
197-
208+
"""Tests simulating an SHA custom module."""
198209
module_name, module_id = add_custom_module(ORGANIZATION_ID)
199210
parent = f"organizations/{ORGANIZATION_ID}/locations/{LOCATION}"
200211

0 commit comments

Comments
 (0)