1717""" Examples of listing assets in Cloud Security Command Center."""
1818import os
1919from datetime import datetime , timedelta
20+ import pytest
2021
2122
22- # The numeric identifier for the organization.
23- ORGANIZATION_ID = os .environ ["GCLOUD_ORGANIZATION" ]
23+ @pytest .fixture (scope = "module" )
24+ def organization_id ():
25+ """Get Organization ID from the environment variable """
26+ return os .environ ["GCLOUD_ORGANIZATION" ]
2427
2528
26- def test_list_all_assets ():
29+ def test_list_all_assets (organization_id ):
2730 """Demonstrate listing and printing all assets."""
28- from google .cloud import securitycenter_v1beta1 as securitycenter
29-
3031 # [START demo_list_all_assets]
32+ from google .cloud import securitycenter as securitycenter
33+
3134 client = securitycenter .SecurityCenterClient ()
32- # ORGANIZATION_ID is the numeric ID of the organization (e.g. 123213123121)
33- org_name = "organizations/{org_id}" .format (org_id = ORGANIZATION_ID )
35+ # organization_id is the numeric ID of the organization.
36+ # organization_id=1234567777
37+ org_name = "organizations/{org_id}" .format (org_id = organization_id )
3438
3539 # Call the API and print results.
3640 asset_iterator = client .list_assets (org_name )
@@ -40,15 +44,16 @@ def test_list_all_assets():
4044 assert i > 0
4145
4246
43- def test_list_assets_with_filters ():
47+ def test_list_assets_with_filters (organization_id ):
4448 """Demonstrate listing assets with a filter."""
45- from google .cloud import securitycenter_v1beta1 as securitycenter
46-
4749 # [START demo_list_assets_with_filter]
50+ from google .cloud import securitycenter as securitycenter
51+
4852 client = securitycenter .SecurityCenterClient ()
4953
50- # ORGANIZATION_ID is the numeric ID of the organization (e.g. 123213123121)
51- org_name = "organizations/{org_id}" .format (org_id = ORGANIZATION_ID )
54+ # organization_id is the numeric ID of the organization.
55+ # organization_id=1234567777
56+ org_name = "organizations/{org_id}" .format (org_id = organization_id )
5257
5358 project_filter = (
5459 "security_center_properties.resource_type="
@@ -62,17 +67,20 @@ def test_list_assets_with_filters():
6267 assert i > 0
6368
6469
65- def test_list_assets_with_filters_and_read_time ():
70+ def test_list_assets_with_filters_and_read_time (organization_id ):
6671 """Demonstrate listing assets with a filter."""
72+ # [START demo_list_assets_with_filter_and_time]
6773 from datetime import datetime , timedelta
68- from google . cloud import securitycenter_v1beta1 as securitycenter
74+
6975 from google .protobuf .timestamp_pb2 import Timestamp
7076
71- # [START demo_list_assets_with_filter_and_time]
77+ from google .cloud import securitycenter as securitycenter
78+
7279 client = securitycenter .SecurityCenterClient ()
7380
74- # ORGANIZATION_ID is the numeric ID of the organization (e.g. 123213123121)
75- org_name = "organizations/{org_id}" .format (org_id = ORGANIZATION_ID )
81+ # organization_id is the numeric ID of the organization.
82+ # organization_id=1234567777
83+ org_name = "organizations/{org_id}" .format (org_id = organization_id )
7684
7785 project_filter = (
7886 "security_center_properties.resource_type="
@@ -94,17 +102,19 @@ def test_list_assets_with_filters_and_read_time():
94102 assert i > 0
95103
96104
97- def test_list_point_in_time_changes ():
105+ def test_list_point_in_time_changes (organization_id ):
98106 """Demonstrate listing assets along with their state changes."""
99- from google .cloud import securitycenter_v1beta1 as securitycenter
100- from google .protobuf .duration_pb2 import Duration
107+ # [START demo_list_assets_changes]
101108 from datetime import timedelta
102109
103- # [START demo_list_assets_changes]
110+ from google .protobuf .duration_pb2 import Duration
111+ from google .cloud import securitycenter as securitycenter
112+
104113 client = securitycenter .SecurityCenterClient ()
105114
106- # ORGANIZATION_ID is the numeric ID of the organization (e.g. 123213123121)
107- org_name = "organizations/{org_id}" .format (org_id = ORGANIZATION_ID )
115+ # organization_id is the numeric ID of the organization.
116+ # organization_id=1234567777
117+ org_name = "organizations/{org_id}" .format (org_id = organization_id )
108118 project_filter = (
109119 "security_center_properties.resource_type="
110120 + '"google.cloud.resourcemanager.Project"'
0 commit comments