diff --git a/package.json b/package.json index 404a22eb..1d800292 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "async": "^2.1.2", "coffee-script": "^1.9.3", "findit2": "^2.2.3", + "gcp-metadata": "^0.1.0", "google-auth-library": "^0.9.5", "lodash": "^4.12.0", "request": "^2.61.0", diff --git a/src/agent/debuglet.js b/src/agent/debuglet.js index 751b26cc..037224b3 100644 --- a/src/agent/debuglet.js +++ b/src/agent/debuglet.js @@ -24,6 +24,7 @@ var extend = require('extend'); var util = require('util'); var semver = require('semver'); var _ = require('lodash'); +var metadata = require('gcp-metadata'); var v8debugapi = require('./v8debugapi.js'); var Debuggee = require('../debuggee.js'); @@ -263,30 +264,31 @@ Debuglet.createDebuggee = return new Debuggee(properties); }; - /** - * @private - */ - Debuglet.prototype.getProjectId_ = function(callback) { +/** + * @private + */ +Debuglet.prototype.getProjectId_ = function(callback) { var that = this; // We need to figure out whether we are running on GCP. We can use our ability // to access the metadata service as a test for that. // TODO: change this to getProjectId in the future. - common.utils.getProjectNumber(function(err, metadataProject) { - // We should get an error if we are not on GCP. - var onGCP = !err; - - // We perfer to use the locally available projectId as that is least - // surprising to users. - var project = that.debug_.options.projectId || process.env.GCLOUD_PROJECT || - metadataProject; - - // We if don't have a projectId by now, we fail with an error. - if (!project) { - return callback(err); - } - return callback(null, project, onGCP); - }); + metadata.project( + 'numeric-project-id', function(err, response, metadataProject) { + // We should get an error if we are not on GCP. + var onGCP = !err; + + // We perfer to use the locally available projectId as that is least + // surprising to users. + var project = that.debug_.options.projectId || + process.env.GCLOUD_PROJECT || metadataProject; + + // We if don't have a projectId by now, we fail with an error. + if (!project) { + return callback(err); + } + return callback(null, project, onGCP); + }); }; Debuglet.prototype.getSourceContext_ = diff --git a/test/standalone/test-debuglet.js b/test/standalone/test-debuglet.js index 89f30da1..a477b1db 100644 --- a/test/standalone/test-debuglet.js +++ b/test/standalone/test-debuglet.js @@ -48,6 +48,7 @@ describe(__filename, function() { }); it('should not start when projectId is not available', function(done) { + this.timeout(8000); var debug = require('../..')(); var debuglet = new Debuglet(debug, defaultConfig); @@ -70,6 +71,7 @@ describe(__filename, function() { }); it('should not crash without project num', function(done) { + this.timeout(8000); var debug = require('../..')(); var debuglet = new Debuglet(debug, defaultConfig);