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

Conversation

eapl-gemugami
Copy link
Contributor

@eapl-gemugami eapl-gemugami commented Mar 10, 2025

Description

Fixes Internal: b/402176817

  • Delete samples securitycenter_group_findings_with_changes and securitycenter_group_findings_at_time

Update failing samples due to changes in API

  • Fix sample securitycenter_list_findings_at_time
  • Add backoff to test_update_asset_discovery_org_settings
  • Update dependencies to latest versions
  • Change import from securitycenter to securitycenter_v1 to make explicit which version is being used
  • Add an exception to securitycenter_receive_notifications as in the Java sample, to ignore a ParsingError.

Improvements to samples

  • Use the same importing style for all datetime objects across samples in snippet_findings.py
  • Remove deprecation warning for utcnow()
  • Use a timezone compatible with Python 3.9 (as datetime.UTC was added in Python 3.11)

Checklist

… warnings

- Use same importing style for all datetime objects across samples
- Use a timezone compatible with Python 3.9 (as datetime.UTC was added in Python 3.11)
- Remove deprecation warning for utcnow()
- Add debug prints to watch failing tests
@product-auto-label product-auto-label bot added api: securitycenter Issues related to the Security Command Center API. samples Issues that are directly related to samples. labels Mar 10, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @eapl-gemugami, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses an internal issue (b/402176817) by unifying the syntax for datetime objects across the securitycenter samples, resolving deprecation warnings, and ensuring compatibility with Python 3.9. Specifically, it standardizes the import style for datetime objects, uses a timezone compatible with Python 3.9 (datetime.UTC was introduced in Python 3.11), and removes the deprecation warning associated with utcnow(). Debug prints have also been added to aid in troubleshooting failing tests.

Highlights

  • Datetime Syntax Unification: The pull request standardizes the way datetime objects are imported and used across the securitycenter samples.
  • Python 3.9 Compatibility: The code is updated to use a timezone compatible with Python 3.9, as datetime.UTC was introduced in Python 3.11.
  • Deprecation Warning Removal: The deprecation warning for utcnow() has been removed.
  • Debugging Enhancements: Debug print statements have been added to assist in identifying and resolving failing tests.

Changelog

  • securitycenter/snippets/snippets_findings.py
    • Replaced import datetime with from datetime import datetime, timezone for consistent datetime object handling. (lines 155, 197, 247, 291, 422, 543)
    • Replaced datetime.datetime.now(tz=datetime.timezone.utc) with datetime.now(tz=timezone.utc) for Python 3.9 compatibility. (lines 164, 228, 262, 311)
    • Replaced datetime.now() - timedelta(days=5) with datetime.now(timezone.utc) - timedelta(days=5) for five_days_ago variable. (line 439)
    • Added debug print statement for five_days_ago variable. (line 442)
    • Replaced datetime.utcnow() - timedelta(days=1) with datetime.now(timezone.utc) - timedelta(days=1) for read_time variable. (line 561)
    • Added debug print statement for read_time variable. (line 564)
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Did you know?

The concept of time zones was largely popularized by the expansion of railways in the 19th century, as standardized time became essential for coordinating train schedules.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request aims to unify the syntax for datetime objects and remove deprecation warnings in the securitycenter snippets. The changes look good overall, addressing the specified issues. However, there are a couple of points that could be improved.

Summary of Findings

  • Unnecessary debug prints: The debug prints added to watch failing tests should be removed before merging the pull request.
  • TODO comments: The TODO comments indicating the debug prints should be removed should be addressed before merging the pull request.

Merge Readiness

The pull request is almost ready for merging. The core issue of unifying datetime syntax and removing deprecation warnings has been addressed. However, the debug prints and corresponding TODO comments should be removed before merging. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging.

@eapl-gemugami eapl-gemugami changed the title fix(securitycenter): unify syntax for datetime and remove deprecation warnings fix(securitycenter): delete deprecated samples Mar 11, 2025
@eapl-gemugami eapl-gemugami changed the title fix(securitycenter): delete deprecated samples fix(securitycenter): delete deprecated samples and update samples Mar 11, 2025
@eapl-gemugami eapl-gemugami added the snippet-bot:force-run Force snippet-bot runs its logic label Mar 11, 2025
@snippet-bot snippet-bot bot removed the snippet-bot:force-run Force snippet-bot runs its logic label Mar 11, 2025
Copy link

snippet-bot bot commented Mar 11, 2025

Here is the summary of changes.

You are about to delete 2 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@eapl-gemugami eapl-gemugami requested a review from iennae March 11, 2025 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: securitycenter Issues related to the Security Command Center API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant