Skip to content

Commit 2cc3c3b

Browse files
author
Micah Kornfield
committed
Update list assets to better conform to rubrics and to v1 add other tests to noxfile
1 parent 3d525b2 commit 2cc3c3b

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

securitycenter/docs/snippets_list_assets.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,24 @@
1717
""" Examples of listing assets in Cloud Security Command Center."""
1818
import os
1919
from 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"'

securitycenter/noxfile.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ def snippets(session):
158158
session.run(
159159
'py.test',
160160
'--quiet',
161-
os.path.join('docs', 'snippets_list_assets.py'),
161+
os.path.join('docs', 'snippets_security_marks.py'),
162+
os.path.join('docs', 'snippets_orgs.py'),
163+
os.path.join('docs', 'snippets_findings.py'),
164+
os.path.join('docs', 'snippets_security_marks.py'),
165+
166+
162167
*session.posargs
163168
)

0 commit comments

Comments
 (0)