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

feat: support apiEndpoint overrides #272

Merged
merged 2 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
11 changes: 11 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ 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];
assert.strictEqual(calledWith.apiEndpoint, apiEndpoint);
assert.strictEqual(calledWith.baseUrl, `https://${apiEndpoint}/dns/v1`);
});
});

describe('createZone', () => {
Expand Down