Skip to content

Commit 6123233

Browse files
feat: add v2 API config for bulk mute finding to the existing mute config Python client library or samples (#12609)
* Add bulk mute finding config * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix the build error * remove unused import * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Address suggestions * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Add type annotation for location id * Address suggestions * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * refactor the filter value --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 66eca62 commit 6123233

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

securitycenter/snippets_v2/mute_findings_v2.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,30 +76,36 @@ def set_unmute_finding(finding_path: str) -> None:
7676

7777

7878
# [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+
104110

105111
# [END securitycenter_bulk_mute_v2]

securitycenter/snippets_v2/mute_findings_v2_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ def test_set_unmute_finding(finding):
6767
assert response.mute.name == "UNMUTED"
6868

6969

70-
# @backoff.on_exception(
71-
# backoff.expo, (InternalServerError, ServiceUnavailable, NotFound), max_tries=3
72-
# )
73-
# def test_bulk_mute_findings(finding):
74-
# # Mute findings that belong to this project.
75-
# response = mute_findings_v2.bulk_mute_findings(
76-
# f"organizations/{ORGANIZATION_ID}",
77-
# "global",
78-
# f'resource.project_display_name="{ORGANIZATION_ID}"',
79-
# )
80-
# assert response.done
70+
@backoff.on_exception(
71+
backoff.expo, (InternalServerError, ServiceUnavailable, NotFound), max_tries=3
72+
)
73+
def test_bulk_mute_findings(finding):
74+
# Mute findings that belong to this project.
75+
response = mute_findings_v2.bulk_mute_findings(
76+
f"organizations/{ORGANIZATION_ID}",
77+
"global",
78+
f'resource.project_display_name="{ORGANIZATION_ID}"',
79+
)
80+
assert response.done

0 commit comments

Comments
 (0)