Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Revamp apiEndpoint #2400

Open
danielbankhead opened this issue Feb 8, 2024 · 1 comment
Open

refactor!: Revamp apiEndpoint #2400

danielbankhead opened this issue Feb 8, 2024 · 1 comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: cleanup An internal cleanup or hygiene concern.

Comments

@danielbankhead
Copy link
Contributor

danielbankhead commented Feb 8, 2024

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 apiEndpoint property private
  • remove the useAuthWithCustomEndpoint parameter/property
  • remove the internal customEndpoint parameter/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 via GoogleAuth#getUniverseDomain. This is a major convenience for TPC customers.
  • We can offer a predictable, secure experience by not disabling auth by default when an apiEndpoint has been provided
  • Classes will no longer have to distinguish between auth and non-auth contexts - we can simply use auth everywhere uniformly

Related:

We this change we can remove the following:

authClient: {
request: <T>(
opts: GaxiosOptions
) => Promise<GaxiosResponse<T>> | GaxiosPromise<T>;
};

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;
}
}

/**
* 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;

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);
}
};

@danielbankhead danielbankhead added type: cleanup An internal cleanup or hygiene concern. priority: p3 Desirable enhancement or fix. May not be included in next release. labels Feb 8, 2024
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Feb 8, 2024
@danielbankhead danielbankhead changed the title refactor!: Remove customEndpoint and useAuthWithCustomEndpoint Parameters refactor!: Revamp apiEndpoint Feb 8, 2024
@danielbankhead
Copy link
Contributor Author

Update: The PassThroughClient is available in Auth v9.7.0:

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 googleapis/nodejs-storage API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: cleanup An internal cleanup or hygiene concern.
Projects
None yet
Development

No branches or pull requests

1 participant