Skip to content

Commit e79e316

Browse files
busunkim96telpirion
authored andcommitted
chore(samples): use timezone aware datetimes (#208)
- Use timezone aware datetimes - Update pubsub
1 parent 7a9b74b commit e79e316

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
google-cloud-pubsub==2.7.0
1+
google-cloud-pubsub==2.7.1
22
google-cloud-securitycenter==1.5.0

securitycenter/snippets/snippets_findings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def create_finding(source_name):
158158
client = securitycenter.SecurityCenterClient()
159159

160160
# Use the current time as the finding "event time".
161-
event_time = datetime.datetime.now()
161+
event_time = datetime.datetime.now(tz=datetime.timezone.utc)
162162

163163
# source_name is the resource path for a source that has been
164164
# created previously (you can use list_sources to find a specific one).
@@ -230,7 +230,7 @@ def create_finding_with_source_properties(source_name):
230230
num_value.number_value = 1234
231231

232232
# Use the current time as the finding "event time".
233-
event_time = datetime.datetime.now()
233+
event_time = datetime.datetime.now(tz=datetime.timezone.utc)
234234

235235
finding = Finding(
236236
state=Finding.State.ACTIVE,
@@ -268,7 +268,7 @@ def update_finding(source_name):
268268

269269
# Set the update time to Now. This must be some time greater then the
270270
# event_time on the original finding.
271-
event_time = datetime.datetime.now()
271+
event_time = datetime.datetime.now(tz=datetime.timezone.utc)
272272

273273
# source_name is the resource path for a source that has been
274274
# created previously (you can use list_sources to find a specific one).
@@ -319,7 +319,7 @@ def update_finding_state(source_name):
319319
request={
320320
"name": finding_name,
321321
"state": Finding.State.INACTIVE,
322-
"start_time": datetime.datetime.now(),
322+
"start_time": datetime.datetime.now(tz=datetime.timezone.utc),
323323
}
324324
)
325325
print(f"New state: {new_finding.state}")

securitycenter/snippets/snippets_list_assets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def list_assets_with_filters_and_read_time(organization_id):
6666
"""Demonstrate listing assets with a filter."""
6767
i = 0
6868
# [START securitycenter_list_assets_at_time]
69-
from datetime import datetime, timedelta
69+
from datetime import datetime, timedelta, timezone
7070

7171
from google.cloud import securitycenter
7272

@@ -82,7 +82,7 @@ def list_assets_with_filters_and_read_time(organization_id):
8282
)
8383

8484
# Lists assets as of yesterday.
85-
read_time = datetime.utcnow() - timedelta(days=1)
85+
read_time = datetime.now(tz=timezone.utc) - timedelta(days=1)
8686

8787
# Call the API and print results.
8888
asset_iterator = client.list_assets(

0 commit comments

Comments
 (0)