Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

feat: support apiEndpoint override #713

Merged
merged 8 commits into from
Jun 1, 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 @@ -48,7 +48,7 @@
"predocs-test": "npm run docs"
},
"dependencies": {
"@google-cloud/common": "^1.0.0",
"@google-cloud/common": "^2.0.0",
"@sindresorhus/is": "^0.17.1",
"acorn": "^6.0.0",
"coffeescript": "^2.0.0",
Expand Down
7 changes: 2 additions & 5 deletions src/agent/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import {Debug} from '../client/stackdriver/debug';
import {Debuggee} from '../debuggee';
import * as stackdriver from '../types/stackdriver';

/** @const {string} Cloud Debug API endpoint */
const API = 'https://clouddebugger.googleapis.com/v2/controller';

export class Controller extends ServiceObject {
private nextWaitToken: string | null;

Expand All @@ -47,10 +44,10 @@ export class Controller extends ServiceObject {
/** @private {string} */
this.nextWaitToken = null;

this.apiUrl = API;
this.apiUrl = `https://${debug.apiEndpoint}/v2/controller`;

if (config && config.apiUrl) {
this.apiUrl = config.apiUrl + new URL(API).pathname;
this.apiUrl = config.apiUrl + new URL(this.apiUrl).pathname;
}
}

Expand Down
17 changes: 13 additions & 4 deletions src/client/stackdriver/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ export interface PackageInfo {
version: string;
}

export interface DebugOptions extends GoogleAuthOptions {
/**
* The API endpoint of the service used to make requests.
* Defaults to `clouddebugger.googleapis.com`.
*/
apiEndpoint?: string;
}

export class Debug extends Service {
options!: GoogleAuthOptions;
options!: DebugOptions;
packageInfo!: PackageInfo;

/**
Expand All @@ -49,7 +57,7 @@ export class Debug extends Service {
* @param options - [Authentication options](#/docs)
*/
constructor(
options: GoogleAuthOptions,
options: DebugOptions = {},
packageJson: {
name: string;
version: string;
Expand All @@ -58,10 +66,11 @@ export class Debug extends Service {
if (new.target !== Debug) {
return new Debug(options, packageJson);
}

options.apiEndpoint = options.apiEndpoint || 'clouddebugger.googleapis.com';
const config = {
projectIdRequired: false,
baseUrl: 'https://clouddebugger.googleapis.com/v2',
apiEndpoint: options.apiEndpoint,
baseUrl: `https://${options.apiEndpoint}/v2`,
scopes: ['https://www.googleapis.com/auth/cloud_debugger'],
packageJson,
};
Expand Down
1 change: 1 addition & 0 deletions test/test-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ delete process.env.GCLOUD_PROJECT;
import {Controller} from '../src/agent/controller';
// TODO: Fix fakeDebug to actually implement Debug.
const fakeDebug = ({
apiEndpoint: `clouddebugger.googleapis.com`,
request: (options: r.Options, cb: r.RequestCallback) => {
teenyRequest(options, (err, r) => {
cb(err, r ? r.body : undefined, r);
Expand Down