-
Notifications
You must be signed in to change notification settings - Fork 395
refactor!: Revamp apiEndpoint #2400
Description
With the advent of TPC and PSC, there’s a lot of complexity with apiEndpoints. To improve, we should:
- expose an
async Storage#getEndpoint()method - make the
apiEndpointproperty private - remove the
useAuthWithCustomEndpointparameter/property - remove the internal
customEndpointparameter/property
Additionally, if STORAGE_EMULATOR_HOST is detected and used the PassThrough AuthClient should be used by default (which can be overwritten via the existing authClient parameter) - removing the need for the useAuthWithCustomEndpoint parameter.
This will greatly clean-up the code base as:
- Customers will not be required to manually provide the
universeDomain- as we can determine it asynchronously viaGoogleAuth#getUniverseDomain. This is a major convenience for TPC customers. - We can offer a predictable, secure experience by not disabling auth by default when an
apiEndpointhas been provided - Classes will no longer have to distinguish between auth and non-auth contexts - we can simply use
autheverywhere uniformly
Related:
- https://github.com/googleapis/nodejs-common/issues/821
- feat!: Align Support for Storage Emulation #2092
- feat:
PassThroughAuthClient google-auth-library-nodejs#1771
We this change we can remove the following:
nodejs-storage/src/resumable-upload.ts
Lines 284 to 288 in 755c9c2
| authClient: { | |
| request: <T>( | |
| opts: GaxiosOptions | |
| ) => Promise<GaxiosResponse<T>> | GaxiosPromise<T>; | |
| }; |
nodejs-storage/src/resumable-upload.ts
Lines 370 to 398 in fcf3b6c
| this.apiEndpoint = `https://storage.${universe}`; | |
| if (cfg.apiEndpoint && cfg.apiEndpoint !== this.apiEndpoint) { | |
| this.apiEndpoint = this.sanitizeEndpoint(cfg.apiEndpoint); | |
| const hostname = new URL(this.apiEndpoint).hostname; | |
| // check if it is a domain of a known universe | |
| const isDomain = hostname === universe; | |
| const isDefaultUniverseDomain = hostname === DEFAULT_UNIVERSE; | |
| // check if it is a subdomain of a known universe | |
| // by checking a last (universe's length + 1) of a hostname | |
| const isSubDomainOfUniverse = | |
| hostname.slice(-(universe.length + 1)) === `.${universe}`; | |
| const isSubDomainOfDefaultUniverse = | |
| hostname.slice(-(DEFAULT_UNIVERSE.length + 1)) === | |
| `.${DEFAULT_UNIVERSE}`; | |
| if ( | |
| !isDomain && | |
| !isDefaultUniverseDomain && | |
| !isSubDomainOfUniverse && | |
| !isSubDomainOfDefaultUniverse | |
| ) { | |
| // a custom, non-universe domain, | |
| // use gaxios | |
| this.authClient = gaxios; | |
| } | |
| } |
nodejs-storage/src/nodejs-common/util.ts
Lines 157 to 165 in 755c9c2
| /** | |
| * If true, just return the provided request options. Default: false. | |
| */ | |
| customEndpoint?: boolean; | |
| /** | |
| * If true, will authenticate when using a custom endpoint. Default: false. | |
| */ | |
| useAuthWithCustomEndpoint?: boolean; |
nodejs-storage/src/nodejs-common/util.ts
Lines 798 to 809 in 755c9c2
| const authorizeRequest = async () => { | |
| if ( | |
| reqConfig.customEndpoint && | |
| !reqConfig.useAuthWithCustomEndpoint | |
| ) { | |
| // Using a custom API override. Do not use `google-auth-library` for | |
| // authentication. (ex: connecting to a local Datastore server) | |
| return reqOpts; | |
| } else { | |
| return authClient.authorizeRequest(reqOpts); | |
| } | |
| }; |