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: use quota_project_id field instead of quota_project #832

Merged
merged 7 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/auth/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface JWTInput {
client_id?: string;
client_secret?: string;
refresh_token?: string;
quota_project?: string;
quota_project_id?: string;
}

export interface CredentialBody {
Expand Down
2 changes: 1 addition & 1 deletion src/auth/jwtclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class JWT extends OAuth2Client {
this.key = json.private_key;
this.keyId = json.private_key_id;
this.projectId = json.project_id;
this.quotaProject = json.quota_project;
this.quotaProjectId = json.quota_project_id;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/auth/oauth2client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class OAuth2Client extends AuthClient {
private certificateCache: Certificates = {};
private certificateExpiry: Date | null = null;
private certificateCacheFormat: CertificateFormat = CertificateFormat.PEM;
protected quotaProject?: string;
protected quotaProjectId?: string;
protected refreshTokenPromises = new Map<string, Promise<GetTokenResponse>>();

// TODO: refactor tests to make this private
Expand Down Expand Up @@ -744,14 +744,14 @@ export class OAuth2Client extends AuthClient {
*/
async getRequestHeaders(url?: string): Promise<Headers> {
const headers = (await this.getRequestMetadataAsync(url)).headers;
// quota_project, stored in application_default_credentials.json, is set in
// quota_project_id, stored in application_default_credentials.json, is set in
// the x-goog-user-project header, to indicate an alternate account for
// billing and quota:
if (
!headers['x-goog-user-project'] && // don't override a value the user sets.
this.quotaProject
this.quotaProjectId
) {
headers['x-goog-user-project'] = this.quotaProject;
headers['x-goog-user-project'] = this.quotaProjectId;
}
return headers;
}
Expand Down
2 changes: 1 addition & 1 deletion src/auth/refreshclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class UserRefreshClient extends OAuth2Client {
this._clientSecret = json.client_secret;
this._refreshToken = json.refresh_token;
this.credentials.refresh_token = json.refresh_token;
this.quotaProject = json.quota_project;
this.quotaProjectId = json.quota_project_id;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"refresh_token": "refreshtoken",
"type": "authorized_user",
"project_id": "my-project",
"quota_project": "my-quota-project"
"quota_project_id": "my-quota-project"
}
2 changes: 1 addition & 1 deletion test/test.refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ it('fromStream should read the stream and create a UserRefreshClient', done => {
});
});

it('getRequestHeaders should populate x-goog-user-project header if quota_project present', async () => {
it('getRequestHeaders should populate x-goog-user-project header if quota_project_id present', async () => {
// The first time auth.getRequestHeaders() is called /token endpoint is used to
// fetch a JWT.
const req = nock('https://oauth2.googleapis.com')
Expand Down