From 2725bef829b3d857e364f55c130d49e39912b8c4 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Fri, 6 Sep 2019 11:14:05 -0700 Subject: [PATCH 1/7] fix: update root url to `compute.googleapis.com` --- src/index.js | 4 ++-- src/zone.js | 2 +- system-test/compute.js | 12 +++++++----- test/index.js | 2 +- test/service.js | 6 +++--- test/snapshot.js | 4 ++-- test/vm.js | 4 ++-- 7 files changed, 18 insertions(+), 16 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/zone.js b/src/zone.js index afec0987..d42ea6ca 100644 --- a/src/zone.js +++ b/src/zone.js @@ -540,7 +540,7 @@ class Zone extends common.ServiceObject { * boot: true, * initializeParams: { * sourceImage: - * 'https://www.googleapis.com/compute/v1/projects' + + * 'https://compute.googleapis.com/compute/v1/projects' + * '/debian-cloud/global/images/debian-7-wheezy-v20150710' * } * } diff --git a/system-test/compute.js b/system-test/compute.js index 400623df..4563342d 100644 --- a/system-test/compute.js +++ b/system-test/compute.js @@ -108,7 +108,7 @@ describe('Compute', () => { await createInstanceGroupManager( INSTANCE_GROUP_MANAGER_NAME, [ - 'https://www.googleapis.com/compute/v1/projects', + 'https://compute.googleapis.com/compute/v1/projects', compute.projectId, 'global/instanceTemplates', INSTANCE_TEMPLATE_NAME, @@ -729,7 +729,7 @@ describe('Compute', () => { it('should have created the right rule', async () => { const target = [ - 'https://www.googleapis.com/compute/v1/global/targetHttpProxies/', + 'https://compute.googleapis.com/compute/v1/global/targetHttpProxies/', TARGET_PROXY_NAME, ].join(''); @@ -746,7 +746,8 @@ describe('Compute', () => { it('should set a new target', async () => { let target = [ - 'https://www.googleapis.com/compute/v1/projects/' + compute.projectId, + 'https://compute.googleapis.com/compute/v1/projects/' + + compute.projectId, '/global/targetHttpProxies/' + TARGET_PROXY_NAME, ].join(''); @@ -789,7 +790,8 @@ describe('Compute', () => { it('should have created the right rule', async () => { let target = [ - 'https://www.googleapis.com/compute/v1/projects/' + compute.projectId, + 'https://compute.googleapis.com/compute/v1/projects/' + + compute.projectId, '/zones/' + zone.name + '/targetInstances/' + TARGET_INSTANCE_NAME, ].join(''); @@ -998,7 +1000,7 @@ describe('Compute', () => { await vm.resize(machineType); const [metadata] = await vm.getMetadata(); const expectedMachineType = [ - 'https://www.googleapis.com/compute/v1', + 'https://compute.googleapis.com/compute/v1', 'zones', zone.id, 'machineTypes', 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..c34cacbe 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() { @@ -204,7 +204,7 @@ describe('Service', function() { service.request = function(reqOpts) { assert.deepStrictEqual(reqOpts.json, { group: [ - 'https://www.googleapis.com/compute/v1/projects/', + 'https://compute.googleapis.com/compute/v1/projects/', COMPUTE.projectId, '/zones/', group.zone, @@ -231,7 +231,7 @@ describe('Service', function() { service.request = function(reqOpts) { assert.deepStrictEqual(reqOpts.json, { group: [ - 'https://www.googleapis.com/compute/v1/projects/', + 'https://compute.googleapis.com/compute/v1/projects/', COMPUTE.projectId, '/zones/', group.zone.name, 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..ab50a944 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, @@ -125,7 +125,7 @@ describe('VM', function() { assert.strictEqual( vm.url, [ - 'https://www.googleapis.com/compute/v1/projects', + 'https://compute.googleapis.com/compute/v1/projects', COMPUTE.projectId, 'zones', ZONE.name, From 1be2122df3265bcc0d0c0b8c8e9133bf49e9eb2c Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Mon, 9 Sep 2019 15:28:04 -0700 Subject: [PATCH 2/7] chore: fix up resource names --- src/zone.js | 2 +- system-test/compute.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/zone.js b/src/zone.js index d42ea6ca..afec0987 100644 --- a/src/zone.js +++ b/src/zone.js @@ -540,7 +540,7 @@ class Zone extends common.ServiceObject { * boot: true, * initializeParams: { * sourceImage: - * 'https://compute.googleapis.com/compute/v1/projects' + + * 'https://www.googleapis.com/compute/v1/projects' + * '/debian-cloud/global/images/debian-7-wheezy-v20150710' * } * } diff --git a/system-test/compute.js b/system-test/compute.js index 4563342d..b448b36a 100644 --- a/system-test/compute.js +++ b/system-test/compute.js @@ -108,7 +108,7 @@ describe('Compute', () => { await createInstanceGroupManager( INSTANCE_GROUP_MANAGER_NAME, [ - 'https://compute.googleapis.com/compute/v1/projects', + 'https://www.googleapis.com/compute/v1/projects', compute.projectId, 'global/instanceTemplates', INSTANCE_TEMPLATE_NAME, @@ -729,7 +729,7 @@ describe('Compute', () => { it('should have created the right rule', async () => { const target = [ - 'https://compute.googleapis.com/compute/v1/global/targetHttpProxies/', + 'https://www.googleapis.com/compute/v1/global/targetHttpProxies/', TARGET_PROXY_NAME, ].join(''); @@ -746,7 +746,7 @@ describe('Compute', () => { it('should set a new target', async () => { let target = [ - 'https://compute.googleapis.com/compute/v1/projects/' + + 'https://www.googleapis.com/compute/v1/projects/' + compute.projectId, '/global/targetHttpProxies/' + TARGET_PROXY_NAME, ].join(''); @@ -790,7 +790,7 @@ describe('Compute', () => { it('should have created the right rule', async () => { let target = [ - 'https://compute.googleapis.com/compute/v1/projects/' + + 'https://www.googleapis.com/compute/v1/projects/' + compute.projectId, '/zones/' + zone.name + '/targetInstances/' + TARGET_INSTANCE_NAME, ].join(''); @@ -1000,7 +1000,7 @@ describe('Compute', () => { await vm.resize(machineType); const [metadata] = await vm.getMetadata(); const expectedMachineType = [ - 'https://compute.googleapis.com/compute/v1', + 'https://www.googleapis.com/compute/v1', 'zones', zone.id, 'machineTypes', From f705867ac05e2a1cb0aed215094b663950be0e90 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Mon, 9 Sep 2019 15:29:27 -0700 Subject: [PATCH 3/7] chore: fix linting --- src/snapshot.js | 4 +++- system-test/compute.js | 6 ++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/snapshot.js b/src/snapshot.js index 9d700a5c..36a6bb8d 100644 --- a/src/snapshot.js +++ b/src/snapshot.js @@ -127,7 +127,9 @@ class Snapshot extends common.ServiceObject { const compute = isDisk ? scope.zone.compute : scope; const config = { parent: scope, - baseUrl: `https://${compute.apiEndpoint}/compute/v1/projects/{{projectId}}/global/snapshots`, + baseUrl: `https://${ + compute.apiEndpoint + }/compute/v1/projects/{{projectId}}/global/snapshots`, /** * @name Snapshot#id * @type {string} diff --git a/system-test/compute.js b/system-test/compute.js index b448b36a..400623df 100644 --- a/system-test/compute.js +++ b/system-test/compute.js @@ -746,8 +746,7 @@ describe('Compute', () => { it('should set a new target', async () => { let target = [ - 'https://www.googleapis.com/compute/v1/projects/' + - compute.projectId, + 'https://www.googleapis.com/compute/v1/projects/' + compute.projectId, '/global/targetHttpProxies/' + TARGET_PROXY_NAME, ].join(''); @@ -790,8 +789,7 @@ describe('Compute', () => { it('should have created the right rule', async () => { let target = [ - 'https://www.googleapis.com/compute/v1/projects/' + - compute.projectId, + 'https://www.googleapis.com/compute/v1/projects/' + compute.projectId, '/zones/' + zone.name + '/targetInstances/' + TARGET_INSTANCE_NAME, ].join(''); From aa4ee5f087f9455091db756530ca68162e38579d Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Mon, 9 Sep 2019 15:35:12 -0700 Subject: [PATCH 4/7] chore: fix linting --- src/snapshot.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/snapshot.js b/src/snapshot.js index 36a6bb8d..9d700a5c 100644 --- a/src/snapshot.js +++ b/src/snapshot.js @@ -127,9 +127,7 @@ class Snapshot extends common.ServiceObject { const compute = isDisk ? scope.zone.compute : scope; const config = { parent: scope, - baseUrl: `https://${ - compute.apiEndpoint - }/compute/v1/projects/{{projectId}}/global/snapshots`, + baseUrl: `https://${compute.apiEndpoint}/compute/v1/projects/{{projectId}}/global/snapshots`, /** * @name Snapshot#id * @type {string} From 2aef130655b887aad8ccb7d7e70913fb8d71c051 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Tue, 10 Sep 2019 10:55:17 -0700 Subject: [PATCH 5/7] chore: fix up groups --- src/service.js | 2 +- src/vm.js | 4 ++-- test/service.js | 4 ++-- test/vm.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/service.js b/src/service.js index e1a281eb..02cb191b 100644 --- a/src/service.js +++ b/src/service.js @@ -286,7 +286,7 @@ 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`, + baseUrl: `https://www.googleapis.com/compute/v1`, p: this.parent.projectId, z: group.zone.name || group.zone, n: group.name, diff --git a/src/vm.js b/src/vm.js index 1bf1d8f8..097708eb 100644 --- a/src/vm.js +++ b/src/vm.js @@ -249,7 +249,7 @@ class VM extends common.ServiceObject { this.hasActiveWaiters = false; this.waiters = []; this.url = format('{base}/{project}/zones/{zone}/instances/{name}', { - base: `https://${this.zone.compute.apiEndpoint}/compute/v1/projects`, + base: `https://www.googleapis.com/compute/v1/projects`, project: zone.compute.projectId, zone: zone.name, name: this.name, @@ -431,7 +431,7 @@ class VM extends common.ServiceObject { } const diskName = replaceProjectIdToken(disk.formattedName, projectId); let deviceName; - const baseUrl = `https://${self.zone.compute.apiEndpoint}/compute/v1/`; + const baseUrl = `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. diff --git a/test/service.js b/test/service.js index c34cacbe..75fa7bab 100644 --- a/test/service.js +++ b/test/service.js @@ -204,7 +204,7 @@ describe('Service', function() { service.request = function(reqOpts) { assert.deepStrictEqual(reqOpts.json, { group: [ - 'https://compute.googleapis.com/compute/v1/projects/', + 'https://www.googleapis.com/compute/v1/projects/', COMPUTE.projectId, '/zones/', group.zone, @@ -231,7 +231,7 @@ describe('Service', function() { service.request = function(reqOpts) { assert.deepStrictEqual(reqOpts.json, { group: [ - 'https://compute.googleapis.com/compute/v1/projects/', + 'https://www.googleapis.com/compute/v1/projects/', COMPUTE.projectId, '/zones/', group.zone.name, diff --git a/test/vm.js b/test/vm.js index ab50a944..8c34a1e9 100644 --- a/test/vm.js +++ b/test/vm.js @@ -125,7 +125,7 @@ describe('VM', function() { assert.strictEqual( vm.url, [ - 'https://compute.googleapis.com/compute/v1/projects', + 'https://www.googleapis.com/compute/v1/projects', COMPUTE.projectId, 'zones', ZONE.name, From 7e17f61a6a883b5d24d461ba1671133b99c795fe Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Tue, 10 Sep 2019 11:28:28 -0700 Subject: [PATCH 6/7] chore: differentiate baseUrl from resourceBaseUrl --- src/service.js | 4 ++-- src/vm.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/service.js b/src/service.js index 02cb191b..07d3a1b2 100644 --- a/src/service.js +++ b/src/service.js @@ -285,8 +285,8 @@ class Service extends common.ServiceObject { */ getHealth(group, callback) { if (!is.string(group)) { - group = format('{baseUrl}/projects/{p}/zones/{z}/instanceGroups/{n}', { - baseUrl: `https://www.googleapis.com/compute/v1`, + 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, diff --git a/src/vm.js b/src/vm.js index 097708eb..8045eae2 100644 --- a/src/vm.js +++ b/src/vm.js @@ -248,8 +248,8 @@ class VM extends common.ServiceObject { this.zone = zone; this.hasActiveWaiters = false; this.waiters = []; - this.url = format('{base}/{project}/zones/{zone}/instances/{name}', { - base: `https://www.googleapis.com/compute/v1/projects`, + 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, @@ -431,13 +431,13 @@ class VM extends common.ServiceObject { } const diskName = replaceProjectIdToken(disk.formattedName, projectId); let deviceName; - const baseUrl = `https://www.googleapis.com/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; } From 817bf2ee6505479fe739ec92e6df784deaa81dc6 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Tue, 10 Sep 2019 11:45:18 -0700 Subject: [PATCH 7/7] chore: fix linting --- src/service.js | 15 +++++++++------ src/vm.js | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/service.js b/src/service.js index 07d3a1b2..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('{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, - }); + 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 8045eae2..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('{resourceBaseUrl}/{project}/zones/{zone}/instances/{name}', { - resourceBaseUrl: `https://www.googleapis.com/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.