Skip to content

Commit

Permalink
chore(samples): use timezone aware datetimes (#208)
Browse files Browse the repository at this point in the history
- Use timezone aware datetimes
- Update pubsub
  • Loading branch information
busunkim96 authored Aug 27, 2021
1 parent 1c668cb commit d11c7c2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion securitycenter/snippets/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
google-cloud-pubsub==2.7.0
google-cloud-pubsub==2.7.1
google-cloud-securitycenter==1.5.0
8 changes: 4 additions & 4 deletions securitycenter/snippets/snippets_findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def create_finding(source_name):
client = securitycenter.SecurityCenterClient()

# Use the current time as the finding "event time".
event_time = datetime.datetime.now()
event_time = datetime.datetime.now(tz=datetime.timezone.utc)

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

# Use the current time as the finding "event time".
event_time = datetime.datetime.now()
event_time = datetime.datetime.now(tz=datetime.timezone.utc)

finding = Finding(
state=Finding.State.ACTIVE,
Expand Down Expand Up @@ -268,7 +268,7 @@ def update_finding(source_name):

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

# source_name is the resource path for a source that has been
# created previously (you can use list_sources to find a specific one).
Expand Down Expand Up @@ -319,7 +319,7 @@ def update_finding_state(source_name):
request={
"name": finding_name,
"state": Finding.State.INACTIVE,
"start_time": datetime.datetime.now(),
"start_time": datetime.datetime.now(tz=datetime.timezone.utc),
}
)
print(f"New state: {new_finding.state}")
Expand Down
4 changes: 2 additions & 2 deletions securitycenter/snippets/snippets_list_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def list_assets_with_filters_and_read_time(organization_id):
"""Demonstrate listing assets with a filter."""
i = 0
# [START securitycenter_list_assets_at_time]
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from google.cloud import securitycenter

Expand All @@ -82,7 +82,7 @@ def list_assets_with_filters_and_read_time(organization_id):
)

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

# Call the API and print results.
asset_iterator = client.list_assets(
Expand Down

0 comments on commit d11c7c2

Please sign in to comment.