Skip to content

Conversation

@chalmerlowe
Copy link
Contributor

Deleting older snippets.py files because the samples in it are adequately covered by the samples in these other files that were recently imported from google-auth-library-python:

What do we need to do to make this happen and have it be successful?

  • Do I need to do something special with the region tags?
  • Is there something that needs to happen so that the samples are picked up by the documentation website?

[START auth_cloud_implicit] is replaced by the sample in this file:
authenticate_implicit_with_adc.py > [START auth_cloud_implicit_adc]

[START auth_cloud_explicit] is replaced by the sample in this file:
authenticate_explicit_with_adc.py > [START auth_cloud_explicit_adc]

[START auth_cloud_explicit_compute_engine] is replaced by the sample in this file:
idtoken_from_metadata_server.py > [START auth_cloud_idtoken_metadata_server]

[START auth_cloud_accesstoken_impersonated_credentials] is replaced by the sample in this file:
idtoken_from_impersonated_credentials.py > [START auth_cloud_idtoken_impersonated_credentials]

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: auth Issues related to the Google Authentication API labels Feb 9, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @chalmerlowe, 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!

This pull request undertakes a significant refactoring and cleanup of Google Cloud authentication sample code. It eliminates redundant snippets.py files by migrating their functionality to a set of more granular and recently imported samples. The changes involve a strategic reorganization of sample files, updates to project dependencies, and a complete overhaul of the corresponding test suite to ensure continued coverage and correctness for the new sample structure. This effort aims to improve maintainability and clarity of the authentication samples.

Highlights

  • Sample Deduplication: Older snippets.py files and their associated infrastructure are being removed as their functionality is now covered by recently imported, more granular samples from google-auth-library-python.
  • File Restructuring and Renaming: Several authentication sample files (e.g., authenticate_explicit_with_adc.py, idtoken_from_metadata_server.py) have been moved from a temporary directory (auth/cloud-client-temp/) to the main auth/cloud-client/ directory, consolidating the sample code.
  • Dependency Updates: The auth/cloud-client/requirements.txt file has been updated to include a more comprehensive set of dependencies, such as google-cloud-compute, google-auth, pytest, boto3, requests, and python-dotenv, aligning with the requirements of the new samples.
  • Test Suite Refactor: The snippets_test.py file in auth/cloud-client/ has been completely rewritten to align with the new, individual sample files, replacing tests for the monolithic snippets.py and ensuring proper coverage for the updated structure.
  • Cleanup of Temporary Files: Associated noxfile.py, requirements.txt, and snippets_test.py from the auth/cloud-client-temp/ directory, along with requirements-test.txt from auth/cloud-client/, have been removed as part of the cleanup.
Changelog
  • auth/cloud-client-temp/authenticate_explicit_with_adc.py
    • Renamed to auth/cloud-client/authenticate_explicit_with_adc.py.
  • auth/cloud-client-temp/authenticate_implicit_with_adc.py
    • Renamed to auth/cloud-client/authenticate_implicit_with_adc.py.
  • auth/cloud-client-temp/custom_aws_supplier.py
    • Renamed to auth/cloud-client/custom_aws_supplier.py.
  • auth/cloud-client-temp/custom_okta_supplier.py
    • Renamed to auth/cloud-client/custom_okta_supplier.py.
  • auth/cloud-client-temp/idtoken_from_impersonated_credentials.py
    • Renamed to auth/cloud-client/idtoken_from_impersonated_credentials.py.
  • auth/cloud-client-temp/idtoken_from_metadata_server.py
    • Renamed to auth/cloud-client/idtoken_from_metadata_server.py.
  • auth/cloud-client-temp/idtoken_from_service_account.py
    • Renamed to auth/cloud-client/idtoken_from_service_account.py.
  • auth/cloud-client-temp/noxfile.py
    • Removed.
  • auth/cloud-client-temp/noxfile_config.py
    • Renamed to auth/cloud-client/noxfile_config.py.
  • auth/cloud-client-temp/requirements.txt
    • Removed.
  • auth/cloud-client-temp/snippets_test.py
    • Removed.
  • auth/cloud-client-temp/verify_google_idtoken.py
    • Renamed to auth/cloud-client/verify_google_idtoken.py.
  • auth/cloud-client/requirements-test.txt
    • Removed.
  • auth/cloud-client/requirements.txt
    • Updated to include new dependencies: google-cloud-compute, google-cloud-storage, google-auth, pytest, boto3, requests, and python-dotenv.
  • auth/cloud-client/snippets.py
    • Removed.
  • auth/cloud-client/snippets_test.py
    • Rewritten to test the new individual authentication sample files.
