Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(securitycenter): delete deprecated samples and update samples #13223

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b057ddc
fix(securitycenter): unify syntax for datetime and remove deprecation…
eapl-gemugami Mar 10, 2025
b67d15a
fix(securitycenter): minor fixes and lint
eapl-gemugami Mar 10, 2025
de45e03
fix(securitycenter): update to latest dependencies
eapl-gemugami Mar 10, 2025
7716723
fix(securitycenter): revert to previous versions of dependencies
eapl-gemugami Mar 10, 2025
7dcb491
fix(securitycenter): comment parameter to check if that skips 400 Req…
eapl-gemugami Mar 10, 2025
a6791a3
fix(securitycenter): remove UTC timezone to validate a conversion pro…
eapl-gemugami Mar 10, 2025
5506aec
fix(securitycenter): delete samples
eapl-gemugami Mar 11, 2025
387cfe4
fix(securitycenter): try fixing list_findings_at_time
eapl-gemugami Mar 11, 2025
1d4b86b
fix(securitycenter): update pubsub version
eapl-gemugami Mar 11, 2025
76f674f
fix(securitycenter): fix linting
eapl-gemugami Mar 11, 2025
ad48adf
fix(securitycenter): fix date conversion to string
eapl-gemugami Mar 11, 2025
961b206
fix(security): update securitycenter version
eapl-gemugami Mar 11, 2025
a82d149
fix(securitycenter): update google-cloud-bigquery
eapl-gemugami Mar 11, 2025
a05a43b
fix(securitycenter): change imports from 'securitycenter' to 'securit…
eapl-gemugami Mar 11, 2025
0492126
fix(securitycenter): fix missing rename
eapl-gemugami Mar 11, 2025
327a7cd
fix(securitycenter): add backoff to 'test_update_asset_discovery_org_…
eapl-gemugami Mar 11, 2025
cdec308
fix(securitycenter): aim for the assert value in list_findings_at_time
eapl-gemugami Mar 11, 2025
5a5a9da
fix(securitycenter): add backoff to receive_notifications
eapl-gemugami Mar 11, 2025
23552d0
fix(securitycenter): fix linting
eapl-gemugami Mar 11, 2025
1542f7b
fix(securitycenter): try to fix exception in receive_notifications
eapl-gemugami Mar 11, 2025
341e837
fix(securitycenter): catch a ParseError on messages
eapl-gemugami Mar 11, 2025
5aff387
fix(securitycenter): fix linting
eapl-gemugami Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions securitycenter/snippets/snippets_findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def list_source(organization_id):
def create_finding(source_name, finding_id):
"""Creates a new finding."""
# [START securitycenter_create_finding]
import datetime
from datetime import datetime, timezone

from google.cloud import securitycenter
from google.cloud.securitycenter_v1 import Finding
Expand All @@ -161,7 +161,7 @@ def create_finding(source_name, finding_id):
client = securitycenter.SecurityCenterClient()

# Use the current time as the finding "event time".
event_time = datetime.datetime.now(tz=datetime.timezone.utc)
event_time = datetime.now(tz=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 @@ -194,7 +194,7 @@ def create_finding(source_name, finding_id):
def create_finding_with_source_properties(source_name):
"""Demonstrate creating a new finding with source properties."""
# [START securitycenter_create_finding_with_source_properties]
import datetime
from datetime import datetime, timezone

from google.cloud import securitycenter
from google.cloud.securitycenter_v1 import Finding
Expand Down Expand Up @@ -225,7 +225,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(tz=datetime.timezone.utc)
event_time = datetime.now(tz=timezone.utc)

finding = Finding(
state=Finding.State.ACTIVE,
Expand All @@ -244,7 +244,7 @@ def create_finding_with_source_properties(source_name):

def update_finding(source_name):
# [START securitycenter_update_finding_source_properties]
import datetime
from datetime import datetime, timezone

from google.cloud import securitycenter
from google.cloud.securitycenter_v1 import Finding
Expand All @@ -259,7 +259,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(tz=datetime.timezone.utc)
event_time = datetime.now(tz=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 @@ -288,7 +288,7 @@ def update_finding(source_name):
def update_finding_state(source_name):
"""Demonstrate updating only a finding state."""
# [START securitycenter_update_finding_state]
import datetime
from datetime import datetime, timezone

from google.cloud import securitycenter
from google.cloud.securitycenter_v1 import Finding
Expand All @@ -308,7 +308,7 @@ def update_finding_state(source_name):
request={
"name": finding_name,
"state": Finding.State.INACTIVE,
"start_time": datetime.datetime.now(tz=datetime.timezone.utc),
"start_time": datetime.now(timezone.utc),
}
)
print(f"New state: {new_finding.state}")
Expand Down Expand Up @@ -419,7 +419,7 @@ def list_filtered_findings(source_name):

def list_findings_at_time(source_name):
# [START securitycenter_list_findings_at_time]
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from google.cloud import securitycenter

Expand All @@ -436,7 +436,11 @@ def list_findings_at_time(source_name):
# "folders/{folder_id}"
# You an also use a wild-card "-" for all sources:
# source_name = "organizations/111122222444/sources/-"
five_days_ago = str(datetime.now() - timedelta(days=5))
five_days_ago = str(datetime.now(timezone.utc) - timedelta(days=5))

# TODO: Remove this after passing the tests
print(f'{five_days_ago=}')

# [END securitycenter_list_findings_at_time]
i = -1
# [START securitycenter_list_findings_at_time]
Expand Down Expand Up @@ -536,7 +540,7 @@ def group_findings_at_time(source_name):
a specific time."""
i = -1
# [START securitycenter_group_findings_at_time]
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from google.cloud import securitycenter

Expand All @@ -554,7 +558,10 @@ def group_findings_at_time(source_name):
# source_name = "organizations/111122222444/sources/1234"

# Group findings as of yesterday.
read_time = datetime.utcnow() - timedelta(days=1)
read_time = datetime.now(timezone.utc) - timedelta(days=1)

# TODO: Remove this after passing the tests
print(f'{read_time=}')

group_result_iterator = client.group_findings(
request={"parent": source_name, "group_by": "category", "read_time": read_time}
Expand Down