1616
1717import random
1818import time
19- from typing import Dict
2019
21- from google .api_core .exceptions import NotFound
20+ from google .api_core .exceptions import GoogleAPICallError , NotFound
2221from google .cloud import securitycentermanagement_v1
2322from google .protobuf .field_mask_pb2 import FieldMask
2423from 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
0 commit comments