Add VPC sample for retrieving Google APIs and services IP ranges - #14496
Add VPC sample for retrieving Google APIs and services IP ranges#14496ersin-ertan wants to merge 1 commit into
Conversation
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
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.
09ecb18 to
98aea6a
Compare
ersin-ertan
left a comment
There was a problem hiding this comment.
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
pytestunit tests (8/8 passing). - Fully compliant with
flake8,black, andnoxstyle 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 descriptiveValueError.
|
Is this a sample or a tool that customers would use? |
|
Yes, hopefully replacing the sample at https://docs.cloud.google.com/vpc/docs/configure-private-google-access#ip-addr-defaults |
Adds
get_google_ip_rangesundervpc/as the modernized and hardened replacement for the archivednetworking-tools-python/tools/cidrtool. 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:urlopen(url, timeout=30)).pytestunit tests (8/8 passing).flake8,black, andnoxstyle standards. Output Comparison:TypeError: unsupported operand type(s) for -: 'NoneType' and 'IPSet'crash; the new implementation exits cleanly with a descriptiveValueError. Testing:python get_google_ip_ranges.pyagainst livegstatic.comendpoints.pytest -v(8/8 tests passing).flake8 .(0 errors) andblack --check .(clean).Description
Fixes #
Checklist
Testing
Compliance & Style
Post-Approval Actions