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

fix: Requests Respect config.projectIdRequired === false #753

Merged
merged 6 commits into from
Jun 21, 2022

Conversation

danielbankhead
Copy link
Contributor

Fixes #711 🦕

Important: Will need to port fix to https://github.com/googleapis/nodejs-storage/

@danielbankhead danielbankhead requested a review from a team as a code owner June 10, 2022 01:05
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Jun 10, 2022
src/util.ts Outdated
Comment on lines 680 to 685
projectId = await authClient.getProjectId();

authenticatedReqOpts = util.decorateRequest(
authenticatedReqOpts!,
projectId
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for the projectId as a fallback when it is not available to preserve existing behavior. Currently, consumers may not expect projectIdRequired to affect things at the request level - this is here to ensure backwards compatibility. Cases:

  • this block is not called (skips catch block): API is fully projectId-free.
  • this is called (is caught): since the projectId was not checked before, this preserves that call. Net = 0 new calls are made

onAuthenticated(null, authorizedReqOpts as DecorateRequestOptions);
})
.catch(onAuthenticated);
const prepareRequest = async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded this block for readability.

@danielbankhead danielbankhead changed the title fix: Respect config.projectIdRequired === false fix: Requests Respect config.projectIdRequired === false Jun 10, 2022
@ddelgrosso1
Copy link
Contributor

Overall I think the code changes look good. However, what is the plan for testing this as to not potentially impact consumers in case this causes unforeseen issues?

@danielbankhead
Copy link
Contributor Author

@ddelgrosso1 I think this is overall safe - here's an overview:

  • if projectIdRequired !== false, the codepaths are the same as before
  • if projectIdRequired === false it will attempt to use the default project id placeholder (which throws if a project id is required), and will fallback to checking for a project id (preserving existing behavior)

Additionally, all API calls are in the same order as before

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks for upstreaming this work @danielbankhead 👏

Will defer to @ddelgrosso1 for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regular GCS uploads are failing with "Unable to detect a Project Id in the current environment."
4 participants