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

feat: Support Not Requiring projectId When Not Required #1448

Merged
merged 4 commits into from
Aug 31, 2022

Conversation

danielbankhead
Copy link
Contributor

There are numerous cases where projectId isn't required to use GoogleAuth.

In fact, I'm failing to find a place where projectId is a hard requirement within the library (including sign, which erroneously requires it and will be removed in this pr: #1447).

Fixes #755 🦕

@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Aug 24, 2022
@danielbankhead
Copy link
Contributor Author

This PR should be followed-up with an issue for removing #getProjectIdOptional in favor of fixing & using getProjectId (with the corrected Promise<string | null>) in a future major release.

@danielbankhead danielbankhead added the owlbot:run Add this label to trigger the Owlbot post processor. label Aug 24, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Aug 24, 2022
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Aug 26, 2022
@danielbankhead danielbankhead marked this pull request as ready for review August 26, 2022 22:04
@danielbankhead danielbankhead requested review from a team as code owners August 26, 2022 22:04
Copy link

@ruyadorno ruyadorno left a comment

Choose a reason for hiding this comment

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

LGTM 👍 just a small suggestion

Comment on lines +214 to +215
e instanceof Error &&
e.message === GoogleAuthExceptionMessages.NO_PROJECT_ID_FOUND

Choose a reason for hiding this comment

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

checking for instanceof Error is quite redundant here, if it threw like an error and has a message property like an error, it's def going to be an error 😄

Suggested change
e instanceof Error &&
e.message === GoogleAuthExceptionMessages.NO_PROJECT_ID_FOUND
e.message === GoogleAuthExceptionMessages.NO_PROJECT_ID_FOUND

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understandable; the instanceof Error check is more-so a type assertion. By default, TS considers 'e' unknown

Comment on lines +209 to +222
async #getProjectIdOptional(): Promise<string | null> {
try {
return await this.getProjectId();
} catch (e) {
if (
e instanceof Error &&
e.message === GoogleAuthExceptionMessages.NO_PROJECT_ID_FOUND
) {
return null;
} else {
throw e;
}
}
}

Choose a reason for hiding this comment

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

Leveraging the Promises API (similar to the previous PR) 😄 might simplify it a bit here again:

Suggested change
async #getProjectIdOptional(): Promise<string | null> {
try {
return await this.getProjectId();
} catch (e) {
if (
e instanceof Error &&
e.message === GoogleAuthExceptionMessages.NO_PROJECT_ID_FOUND
) {
return null;
} else {
throw e;
}
}
}
#getProjectIdOptional(): Promise<string | null> {
return this.getProjectId()
.catch (e => {
if (e.message === GoogleAuthExceptionMessages.NO_PROJECT_ID_FOUND) {
return null;
} else {
throw e;
}
})
}

@danielbankhead danielbankhead merged commit b37489b into main Aug 31, 2022
@danielbankhead danielbankhead deleted the allow-missing-project-id branch August 31, 2022 16:54
gcf-merge-on-green bot pushed a commit that referenced this pull request Aug 31, 2022
🤖 I have created a release *beep* *boop*
---


## [8.5.0](v8.4.0...v8.5.0) (2022-08-31)


### Features

* Support Not Requiring `projectId` When Not Required ([#1448](#1448)) ([b37489b](b37489b))


### Bug Fixes

* add hashes to requirements.txt ([#1544](#1544)) ([#1449](#1449)) ([54afa8e](54afa8e))
* remove `projectId` check for `signBlob` calls ([6c04661](6c04661))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
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.

Requires projectId even when not used
4 participants