From 4ad52a301d844252bcd6c6a3577c8520c027e643 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Tue, 10 Sep 2019 12:17:49 -0700 Subject: [PATCH] fix: update root url to `compute.googleapis.com` (#349) --- src/index.js | 4 ++-- src/service.js | 15 +++++++++------ src/vm.js | 19 +++++++++++-------- test/index.js | 2 +- test/service.js | 2 +- test/snapshot.js | 4 ++-- test/vm.js | 2 +- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/index.js b/src/index.js index 7d3557ce..b639112c 100644 --- a/src/index.js +++ b/src/index.js @@ -58,7 +58,7 @@ const Image = require('./image.js'); * attempted before returning the error. * @property {Constructor} [promise] Custom promise module to use instead of * native Promises. - * @property {string} [apiEndpoint] The API endpoint of the service used to make requests. Defaults to `www.googleapis.com` + * @property {string} [apiEndpoint] The API endpoint of the service used to make requests. Defaults to `compute.googleapis.com` */ /** * @see [What is Google Compute Engine?]{@link https://cloud.google.com/compute/docs} @@ -80,7 +80,7 @@ const Image = require('./image.js'); */ class Compute extends common.Service { constructor(options = {}) { - options.apiEndpoint = options.apiEndpoint || 'www.googleapis.com'; + options.apiEndpoint = options.apiEndpoint || 'compute.googleapis.com'; const config = { apiEndpoint: options.apiEndpoint, baseUrl: `https://${options.apiEndpoint}/compute/v1`, diff --git a/src/service.js b/src/service.js index e1a281eb..ba075686 100644 --- a/src/service.js +++ b/src/service.js @@ -285,12 +285,15 @@ class Service extends common.ServiceObject { */ getHealth(group, callback) { if (!is.string(group)) { - group = format('{baseUrl}/projects/{p}/zones/{z}/instanceGroups/{n}', { - baseUrl: `https://${this.compute.apiEndpoint}/compute/v1`, - p: this.parent.projectId, - z: group.zone.name || group.zone, - n: group.name, - }); + group = format( + '{resourceBaseUrl}/projects/{p}/zones/{z}/instanceGroups/{n}', + { + resourceBaseUrl: `https://www.googleapis.com/compute/v1`, + p: this.parent.projectId, + z: group.zone.name || group.zone, + n: group.name, + } + ); } this.request( { diff --git a/src/vm.js b/src/vm.js index 1bf1d8f8..3c79e486 100644 --- a/src/vm.js +++ b/src/vm.js @@ -248,12 +248,15 @@ class VM extends common.ServiceObject { this.zone = zone; this.hasActiveWaiters = false; this.waiters = []; - this.url = format('{base}/{project}/zones/{zone}/instances/{name}', { - base: `https://${this.zone.compute.apiEndpoint}/compute/v1/projects`, - project: zone.compute.projectId, - zone: zone.name, - name: this.name, - }); + this.url = format( + '{resourceBaseUrl}/{project}/zones/{zone}/instances/{name}', + { + resourceBaseUrl: `https://www.googleapis.com/compute/v1/projects`, + project: zone.compute.projectId, + zone: zone.name, + name: this.name, + } + ); } /** * Attach a disk to the instance. @@ -431,13 +434,13 @@ class VM extends common.ServiceObject { } const diskName = replaceProjectIdToken(disk.formattedName, projectId); let deviceName; - const baseUrl = `https://${self.zone.compute.apiEndpoint}/compute/v1/`; + const resourceBaseUrl = `https://www.googleapis.com/compute/v1/`; const disks = metadata.disks || []; // Try to find the deviceName by matching the source of the attached disks // to the name of the disk provided by the user. for (let i = 0; !deviceName && i < disks.length; i++) { const attachedDisk = disks[i]; - const source = attachedDisk.source.replace(baseUrl, ''); + const source = attachedDisk.source.replace(resourceBaseUrl, ''); if (source === diskName) { deviceName = attachedDisk.deviceName; } diff --git a/test/index.js b/test/index.js index a4be715a..169576c2 100644 --- a/test/index.js +++ b/test/index.js @@ -213,7 +213,7 @@ describe('Compute', function() { const calledWith = compute.calledWith_[0]; - const baseUrl = 'https://www.googleapis.com/compute/v1'; + const baseUrl = 'https://compute.googleapis.com/compute/v1'; assert.strictEqual(calledWith.baseUrl, baseUrl); assert.deepStrictEqual(calledWith.scopes, [ 'https://www.googleapis.com/auth/compute', diff --git a/test/service.js b/test/service.js index 845648cc..75fa7bab 100644 --- a/test/service.js +++ b/test/service.js @@ -46,7 +46,7 @@ describe('Service', function() { const COMPUTE = { projectId: 'project-id', createService: util.noop, - apiEndpoint: 'www.googleapis.com', + apiEndpoint: 'compute.googleapis.com', }; before(function() { diff --git a/test/snapshot.js b/test/snapshot.js index e5dc912e..e098ff00 100644 --- a/test/snapshot.js +++ b/test/snapshot.js @@ -42,7 +42,7 @@ describe('Snapshot', function() { let snapshot; const COMPUTE = { - apiEndpoint: 'www.googleapis.com', + apiEndpoint: 'compute.googleapis.com', }; const SNAPSHOT_NAME = 'snapshot-name'; @@ -74,7 +74,7 @@ describe('Snapshot', function() { assert.strictEqual(calledWith.parent, COMPUTE); assert.strictEqual( calledWith.baseUrl, - 'https://www.googleapis.com/compute/v1/projects/{{projectId}}/global/snapshots' + 'https://compute.googleapis.com/compute/v1/projects/{{projectId}}/global/snapshots' ); assert.strictEqual(calledWith.id, SNAPSHOT_NAME); assert.deepStrictEqual(calledWith.methods, { diff --git a/test/vm.js b/test/vm.js index 54280225..8c34a1e9 100644 --- a/test/vm.js +++ b/test/vm.js @@ -62,7 +62,7 @@ describe('VM', function() { }, }, projectId: 'project-id', - apiEndpoint: 'www.googleapis.com', + apiEndpoint: 'compute.googleapis.com', }; const ZONE = { compute: COMPUTE,