Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit fe05cc3

Browse filesBrowse files
authored
docs(samples): included snippet for unmute finding (#308)
1 parent 4551d1f commit fe05cc3
Copy full SHA for fe05cc3

File tree

Expand file treeCollapse file tree

2 files changed

+41
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+41
-6
lines changed

‎samples/snippets/snippets_mute_config.py

Copy file name to clipboardExpand all lines: samples/snippets/snippets_mute_config.py
+33-5Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ def update_mute_rule(mute_config_name: str) -> None:
176176
# [END securitycenter_update_mute_config]
177177

178178

179-
# [START securitycenter_set_mute_unmute]
180-
def set_mute_unmute_finding(finding_path: str) -> None:
179+
# [START securitycenter_set_mute]
180+
def set_mute_finding(finding_path: str) -> None:
181181
"""
182-
Mute/unmute an individual finding.
182+
Mute an individual finding.
183183
If a finding is already muted, muting it again has no effect.
184-
Similarly, unmuting a finding that isn't muted has no effect.
185184
Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
186185
Args:
187186
finding_path: The relative resource name of the finding. See:
@@ -203,7 +202,36 @@ def set_mute_unmute_finding(finding_path: str) -> None:
203202
print(f"Mute value for the finding: {finding.mute.name}")
204203

205204

206-
# [END securitycenter_set_mute_unmute]
205+
# [END securitycenter_set_mute]
206+
207+
208+
# [START securitycenter_set_unmute]
209+
def set_unmute_finding(finding_path: str) -> None:
210+
"""
211+
Unmute an individual finding.
212+
Unmuting a finding that isn't muted has no effect.
213+
Various mute states are: MUTE_UNSPECIFIED/MUTE/UNMUTE.
214+
Args:
215+
finding_path: The relative resource name of the finding. See:
216+
https://cloud.google.com/apis/design/resource_names#relative_resource_name
217+
Use any one of the following formats:
218+
- organizations/{organization_id}/sources/{source_id}/finding/{finding_id},
219+
- folders/{folder_id}/sources/{source_id}/finding/{finding_id},
220+
- projects/{project_id}/sources/{source_id}/finding/{finding_id}.
221+
"""
222+
from google.cloud import securitycenter
223+
224+
client = securitycenter.SecurityCenterClient()
225+
226+
request = securitycenter.SetMuteRequest()
227+
request.name = finding_path
228+
request.mute = securitycenter.Finding.Mute.UNMUTED
229+
230+
finding = client.set_mute(request)
231+
print(f"Mute value for the finding: {finding.mute.name}")
232+
233+
234+
# [END securitycenter_set_unmute]
207235

208236

209237
# [START securitycenter_bulk_mute]

‎samples/snippets/snippets_mute_config_test.py

Copy file name to clipboardExpand all lines: samples/snippets/snippets_mute_config_test.py
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,18 @@ def test_update_mute_rule(capsys: CaptureFixture, mute_rule):
107107

108108
def test_set_mute_finding(capsys: CaptureFixture, finding):
109109
finding_path = finding.get("finding1")
110-
snippets_mute_config.set_mute_unmute_finding(finding_path)
110+
snippets_mute_config.set_mute_finding(finding_path)
111111
out, _ = capsys.readouterr()
112112
assert re.search("Mute value for the finding: MUTED", out)
113113

114114

115+
def test_set_unmute_finding(capsys: CaptureFixture, finding):
116+
finding_path = finding.get("finding1")
117+
snippets_mute_config.set_unmute_finding(finding_path)
118+
out, _ = capsys.readouterr()
119+
assert re.search("Mute value for the finding: UNMUTED", out)
120+
121+
115122
def test_bulk_mute_findings(capsys: CaptureFixture, finding):
116123
# Mute findings that belong to this project.
117124
snippets_mute_config.bulk_mute_findings(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.