Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support apiEndpoint override #728

Merged
merged 3 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
Expand Down
14 changes: 14 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down