Skip to content

refactor(storage): revamp apiEndpoint handling, enforce uniform authentication, and use PassThroughClient for emulator - #9625

Open
thiyaguk09 wants to merge 8 commits into
googleapis:mainfrom
thiyaguk09:7828-refactor-revamp-apiendpoint
Open

thiyaguk09 wants to merge 8 commits into
googleapis:mainfrom
thiyaguk09:7828-refactor-revamp-apiendpoint

Conversation

@thiyaguk09

Copy link
Copy Markdown
Contributor

Summary

Refactors apiEndpoint handling in @google-cloud/storage to improve support for Trusted Partner Cloud (TPC) and Private Service Connect (PSC), enforce uniform authentication across all requests, and streamline emulator authentication.

Changes

  1. Remove Authentication Bypasses (src/nodejs-common/util.ts, src/nodejs-common/service.ts, src/resumable-upload.ts)

    • Removed the useAuthWithCustomEndpoint and customEndpoint properties and configuration options across MakeAuthenticatedRequestFactoryConfig, ServiceConfig, ServiceOptions, Service, UploadConfig, Upload, and Storage.
    • Removed the conditional bypass in makeAuthenticatedRequestFactory so all requests uniformly authenticate via authClient.authorizeRequest(reqOpts).
  2. Revamp apiEndpoint and Add getEndpoint() (src/storage.ts, src/file.ts, src/signer.ts, src/transfer-manager.ts)

    • Changed apiEndpoint visibility on Service and Storage from public to protected.
    • Added async getEndpoint(): Promise<string> on Storage, which resolves the universe domain dynamically via await this.authClient.getUniverseDomain() when no custom apiEndpoint or STORAGE_EMULATOR_HOST was configured at initialization, and returns the sanitized endpoint (https://storage.${universeDomain}).
    • Updated File#generateSignedPostPolicyV4 to await this.storage.getEndpoint().
  3. Streamline Emulator Authentication (src/storage.ts)

    • Defaulted options.authClient to a PassThroughClient instance from google-auth-library when process.env.STORAGE_EMULATOR_HOST is set and no custom authClient is provided.
  4. Tests (test/index.ts, test/file.ts, test/nodejs-common/util.ts, test/resumable-upload.ts)

    • Removed obsolete unit tests for customEndpoint and useAuthWithCustomEndpoint.
    • Updated Storage unit tests to mock GoogleAuth#getUniverseDomain() when testing await storage.getEndpoint().
    • Added unit test verifying PassThroughClient is used when STORAGE_EMULATOR_HOST is set without an explicit authClient.

Fixes #7828

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Oct 14, 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 refactors the storage service's endpoint management by removing explicit customEndpoint and useAuthWithCustomEndpoint flags in favor of a more dynamic getEndpoint() method. This change allows for better handling of universe domains and custom endpoints. My review identified several areas for improvement: adding defensive checks when calling getUniverseDomain to prevent runtime errors, ensuring that getEndpoint() is awaited in the URLSigner to maintain correct domain resolution in TPC/PSC environments, and improving test robustness by ensuring stubs are restored in finally blocks to avoid test pollution.

Comment thread handwritten/storage/src/storage.ts
Comment thread handwritten/storage/src/signer.ts
Comment thread handwritten/storage/src/signer.ts Outdated
Comment thread handwritten/storage/test/index.ts
@thiyaguk09
thiyaguk09 marked this pull request as ready for review October 15, 2026 09:05
@thiyaguk09
thiyaguk09 requested review from a team as code owners October 15, 2026 09:05

This branch has not been deployed

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

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor!: Revamp apiEndpoint

1 participant