Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix: update root url to compute.googleapis.com (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and bcoe committed Sep 10, 2019
1 parent 6f87a3b commit 4ad52a3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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`,
Expand Down
15 changes: 9 additions & 6 deletions src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
19 changes: 11 additions & 8 deletions src/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions test/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Snapshot', function() {
let snapshot;

const COMPUTE = {
apiEndpoint: 'www.googleapis.com',
apiEndpoint: 'compute.googleapis.com',
};
const SNAPSHOT_NAME = 'snapshot-name';

Expand Down Expand Up @@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('VM', function() {
},
},
projectId: 'project-id',
apiEndpoint: 'www.googleapis.com',
apiEndpoint: 'compute.googleapis.com',
};
const ZONE = {
compute: COMPUTE,
Expand Down

0 comments on commit 4ad52a3

Please sign in to comment.