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

Commit

Permalink
feat: support apiEndpoint override
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Jun 7, 2019
1 parent e884c92 commit 951ece1
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"predocs-test": "npm run docs"
},
"dependencies": {
"@google-cloud/common": "^1.0.0",
"@google-cloud/common": "^2.0.0",
"@google-cloud/paginator": "^1.0.0",
"@google-cloud/projectify": "^1.0.0",
"@google-cloud/promisify": "^1.0.0",
Expand All @@ -54,15 +54,15 @@
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-node": "^9.0.0",
"eslint-plugin-prettier": "^3.0.0",
"jsdoc-baseline": "^0.1.0",
"intelli-espower-loader": "^1.0.1",
"jsdoc": "^3.6.2",
"jsdoc-baseline": "^0.1.0",
"linkinator": "^1.4.2",
"mocha": "^6.0.0",
"nyc": "^14.0.0",
"power-assert": "^1.5.0",
"prettier": "^1.13.5",
"proxyquire": "^2.0.1",
"uuid": "^3.2.1",
"linkinator": "^1.1.2"
"uuid": "^3.2.1"
}
}
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +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`
*/
/**
* @see [What is Google Compute Engine?]{@link https://cloud.google.com/compute/docs}
Expand All @@ -78,10 +79,11 @@ const Image = require('./image.js');
* });
*/
class Compute extends common.Service {
constructor(options) {
options = options || {};
constructor(options = {}) {
options.apiEndpoint = options.apiEndpoint || 'www.googleapis.com';
const config = {
baseUrl: 'https://www.googleapis.com/compute/v1',
apiEndpoint: options.apiEndpoint,
baseUrl: `https://${options.apiEndpoint}/compute/v1`,
scopes: ['https://www.googleapis.com/auth/compute'],
packageJson: require('../package.json'),
};
Expand Down
2 changes: 1 addition & 1 deletion src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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://www.googleapis.com/compute/v1',
baseUrl: `https://${this.compute.apiEndpoint}/compute/v1`,
p: this.parent.projectId,
z: group.zone.name || group.zone,
n: group.name,
Expand Down
8 changes: 5 additions & 3 deletions src/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ class Snapshot extends common.ServiceObject {
*/
getMetadata: true,
};
const compute = isDisk ? scope.zone.compute : scope;
const config = {
parent: scope,
baseUrl:
'https://www.googleapis.com/compute/v1/projects/{{projectId}}/global/snapshots',
baseUrl: `https://${
compute.apiEndpoint
}/compute/v1/projects/{{projectId}}/global/snapshots`,
/**
* @name Snapshot#id
* @type {string}
Expand Down Expand Up @@ -174,7 +176,7 @@ class Snapshot extends common.ServiceObject {
* @name Snapshot#compute
* @type {Compute}
*/
this.compute = isDisk ? scope.zone.compute : scope;
this.compute = compute;
/**
* @name Snapshot#name
* @type {string}
Expand Down
4 changes: 2 additions & 2 deletions src/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class VM extends common.ServiceObject {
this.hasActiveWaiters = false;
this.waiters = [];
this.url = format('{base}/{project}/zones/{zone}/instances/{name}', {
base: 'https://www.googleapis.com/compute/v1/projects',
base: `https://${this.zone.compute.apiEndpoint}/compute/v1/projects`,
project: zone.compute.projectId,
zone: zone.name,
name: this.name,
Expand Down Expand Up @@ -422,7 +422,7 @@ class VM extends common.ServiceObject {
}
const diskName = replaceProjectIdToken(disk.formattedName, projectId);
let deviceName;
const baseUrl = 'https://www.googleapis.com/compute/v1/';
const baseUrl = `https://${self.zone.compute.apiEndpoint}/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.
Expand Down
1 change: 1 addition & 0 deletions test/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('Service', function() {
const COMPUTE = {
projectId: 'project-id',
createService: util.noop,
apiEndpoint: 'www.googleapis.com',
};

before(function() {
Expand Down
4 changes: 3 additions & 1 deletion test/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ describe('Snapshot', function() {
let Snapshot;
let snapshot;

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

before(function() {
Expand Down
1 change: 1 addition & 0 deletions test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('VM', function() {
},
},
projectId: 'project-id',
apiEndpoint: 'www.googleapis.com',
};
const ZONE = {
compute: COMPUTE,
Expand Down

0 comments on commit 951ece1

Please sign in to comment.