|
18 | 18 | import time |
19 | 19 | from typing import Dict |
20 | 20 |
|
| 21 | +from google.api_core.exceptions import NotFound |
21 | 22 | from google.cloud import securitycentermanagement_v1 |
22 | | -from google.protobuf.struct_pb2 import Struct |
23 | 23 | from google.protobuf.field_mask_pb2 import FieldMask |
| 24 | +from google.protobuf.struct_pb2 import Struct |
24 | 25 |
|
25 | 26 |
|
26 | 27 | # [START securitycenter_create_event_threat_detection_custom_module] |
@@ -89,6 +90,7 @@ def create_event_threat_detection_custom_module(parent: str) -> Dict: |
89 | 90 |
|
90 | 91 | # [END securitycenter_create_event_threat_detection_custom_module] |
91 | 92 |
|
| 93 | + |
92 | 94 | # [START securitycenter_get_event_threat_detection_custom_module] |
93 | 95 | def get_event_threat_detection_custom_module(parent: str, module_id: str): |
94 | 96 | """ |
@@ -118,6 +120,7 @@ def get_event_threat_detection_custom_module(parent: str, module_id: str): |
118 | 120 | raise e |
119 | 121 | # [END securitycenter_get_event_threat_detection_custom_module] |
120 | 122 |
|
| 123 | + |
121 | 124 | # [START securitycenter_list_event_threat_detection_custom_module] |
122 | 125 | def list_event_threat_detection_custom_module(parent: str): |
123 | 126 | """ |
@@ -155,6 +158,7 @@ def list_event_threat_detection_custom_module(parent: str): |
155 | 158 | raise e |
156 | 159 | # [END securitycenter_list_event_threat_detection_custom_module] |
157 | 160 |
|
| 161 | + |
158 | 162 | # [START securitycenter_update_event_threat_detection_custom_module] |
159 | 163 | def update_event_threat_detection_custom_module(parent: str, module_id: str): |
160 | 164 | """ |
@@ -194,3 +198,32 @@ def update_event_threat_detection_custom_module(parent: str, module_id: str): |
194 | 198 | raise |
195 | 199 |
|
196 | 200 | # [END securitycenter_update_event_threat_detection_custom_module] |
| 201 | + |
| 202 | + |
| 203 | +# [START securitycenter_delete_event_threat_detection_custom_module] |
| 204 | +def delete_event_threat_detection_custom_module(parent: str, module_id: str): |
| 205 | + """ |
| 206 | + Deletes an Event Threat Detection custom module. |
| 207 | + Args: |
| 208 | + parent: Use any one of the following options: |
| 209 | + - organizations/{organization_id}/locations/{location_id} |
| 210 | + - folders/{folder_id}/locations/{location_id} |
| 211 | + - projects/{project_id}/locations/{location_id} |
| 212 | + Returns: |
| 213 | + Message that Event Threat Detection custom module is deleted. |
| 214 | + Raises: |
| 215 | + NotFound: If the specified custom module does not exist. |
| 216 | + """ |
| 217 | + client = securitycentermanagement_v1.SecurityCenterManagementClient() |
| 218 | + |
| 219 | + try: |
| 220 | + request = securitycentermanagement_v1.DeleteEventThreatDetectionCustomModuleRequest( |
| 221 | + name=f"{parent}/eventThreatDetectionCustomModules/{module_id}", |
| 222 | + ) |
| 223 | + |
| 224 | + client.delete_event_threat_detection_custom_module(request=request) |
| 225 | + print(f"Deleted Event Threat Detection Custom Module Successfully: {module_id}") |
| 226 | + except NotFound as e: |
| 227 | + print(f"Custom Module not found: {module_id}") |
| 228 | + raise e |
| 229 | +# [END securitycenter_delete_event_threat_detection_custom_module] |
0 commit comments