@@ -76,30 +76,36 @@ def set_unmute_finding(finding_path: str) -> None:
76
76
77
77
78
78
# [START securitycenter_bulk_mute_v2]
79
- # def bulk_mute_findings(parent_path: str, location_id, mute_rule: str) -> None:
80
- # """
81
- # Kicks off a long-running operation (LRO) to bulk mute findings for a parent based on a filter.
82
- # The parent can be either an organization, folder, or project. The findings
83
- # matched by the filter will be muted after the LRO is done.
84
- # Args:
85
- # parent_path: use any one of the following options:
86
- # - organizations/{organization}
87
- # - folders/{folder}
88
- # - projects/{project}
89
- # mute_rule: Expression that identifies findings that should be updated.
90
- # """
91
- # from google.cloud import securitycenter_v2
92
-
93
- # client = securitycenter_v2.SecurityCenterClient()
94
-
95
- # request = securitycenter_v2.BulkMuteFindingsRequest()
96
- # request.parent = parent_path + "/locations/" + location_id
97
- # # To create mute rules, see:
98
- # # https://cloud.google.com/security-command-center/docs/how-to-mute-findings#create_mute_rules
99
- # request.filter = mute_rule
100
-
101
- # response = client.bulk_mute_findings(request)
102
- # print(f"Bulk mute findings completed successfully! : {response}")
103
- # return response
79
+ def bulk_mute_findings (parent_path : str , location_id : str , mute_rule : str ) -> None :
80
+ """
81
+ Kicks off a long-running operation (LRO) to bulk mute findings for a parent based on a filter.
82
+
83
+ The parent can be either an organization, folder, or project. The findings
84
+ matched by the filter will be muted after the LRO is done.
85
+
86
+ Args:
87
+ parent_path: Used to specify the resource under which the mute rule operates.
88
+ Use any one of the following options:
89
+ - organizations/{organization}
90
+ - folders/{folder}
91
+ - projects/{project}
92
+ location_id: The Google Cloud location ID, for example: 'global'.
93
+ mute_rule: Expression that identifies findings that should be updated.
94
+ """
95
+ from google .cloud import securitycenter_v2
96
+
97
+ client = securitycenter_v2 .SecurityCenterClient ()
98
+
99
+ request = securitycenter_v2 .BulkMuteFindingsRequest (
100
+ parent = f"{ parent_path } /locations/{ location_id } " ,
101
+ # To create mute rules, see:
102
+ # https://cloud.google.com/security-command-center/docs/how-to-mute-findings#create_mute_rules
103
+ filter = mute_rule ,
104
+ )
105
+
106
+ response = client .bulk_mute_findings (request )
107
+ print (f"Bulk mute findings completed successfully: { response } " )
108
+ return response
109
+
104
110
105
111
# [END securitycenter_bulk_mute_v2]
0 commit comments