Skip to content

Commit 300b40b

Browse files
committed
Address comments by code review bot
1 parent 74a15b9 commit 300b40b

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

securitycenter/snippets_management_api/event_threat_detection_custom_modules.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,27 @@
1616

1717
import random
1818
import time
19-
from typing import Dict
2019

21-
from google.api_core.exceptions import NotFound
20+
from google.api_core.exceptions import GoogleAPICallError, NotFound
2221
from google.cloud import securitycentermanagement_v1
2322
from google.protobuf.field_mask_pb2 import FieldMask
2423
from google.protobuf.struct_pb2 import Struct
2524

2625

2726
# [START securitycenter_create_event_threat_detection_custom_module]
28-
def create_event_threat_detection_custom_module(parent: str) -> Dict:
27+
def create_event_threat_detection_custom_module(parent: str) -> securitycentermanagement_v1.EventThreatDetectionCustomModule:
2928
"""
3029
Creates a Event Threat Detection Custom Module.
3130
32-
This custom module evaluates Cloud KMS CryptoKeys to ensure their rotation period exceeds 30 days (2592000 seconds),
33-
as per security best practices. A shorter rotation period helps reduce the risk of exposure in the event of a compromise.
31+
This custom module creates a configurable bad IP type custom module, which can be used to detect and block malicious IP addresses.
3432
3533
Args:
3634
parent: Use any one of the following options:
3735
- organizations/{organization_id}/locations/{location_id}
3836
- folders/{folder_id}/locations/{location_id}
3937
- projects/{project_id}/locations/{location_id}
4038
Returns:
41-
Dict: Created custom module details.
39+
EventThreatDetectionCustomModule
4240
"""
4341
client = securitycentermanagement_v1.SecurityCenterManagementClient()
4442

@@ -84,7 +82,7 @@ def create_event_threat_detection_custom_module(parent: str) -> Dict:
8482
print(f"Created EventThreatDetectionCustomModule: {response.name}")
8583
return response
8684

87-
except Exception as e:
85+
except GoogleAPICallError as e:
8886
print(f"Failed to create EventThreatDetectionCustomModule: {e}")
8987
raise
9088

@@ -116,7 +114,7 @@ def get_event_threat_detection_custom_module(parent: str, module_id: str):
116114
print(f"Retrieved Event Threat Detection Custom Module: {response.name}")
117115
return response
118116
except NotFound as e:
119-
print(f"Custom Module not found: {response.name}")
117+
print(f"Custom Module not found: {e.message}")
120118
raise e
121119
# [END securitycenter_get_event_threat_detection_custom_module]
122120

@@ -153,9 +151,7 @@ def list_event_threat_detection_custom_module(parent: str):
153151
except NotFound as e:
154152
print(f"Parent resource not found: {parent}")
155153
raise e
156-
except Exception as e:
157-
print(f"An error occurred while listing custom modules: {e}")
158-
raise e
154+
159155
# [END securitycenter_list_event_threat_detection_custom_module]
160156

161157

@@ -170,7 +166,7 @@ def update_event_threat_detection_custom_module(parent: str, module_id: str):
170166
- folders/{folder_id}/locations/{location_id}
171167
- projects/{project_id}/locations/{location_id}
172168
Returns:
173-
Dict: Created custom module details.
169+
EventThreatDetectionCustomModule
174170
"""
175171
client = securitycentermanagement_v1.SecurityCenterManagementClient()
176172

securitycenter/snippets_management_api/event_threat_detection_custom_modules_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ def test_delete_event_threat_detection_custom_module():
193193
response = event_threat_detection_custom_modules.delete_event_threat_detection_custom_module(parent, module_id)
194194
except Exception as e:
195195
pytest.fail(f"delete_event_threat_detection_custom_module() failed: {e}")
196-
return
197196
assert response is None
198197

199198
print(f"Custom module was deleted successfully: {module_id}")

0 commit comments

Comments
 (0)