From 24aa2649114bc10b29e363847fe082108c646c16 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 29 May 2019 11:41:13 -0700 Subject: [PATCH 1/4] feat: support apiEndpoint override --- package.json | 2 +- src/agent/controller.ts | 7 ++----- src/client/stackdriver/debug.ts | 17 +++++++++++++---- test/test-controller.ts | 1 + 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 6457769a..4e390037 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "uuid": "^3.3.2" }, "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", diff --git a/src/agent/controller.ts b/src/agent/controller.ts index 5053f147..b0778aaa 100644 --- a/src/agent/controller.ts +++ b/src/agent/controller.ts @@ -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; @@ -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; } } diff --git a/src/client/stackdriver/debug.ts b/src/client/stackdriver/debug.ts index b132478c..adc02213 100644 --- a/src/client/stackdriver/debug.ts +++ b/src/client/stackdriver/debug.ts @@ -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; /** @@ -49,7 +57,7 @@ export class Debug extends Service { * @param options - [Authentication options](#/docs) */ constructor( - options: GoogleAuthOptions, + options: DebugOptions = {}, packageJson: { name: string; version: string; @@ -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, }; diff --git a/test/test-controller.ts b/test/test-controller.ts index d25a2add..b7ef3388 100644 --- a/test/test-controller.ts +++ b/test/test-controller.ts @@ -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: `cloudebugger.googleapis.com`, request: (options: r.Options, cb: r.RequestCallback) => { teenyRequest(options, (err, r) => { cb(err, r ? r.body : undefined, r); From a2a5f64929a8c5ff77a9370281ea74eabff05ae6 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Fri, 31 May 2019 11:26:50 -0700 Subject: [PATCH 2/4] Update package.json --- package.json | 46 +--------------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/package.json b/package.json index 6cb6ce6a..9265de7e 100644 --- a/package.json +++ b/package.json @@ -96,49 +96,5 @@ "teeny-request": "^3.11.3", "typescript": "~3.5.0", "uuid": "^3.3.2" - }, - "dependencies": { - "@google-cloud/common": "^2.0.0", - "@sindresorhus/is": "^0.17.1", - "acorn": "^6.0.0", - "coffeescript": "^2.0.0", - "console-log-level": "^1.4.0", - "extend": "^3.0.1", - "findit2": "^2.2.3", - "gcp-metadata": "^2.0.0", - "lodash.pickby": "^4.6.0", - "p-limit": "^2.2.0", - "semver": "^6.0.0", - "source-map": "^0.6.1", - "split": "^1.0.0" - }, - "scripts": { - "prepare": "npm run compile", - "presamples-test": "npm run compile", - "samples-test": "cd samples/ && npm link ../ && npm install && npm test && cd ../", - "presystem-test": "npm run compile", - "system-test": "mocha build/system-test", - "test-no-cover": "cross-env CLOUD_DEBUG_ASSERTIONS=1 mocha build/test --require source-map-support/register --timeout 4000 --R spec", - "test": "nyc npm run test-no-cover && nyc report", - "check": "gts check", - "clean": "gts clean", - "precompile": "npm run compile-scripts && node build/scripts/setup-build-dir.js", - "compile": "tsc -p .", - "compile-scripts": "tsc -p scripts-tsconfig.json", - "fix": "gts fix", - "pretest": "npm run compile", - "posttest": "npm run check && npm run license-check", - "prepack": "npm run compile", - "license-check": "jsgl --local .", - "lint": "npm run check", - "docs": "compodoc src/", - "docs-test": "linkinator docs -r --skip www.googleapis.com", - "predocs-test": "npm run docs" - }, - "files": [ - "CHANGELOG.md", - "LICENSE", - "README.md", - "build/src" - ] + } } From ec5d73713e48b072d1d519325ebf86fcee7bfb9d Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Fri, 31 May 2019 11:27:42 -0700 Subject: [PATCH 3/4] eugh --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9265de7e..7403842e 100644 --- a/package.json +++ b/package.json @@ -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", From 96e8c6e61126236cc90e24f50d0ba016cd4eae14 Mon Sep 17 00:00:00 2001 From: Dominic Kramer Date: Fri, 31 May 2019 14:44:37 -0700 Subject: [PATCH 4/4] chore: fix the tests (a typo in apiEndpoint) --- test/test-controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-controller.ts b/test/test-controller.ts index b7ef3388..6e714d84 100644 --- a/test/test-controller.ts +++ b/test/test-controller.ts @@ -30,7 +30,7 @@ delete process.env.GCLOUD_PROJECT; import {Controller} from '../src/agent/controller'; // TODO: Fix fakeDebug to actually implement Debug. const fakeDebug = ({ - apiEndpoint: `cloudebugger.googleapis.com`, + apiEndpoint: `clouddebugger.googleapis.com`, request: (options: r.Options, cb: r.RequestCallback) => { teenyRequest(options, (err, r) => { cb(err, r ? r.body : undefined, r);