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

Commit dfa349e

Browse files
feat: support apiEndpoint override (#713)
1 parent 6cb07e7 commit dfa349e

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"predocs-test": "npm run docs"
4949
},
5050
"dependencies": {
51-
"@google-cloud/common": "^1.0.0",
51+
"@google-cloud/common": "^2.0.0",
5252
"@sindresorhus/is": "^0.17.1",
5353
"acorn": "^6.0.0",
5454
"coffeescript": "^2.0.0",

src/agent/controller.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import {Debug} from '../client/stackdriver/debug';
2929
import {Debuggee} from '../debuggee';
3030
import * as stackdriver from '../types/stackdriver';
3131

32-
/** @const {string} Cloud Debug API endpoint */
33-
const API = 'https://clouddebugger.googleapis.com/v2/controller';
34-
3532
export class Controller extends ServiceObject {
3633
private nextWaitToken: string | null;
3734

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

50-
this.apiUrl = API;
47+
this.apiUrl = `https://${debug.apiEndpoint}/v2/controller`;
5148

5249
if (config && config.apiUrl) {
53-
this.apiUrl = config.apiUrl + new URL(API).pathname;
50+
this.apiUrl = config.apiUrl + new URL(this.apiUrl).pathname;
5451
}
5552
}
5653

src/client/stackdriver/debug.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ export interface PackageInfo {
2121
version: string;
2222
}
2323

24+
export interface DebugOptions extends GoogleAuthOptions {
25+
/**
26+
* The API endpoint of the service used to make requests.
27+
* Defaults to `clouddebugger.googleapis.com`.
28+
*/
29+
apiEndpoint?: string;
30+
}
31+
2432
export class Debug extends Service {
25-
options!: GoogleAuthOptions;
33+
options!: DebugOptions;
2634
packageInfo!: PackageInfo;
2735

2836
/**
@@ -49,7 +57,7 @@ export class Debug extends Service {
4957
* @param options - [Authentication options](#/docs)
5058
*/
5159
constructor(
52-
options: GoogleAuthOptions,
60+
options: DebugOptions = {},
5361
packageJson: {
5462
name: string;
5563
version: string;
@@ -58,10 +66,11 @@ export class Debug extends Service {
5866
if (new.target !== Debug) {
5967
return new Debug(options, packageJson);
6068
}
61-
69+
options.apiEndpoint = options.apiEndpoint || 'clouddebugger.googleapis.com';
6270
const config = {
6371
projectIdRequired: false,
64-
baseUrl: 'https://clouddebugger.googleapis.com/v2',
72+
apiEndpoint: options.apiEndpoint,
73+
baseUrl: `https://${options.apiEndpoint}/v2`,
6574
scopes: ['https://www.googleapis.com/auth/cloud_debugger'],
6675
packageJson,
6776
};

test/test-controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ delete process.env.GCLOUD_PROJECT;
3030
import {Controller} from '../src/agent/controller';
3131
// TODO: Fix fakeDebug to actually implement Debug.
3232
const fakeDebug = ({
33+
apiEndpoint: `clouddebugger.googleapis.com`,
3334
request: (options: r.Options, cb: r.RequestCallback) => {
3435
teenyRequest(options, (err, r) => {
3536
cb(err, r ? r.body : undefined, r);

0 commit comments

Comments
 (0)