refactor(gcp): Migrate Storage module to google-cloud-storage SDK
Description
This PR migrates the GCP Storage module from the legacy googleapiclient (Discovery API) to the modern, official google-cloud-storage SDK. This change addresses issue #2233 and improves the resilience of GCP syncs.
Why is this change necessary?
The previous library lacked built-in retry logic for transient errors, often leading to failures when hitting API rate limits (429s) or server errors (5xx). The new SDK handles exponential backoff and retries automatically.
Key Changes
- Dependency Update: Added
google-cloud-storage>=2.0.0topyproject.toml. - Code Refactor (
storage.py):- Removed
googleapiclientimports and logic. - Implemented
get_gcp_bucketsusingstorage.Client. - Added logic to manually map SDK objects back to the existing dictionary format (e.g., preserving camelCase keys like
storageClassandiamConfiguration) to ensure backward compatibility with the Neo4j loader. - Added error handling for
ForbiddenandInvalidArgumentexceptions specific to the new SDK.
- Removed
- Testing: Added a new unit test file
tests/unit/cartography/intel/gcp/test_storage_sdk.pyto verify success paths, error handling, and edge cases (minimal bucket data).
Testing Performed
- Unit Tests: Verified all tests pass in
test_storage_sdk.py.
- Manual Sync: Verified against a GCP project (logs confirmed a successful
gcpstage sync).
Hi, thanks for your contribution.
As noted in the PR template, please provide test results from a real environment (screenshots of logs, the graph). Cartography is a tool used in production by many companies we can't accept contributions that haven't been tested.
Thanks for understanding :)