Repository navigation
refactor(storage): revamp apiEndpoint handling, enforce uniform authentication, and use PassThroughClient for emulator - #9625
Open
thiyaguk09 wants to merge 8 commits into
Conversation
…API endpoint resolution
Contributor
There was a problem hiding this comment.
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.
thiyaguk09
marked this pull request as ready for review
October 15, 2026 09:05
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors
apiEndpointhandling in@google-cloud/storageto improve support for Trusted Partner Cloud (TPC) and Private Service Connect (PSC), enforce uniform authentication across all requests, and streamline emulator authentication.Changes
Remove Authentication Bypasses (
src/nodejs-common/util.ts,src/nodejs-common/service.ts,src/resumable-upload.ts)useAuthWithCustomEndpointandcustomEndpointproperties and configuration options acrossMakeAuthenticatedRequestFactoryConfig,ServiceConfig,ServiceOptions,Service,UploadConfig,Upload, andStorage.makeAuthenticatedRequestFactoryso all requests uniformly authenticate viaauthClient.authorizeRequest(reqOpts).Revamp
apiEndpointand AddgetEndpoint()(src/storage.ts,src/file.ts,src/signer.ts,src/transfer-manager.ts)apiEndpointvisibility onServiceandStoragefrompublictoprotected.async getEndpoint(): Promise<string>onStorage, which resolves the universe domain dynamically viaawait this.authClient.getUniverseDomain()when no customapiEndpointorSTORAGE_EMULATOR_HOSTwas configured at initialization, and returns the sanitized endpoint (https://storage.${universeDomain}).File#generateSignedPostPolicyV4to awaitthis.storage.getEndpoint().Streamline Emulator Authentication (
src/storage.ts)options.authClientto aPassThroughClientinstance fromgoogle-auth-librarywhenprocess.env.STORAGE_EMULATOR_HOSTis set and no customauthClientis provided.Tests (
test/index.ts,test/file.ts,test/nodejs-common/util.ts,test/resumable-upload.ts)customEndpointanduseAuthWithCustomEndpoint.Storageunit tests to mockGoogleAuth#getUniverseDomain()when testingawait storage.getEndpoint().PassThroughClientis used whenSTORAGE_EMULATOR_HOSTis set without an explicitauthClient.Fixes #7828