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: set x-goog-user-project header, with quota_project from default credentials #829

Merged
merged 3 commits into from Nov 20, 2019

Conversation

bcoe
Copy link
Contributor

@bcoe bcoe commented Nov 20, 2019

If the quota_project parameter is set, kicks it along in the request header x-goog-user-project.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 20, 2019
src/auth/googleauth.ts Outdated Show resolved Hide resolved
if (this.jsonContent && this.jsonContent.quota_project) {
headers = Object.assign({}, headers, {
'x-goog-user-project': this.jsonContent.quota_project,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment about why it's not the other way around, i.e.
Object.assign({}, ..., headers)

Copy link
Member

Choose a reason for hiding this comment

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

If client.getRequestHeaders() always returns an object, the whole Object.assign can be removed and replaced with a simple assignment :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tend to agree that headers should take precedence if set explicitly, I've updated the PR and added a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've noticed a few bugs in our auth library in my time working on it, caused by passing an object by reference and than modifying the object, e.g., deleting a key.

I've been being defensive by creating shallow copies with Object.assign({}), something worth thinking about in API design would be starting to Object.freeze objects that we don't wish for users to modify, at which point it forces people to make copies, but you can pass the object around if you do not need to mutate it.

@codecov
Copy link

codecov bot commented Nov 20, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@558677f). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #829   +/-   ##
=========================================
  Coverage          ?   84.93%           
=========================================
  Files             ?       17           
  Lines             ?      956           
  Branches          ?      214           
=========================================
  Hits              ?      812           
  Misses            ?       86           
  Partials          ?       58
Impacted Files Coverage Δ
src/auth/googleauth.ts 86.83% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 558677f...2b4c84f. Read the comment docs.

@bcoe bcoe merged commit 3240d16 into master Nov 20, 2019
@bcoe bcoe deleted the x-goog-user-project branch November 20, 2019 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants