From 8933966659f3b07f5454a2756fa52d92fea147d2 Mon Sep 17 00:00:00 2001 From: Chris Broadfoot Date: Mon, 25 Nov 2019 12:52:30 -0500 Subject: [PATCH] fix: use quota_project_id field instead of quota_project (#832) --- src/auth/credentials.ts | 2 +- src/auth/jwtclient.ts | 2 +- src/auth/oauth2client.ts | 8 ++++---- src/auth/refreshclient.ts | 2 +- .../.config/gcloud/application_default_credentials.json | 2 +- test/test.refresh.ts | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/auth/credentials.ts b/src/auth/credentials.ts index 94c01625..a9ee2e19 100644 --- a/src/auth/credentials.ts +++ b/src/auth/credentials.ts @@ -37,7 +37,7 @@ export interface JWTInput { client_id?: string; client_secret?: string; refresh_token?: string; - quota_project?: string; + quota_project_id?: string; } export interface CredentialBody { diff --git a/src/auth/jwtclient.ts b/src/auth/jwtclient.ts index 41a18e6d..a2153a27 100644 --- a/src/auth/jwtclient.ts +++ b/src/auth/jwtclient.ts @@ -265,7 +265,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; } /** diff --git a/src/auth/oauth2client.ts b/src/auth/oauth2client.ts index a1f3b22b..31af6a9c 100644 --- a/src/auth/oauth2client.ts +++ b/src/auth/oauth2client.ts @@ -365,7 +365,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>(); // TODO: refactor tests to make this private @@ -742,14 +742,14 @@ export class OAuth2Client extends AuthClient { */ async getRequestHeaders(url?: string): Promise { 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; } diff --git a/src/auth/refreshclient.ts b/src/auth/refreshclient.ts index 4e0f7521..7175f098 100644 --- a/src/auth/refreshclient.ts +++ b/src/auth/refreshclient.ts @@ -115,7 +115,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; } /** diff --git a/test/fixtures/config-with-quota/.config/gcloud/application_default_credentials.json b/test/fixtures/config-with-quota/.config/gcloud/application_default_credentials.json index 36144859..1aa818da 100644 --- a/test/fixtures/config-with-quota/.config/gcloud/application_default_credentials.json +++ b/test/fixtures/config-with-quota/.config/gcloud/application_default_credentials.json @@ -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" } diff --git a/test/test.refresh.ts b/test/test.refresh.ts index e08b68df..9a5fcb1c 100644 --- a/test/test.refresh.ts +++ b/test/test.refresh.ts @@ -123,7 +123,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')