Skip to content

Commit 74734a1

Browse files
author
Micah Kornfield
committed
add missing policy and source tests
1 parent 8d20324 commit 74734a1

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

securitycenter/docs/snippets_findings.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,28 @@ def test_create_source(organization_id):
6565
# [END create_source]
6666

6767

68+
def test_get_source(source_name):
69+
"""Gets an existing source."""
70+
# [START get_source]
71+
from google.cloud import securitycenter as securitycenter
72+
from google.protobuf import field_mask_pb2
73+
74+
client = securitycenter.SecurityCenterClient()
75+
76+
# source_name is the resource path for a source that has been
77+
# created previously (you can use list_sources to find a specific one).
78+
# Its format is:
79+
# source_name = "organizations/{organization_id}/sources/{source_id}"
80+
# e.g.:
81+
# source_name = "organizations/111122222444/sources/1234"
82+
source = client.get_source(source_name)
83+
84+
print("Source: {}".format(source))
85+
# [END get_source]
86+
87+
6888
def test_update_source(source_name):
69-
"Updates a sources display name."
89+
"""Updates a source's display name."""
7090
# [START update_source]
7191
from google.cloud import securitycenter as securitycenter
7292
from google.protobuf import field_mask_pb2
@@ -447,3 +467,24 @@ def test_list_findings_at_time(source_name):
447467
)
448468
# [END list_findings_at_a_time]
449469
assert i == -1
470+
471+
472+
def test_get_iam_policy(source_name):
473+
"""Gives a user findingsEditor permission to the source."""
474+
user_email = "csccclienttest@gmail.com"
475+
# [START get_source_iam]
476+
from google.cloud import securitycenter as securitycenter
477+
from google.iam.v1 import policy_pb2
478+
479+
client = securitycenter.SecurityCenterClient()
480+
481+
# source_name is the resource path for a source that has been
482+
# created previously (you can use list_sources to find a specific one).
483+
# Its format is:
484+
# source_name = "organizations/{organization_id}/sources/{source_id}"
485+
# e.g.:
486+
# source_name = "organizations/111122222444/sources/1234"
487+
# Get the old policy so we can do an incremental update.
488+
policy = client.get_iam_policy(source_name)
489+
print("Policy: {}".format(policy))
490+
# [END get_source_iam]

0 commit comments

Comments
 (0)