Skip to content

Add VPC sample for retrieving Google APIs and services IP ranges - #14496

Open
ersin-ertan wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
ersin-ertan:main
Open

Add VPC sample for retrieving Google APIs and services IP ranges#14496
ersin-ertan wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
ersin-ertan:main

Conversation

@ersin-ertan

@ersin-ertan ersin-ertan commented Aug 12, 2026

Copy link
Copy Markdown

Adds get_google_ip_ranges under vpc/ as the modernized and hardened replacement for the archived networking-tools-python/tools/cidr tool. This sample computes the IP address ranges (CIDRs) used exclusively for Google APIs and default domain services by calculating the set difference (goog.json - cloud.json). Key improvements over the archived implementation:

  • Python 3.9+ baseline with full PEP 484 type annotations.
  • Network hardening with explicit 30s timeouts (urlopen(url, timeout=30)).
  • Safe JSON & prefix parsing with graceful recovery on malformed entries.
  • Replaced legacy unittest + localhost HTTP server with hermetic pytest unit tests (8/8 passing).
  • Fully compliant with flake8, black, and nox style standards. Output Comparison:
  • Normal Execution: Outputs the exact same 360+ default domain CIDR blocks as the legacy tool.
  • Error Handling: Fixes a legacy bug where network/parsing failures caused an unhandled TypeError: unsupported operand type(s) for -: 'NoneType' and 'IPSet' crash; the new implementation exits cleanly with a descriptive ValueError. Testing:
  • Live verification: Ran python get_google_ip_ranges.py against live gstatic.com endpoints.
  • Unit testing: pytest -v (8/8 tests passing).
  • Linter & formatter: flake8 . (0 errors) and black --check . (clean).

Description

Fixes #

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

@ersin-ertan
ersin-ertan requested review from a team as code owners August 12, 2026 03:01
@snippet-bot

snippet-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

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 the samples Issues that are directly related to samples. label Aug 12, 2026

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

Copy link
Copy Markdown
Contributor

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 introduces a new Python sample script that retrieves Google's public IP range feeds and calculates the IP set difference to isolate CIDR ranges used exclusively for Google APIs and default services. The reviewer feedback focuses on improving the script's usability by redirecting all non-data output (status, warning, and error messages) to sys.stderr to keep stdout clean for CIDR data. Additionally, the feedback suggests handling potential TypeError exceptions when parsing invalid prefix entries, updating the test suite to assert against sys.stderr output, and adjusting the ignored_versions in noxfile_config.py to align with the repository's Python testing guidelines.

Comment thread vpc/get_google_ip_ranges/noxfile_config.py
Comment thread vpc/get_google_ip_ranges/get_google_ip_ranges.py
Comment thread vpc/get_google_ip_ranges/get_google_ip_ranges.py
Comment thread vpc/get_google_ip_ranges/get_google_ip_ranges.py
Comment thread vpc/get_google_ip_ranges/get_google_ip_ranges.py
Comment thread vpc/get_google_ip_ranges/get_google_ip_ranges_test.py
Comment thread vpc/get_google_ip_ranges/get_google_ip_ranges_test.py
Comment thread vpc/get_google_ip_ranges/get_google_ip_ranges_test.py
Comment thread vpc/get_google_ip_ranges/get_google_ip_ranges_test.py
Comment thread vpc/get_google_ip_ranges/get_google_ip_ranges_test.py
@ersin-ertan
ersin-ertan requested a review from a team as a code owner August 12, 2026 14:21
@ersin-ertan
ersin-ertan force-pushed the main branch 2 times, most recently from 09ecb18 to 98aea6a Compare August 12, 2026 14:25

@ersin-ertan ersin-ertan left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Adds get_google_ip_ranges under vpc/ as the modernized and hardened replacement for the archived networking-tools-python/tools/cidr tool.

This sample computes the IP address ranges (CIDRs) used exclusively for Google APIs and default domain services by calculating the set difference (goog.json - cloud.json).

Key improvements over the archived implementation:

  • Python 3.9+ baseline with full PEP 484 type annotations.
  • Network hardening with explicit 30s timeouts (urlopen(url, timeout=30)).
  • Safe JSON & prefix parsing with graceful recovery on malformed entries.
  • Replaced legacy unittest + localhost HTTP server with hermetic pytest unit tests (8/8 passing).
  • Fully compliant with flake8, black, and nox style standards.

Output Comparison:

  • Normal Execution: Outputs the exact same 360+ default domain CIDR blocks as the legacy tool.
  • Error Handling: Fixes a legacy bug where network/parsing failures caused an unhandled TypeError: unsupported operand type(s) for -: 'NoneType' and 'IPSet' crash; the new implementation exits cleanly with a descriptive ValueError.

@iennae

iennae commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Is this a sample or a tool that customers would use?

@ersin-ertan

Copy link
Copy Markdown
Author

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

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants