From 61eeb64a6bca194361aacf2a312d27d0e6d63b35 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Fri, 31 May 2019 13:07:12 +0000 Subject: [PATCH] feat: support apiEndpoint override (#728) --- package.json | 3 +-- src/storage.ts | 9 ++++++++- test/index.ts | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f0bc27a2e..c0313a3a5 100644 --- a/package.json +++ b/package.json @@ -50,10 +50,9 @@ "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", - "@types/protobufjs": "^6.0.0", "arrify": "^2.0.0", "compressible": "^2.0.12", "concat-stream": "^2.0.0", diff --git a/src/storage.ts b/src/storage.ts index 0e3ce7330..05370cac2 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -50,6 +50,11 @@ export interface StorageOptions extends GoogleAuthOptions { autoRetry?: boolean; maxRetries?: number; promise?: typeof Promise; + /** + * The API endpoint of the service used to make requests. + * Defaults to `www.googleapis.com`. + */ + apiEndpoint?: string; } export interface BucketOptions { @@ -285,8 +290,10 @@ export class Storage extends Service { * @param {StorageOptions} [options] Configuration options. */ constructor(options: StorageOptions = {}) { + options.apiEndpoint = options.apiEndpoint || 'www.googleapis.com'; const config = { - baseUrl: 'https://www.googleapis.com/storage/v1', + apiEndpoint: options.apiEndpoint, + baseUrl: `https://${options.apiEndpoint}/storage/v1`, projectIdRequired: false, scopes: [ 'https://www.googleapis.com/auth/iam', diff --git a/test/index.ts b/test/index.ts index a171be03c..076aa803e 100644 --- a/test/index.ts +++ b/test/index.ts @@ -134,6 +134,20 @@ describe('Storage', () => { require('../../package.json') ); }); + + it('should propagate the apiEndpoint option', () => { + const apiEndpoint = 'some.fake.endpoint'; + storage = new Storage({ + projectId: PROJECT_ID, + apiEndpoint, + }); + const calledWith = storage.calledWith_[0]; + assert.strictEqual( + calledWith.baseUrl, + `https://${apiEndpoint}/storage/v1` + ); + assert.strictEqual(calledWith.apiEndpoint, apiEndpoint); + }); }); describe('bucket', () => {