Activity
  • The author, chalmerlowe, has posed questions regarding the handling of region tags and the process for ensuring the new samples are correctly picked up by the documentation website. This indicates that the author is seeking clarification on the final steps for successful integration and documentation of these changes.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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.

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

This pull request correctly deduplicates the authentication samples by removing the older snippets.py and its related files, and migrating the newer samples from a temporary directory. The changes look good overall.

I've left a few comments:

  • In requirements.txt, the pytest dependency should be moved to a separate test-specific requirements file to avoid installing it in production. Also, the version specifiers for pytest need to be adjusted to cover all supported Python versions, and the === operator should be used for version pinning as per repository guidelines.
  • In snippets_test.py, two tests rely on the GOOGLE_APPLICATION_CREDENTIALS environment variable. I've suggested adding logic to skip these tests if the variable is not set, which will make the test suite more robust.

Comment on lines +4 to +5
pytest===8.4.2; python_version == '3.9'
pytest==9.0.2; python_version > '3.9'
Copy link
Contributor

Choose a reason for hiding this comment

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

high

There are a few issues with how pytest is specified here:

  1. Test dependencies in production requirements: pytest is a testing dependency and should not be included in the main requirements.txt file. This will cause it to be installed in production environments where it's not needed. It's standard practice to keep test dependencies in a separate file, like requirements-test.txt or dev-requirements.txt.

  2. Incomplete Python version coverage: The pytest dependency is only specified for Python 3.9 and greater. The project's previous test configuration (noxfile.py) supported Python 3.7 and 3.8. If these versions are still supported, tests will fail because pytest won't be installed. Please ensure test dependencies are available for all supported Python versions.

  3. Version specifier: For version pinning in requirements.txt, the === operator is preferred to prevent automated updates from overwriting specific version numbers required for certain Python runtimes.

I recommend removing these lines from this file and adding the corrected pytest dependency to a dedicated test requirements file, ensuring === is used for version pinning.

References
  1. Use the === operator in requirements.txt for version pinning to prevent automated updates from overwriting specific version numbers required for certain Python runtimes.


with credentials_patch:
snippets.explicit_compute_engine(project)
def test_idtoken_from_service_account(capsys: CaptureFixture) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test will fail if the GOOGLE_APPLICATION_CREDENTIALS environment variable is not set, as SERVICE_ACCOUNT_FILE will be None. It's good practice to skip tests that depend on environment variables when they aren't available. You can use the pytest.mark.skipif decorator for this.

Example:

import pytest

# ...

@pytest.mark.skipif(not SERVICE_ACCOUNT_FILE, reason="GOOGLE_APPLICATION_CREDENTIALS not set")
def test_idtoken_from_service_account(capsys: CaptureFixture) -> None:
    # ... test implementation

This will make your test suite more robust in different environments.

scope = "https://www.googleapis.com/auth/cloud-platform"
snippets.accesstoken_from_impersonated_credentials(
impersonated_service_account, scope
def test_verify_google_idtoken() -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to test_idtoken_from_service_account, this test depends on the GOOGLE_APPLICATION_CREDENTIALS environment variable and will fail if it's not set. This test should also be skipped when the variable is missing to prevent unexpected test failures.

Example:

import pytest

# ...

@pytest.mark.skipif(not SERVICE_ACCOUNT_FILE, reason="GOOGLE_APPLICATION_CREDENTIALS not set")
def test_verify_google_idtoken() -> None:
    # ... test implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: auth Issues related to the Google Authentication API samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant