Skip to content

chore(secretmanager): Add global samples for delayed destory #13312

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

Merged
merged 4 commits into from
Apr 24, 2025

Conversation

archana-9430
Copy link
Contributor

Description

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

@archana-9430 archana-9430 requested review from a team as code owners April 22, 2025 07:21
Copy link

snippet-bot bot commented Apr 22, 2025

Here is the summary of changes.

You are about to add 3 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

@product-auto-label product-auto-label bot added api: secretmanager Issues related to the Secret Manager API. samples Issues that are directly related to samples. labels Apr 22, 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 @archana-9430, 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 adds new samples for delayed destroy functionality in the Secret Manager. It includes code to create a secret with a delayed destroy TTL, disable the delayed destroy, and update the secret with a new delayed destroy TTL. The PR also includes corresponding tests for these new functionalities.

Highlights

  • New Samples: Adds create_secret_with_delayed_destroy.py, disable_secret_with_delayed_destroy.py, and update_secret_with_delayed_destroy.py to demonstrate the delayed destroy feature.
  • Test Coverage: Extends snippets_test.py to include tests for the new delayed destroy samples, ensuring proper functionality.
  • Functionality: Adds functionality to create, disable, and update secrets with delayed destroy.

Changelog

Click here to see the changelog
  • secretmanager/snippets/create_secret_with_delayed_destroy.py
    • Adds a new sample to create a secret with a specified version destroy TTL.
    • Includes argument parsing for project ID, secret ID, and version destroy TTL.
    • Uses the Secret Manager client to create the secret with the delayed destroy setting.
  • secretmanager/snippets/disable_secret_with_delayed_destroy.py
    • Adds a new sample to disable the delayed destroy setting on a secret.
    • Includes argument parsing for project ID and secret ID.
    • Uses the Secret Manager client to update the secret and remove the version destroy TTL.
  • secretmanager/snippets/snippets_test.py
    • Imports new modules for delayed destroy functionality.
    • Adds a new fixture secret_with_delayed_destroy to create a secret with delayed destroy for testing.
    • Adds tests for creating and disabling secrets with delayed destroy.
    • Adds a test for updating secrets with delayed destroy.
  • secretmanager/snippets/update_secret_with_delayed_destroy.py
    • Adds a new sample to update the version destroy TTL on an existing secret.
    • Includes argument parsing for project ID, secret ID, and the new version destroy TTL.
    • Uses the Secret Manager client to update the secret with the new delayed destroy setting.
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.


A secret's life,
A TTL to decide,
When it must fade.

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 introduces new functionalities for creating, disabling, and updating secrets with delayed destroy options in the Secret Manager API. The changes include new sample snippets and corresponding tests. Overall, the code is well-structured and addresses the intended functionality. However, there are a few areas that could be improved for clarity and correctness.

Summary of Findings

  • Inconsistent Argument Naming: The argument name version_destroy_ttl is used in multiple functions, but in update_secret_with_delayed_destroy.py, it's named new_version_destroy_ttl. Consistent naming improves readability and reduces confusion.
  • Incorrect Assertion in Test: In test_update_secret_with_delayed_destroy, the assertion assert updated_secret.version_destroy_ttl == timedelta(seconds=version_destroy_ttl) compares against the original version_destroy_ttl fixture value instead of the updated_version_destroy_ttl_value used in the update call. This will cause the test to fail.
  • Missing Input Validation: The code does not validate the version_destroy_ttl input. It should check if the value is within the allowed range and is a valid integer.

Merge Readiness

The pull request is almost ready for merging, but there are a few issues that need to be addressed. Specifically, the inconsistent argument naming, incorrect assertion in the test, and missing input validation should be fixed before merging. I am unable to approve this pull request, and other reviewers should review and approve this code before merging.

Comment on lines 598 to 599
updated_secret = update_secret_with_delayed_destroy(project_id, secret_id, updated_version_destroy_ttl_value)
assert updated_secret.version_destroy_ttl == timedelta(seconds=version_destroy_ttl)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The assertion compares against the original version_destroy_ttl fixture value instead of the updated_version_destroy_ttl_value used in the update call. This will cause the test to fail. It should be updated to compare against updated_version_destroy_ttl_value.

Suggested change
updated_secret = update_secret_with_delayed_destroy(project_id, secret_id, updated_version_destroy_ttl_value)
assert updated_secret.version_destroy_ttl == timedelta(seconds=version_destroy_ttl)
updated_secret = update_secret_with_delayed_destroy(project_id, secret_id, updated_version_destroy_ttl_value)
assert updated_secret.version_destroy_ttl == timedelta(seconds=updated_version_destroy_ttl_value)

Copy link
Member

@rsamborski rsamborski left a comment

Choose a reason for hiding this comment

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

Good job overall, please fix couple suggestions and I will approve.

return response


# [END secretmanager_create_secret_with_delayed_destroy]
Copy link
Member

Choose a reason for hiding this comment

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

nit: remove the trailing empty lines

from google.protobuf.duration_pb2 import Duration


# [START secretmanager_update_secret_with_delayed_destroy]
Copy link
Member

Choose a reason for hiding this comment

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

fix: region tag should start before all necessary imports (line 17 in this case)

@archana-9430
Copy link
Contributor Author

Hi Remigiusz,
Thanks for reviewing the PR.
Incorporated all the suggested changes. Please take a look!

@archana-9430 archana-9430 merged commit 38ac3ad into main Apr 24, 2025
14 checks passed
@archana-9430 archana-9430 deleted the sm-global-python-delayed-destroy-samples branch April 24, 2025 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: secretmanager Issues related to the Secret Manager API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants