cartography icon indicating copy to clipboard operation
cartography copied to clipboard

refactor(gcp): Migrate Storage module to google-cloud-storage SDK

Open Prachi194agrawal opened this issue 10 months ago • 2 comments

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.0 to pyproject.toml.
  • Code Refactor (storage.py):
    • Removed googleapiclient imports and logic.
    • Implemented get_gcp_buckets using storage.Client.
    • Added logic to manually map SDK objects back to the existing dictionary format (e.g., preserving camelCase keys like storageClass and iamConfiguration) to ensure backward compatibility with the Neo4j loader.
    • Added error handling for Forbidden and InvalidArgument exceptions specific to the new SDK.
  • Testing: Added a new unit test file tests/unit/cartography/intel/gcp/test_storage_sdk.py to verify success paths, error handling, and edge cases (minimal bucket data).

Testing Performed

  • Unit Tests: Verified all tests pass in test_storage_sdk.py.
Screenshot from 2026-01-17 23-45-31
  • Manual Sync: Verified against a GCP project (logs confirmed a successful gcp stage sync).

Screenshot from 2026-01-18 01-18-03

Prachi194agrawal avatar Jan 18 '26 18:01 Prachi194agrawal

Screenshot from 2026-01-20 15-16-40 Screenshot from 2026-01-20 15-16-13

Prachi194agrawal avatar Jan 20 '26 10:01 Prachi194agrawal

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 :)

jychp avatar Jan 25 '26 03:01 jychp