From f68653f75e0c0510856064d01c19fe0313e4fff3 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 29 May 2019 15:18:20 -0700 Subject: [PATCH 1/2] feat: support apiEndpoint overrides --- package.json | 2 +- src/index.ts | 15 ++++++++++++--- test/index.ts | 12 ++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 0194380..25eb078 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,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/promisify": "^1.0.0", "arrify": "^2.0.0", diff --git a/src/index.ts b/src/index.ts index a90f10a..5b7743f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,6 +59,14 @@ export interface CreateZoneRequest { export type CreateZoneResponse = [Zone, Metadata]; +export interface DNSOptions extends GoogleAuthOptions { + /** + * The API endpoint of the service used to make requests. + * Defaults to `www.googleapis.com`. + */ + apiEndpoint?: string; +} + /** * @typedef {object} ClientConfig * @property {string} [projectId] The project ID from the Google Developer's @@ -118,10 +126,11 @@ export type CreateZoneResponse = [Zone, Metadata]; */ class DNS extends Service { getZonesStream: (query: GetZonesRequest) => Stream; - constructor(options?: GoogleAuthOptions) { - options = options || {}; + constructor(options: DNSOptions = {}) { + options.apiEndpoint = options.apiEndpoint || 'www.googleapis.com'; const config = { - baseUrl: 'https://www.googleapis.com/dns/v1', + apiEndpoint: options.apiEndpoint, + baseUrl: `https://${options.apiEndpoint}/dns/v1`, scopes: [ 'https://www.googleapis.com/auth/ndev.clouddns.readwrite', 'https://www.googleapis.com/auth/cloud-platform', diff --git a/test/index.ts b/test/index.ts index b0c89a2..7188e8f 100644 --- a/test/index.ts +++ b/test/index.ts @@ -135,6 +135,18 @@ describe('DNS', () => { require('../../package.json') ); }); + + it('should enable apiEndpoint override', () => { + const apiEndpoint = 'fake.endpoint'; + dns = new DNS({ + projectId: PROJECT_ID, + apiEndpoint, + }); + const calledWith = dns.calledWith_[0]; + console.log(calledWith); + assert.strictEqual(calledWith.apiEndpoint, apiEndpoint); + assert.strictEqual(calledWith.baseUrl, `https://${apiEndpoint}/dns/v1`); + }); }); describe('createZone', () => { From 06cb8ef8095d27d68642f7afd544a759fde985b7 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Fri, 31 May 2019 10:04:07 -0700 Subject: [PATCH 2/2] fixy --- test/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/index.ts b/test/index.ts index 7188e8f..0852ed1 100644 --- a/test/index.ts +++ b/test/index.ts @@ -143,7 +143,6 @@ describe('DNS', () => { apiEndpoint, }); const calledWith = dns.calledWith_[0]; - console.log(calledWith); assert.strictEqual(calledWith.apiEndpoint, apiEndpoint); assert.strictEqual(calledWith.baseUrl, `https://${apiEndpoint}/dns/v1`); });